bxSlider custom transition mode - css-transitions

I'm trying to get a new transition effect for bxslider, but I'm not sure if this is the correct approach.
This is what I have so far: http://jsfiddle.net/wilfff/6KAFt/
$('.bxslider').bxSlider({
auto: true,
controls: false,
pager: false,
mode: 'fade',
delay: 8900/*,
onSlideBefore: function (elm) {
elm.css({
"-webkit-transition": ".9s ease-out",
"-moz-transition": ".9s ease-out",
"-ms-transition": ".9s ease-out",
"-o-transition": ".9s ease-out",
"transition": ".9s ease-out",
"-webkit-transform": "rotateX(360deg)",
"-moz-transform": "rotateX(360deg)",
"-ms-transform": "rotateX(360deg)",
"-o-transform": "rotateX(360deg)",
"transform": "rotateX(360deg)"
});
elm.hide();
}*/,
onSlideAfter: function (elm) {
elm.css({
"-webkit-transition": ".9s ease-out",
"-moz-transition": ".9s ease-out",
"-ms-transition": ".9s ease-out",
"-o-transition": ".9s ease-out",
"transition": ".9s ease-out",
"-webkit-transform": "rotateX(360deg)",
"-moz-transform": "rotateX(360deg)",
"-ms-transform": "rotateX(360deg)",
"-o-transform": "rotateX(360deg)",
"transform": "rotateX(360deg)"
});
}
});
What I'm trying to achieve is this effect: http://webstuffshare.com/demo/FlippingSlider/index.html
Any help will be appreciated!
Cheers! :)

Related

any Jest test fails with "result.message is not a function" after upgrading to 27.2.5

After upgrading Jest to v.27.2.5 from v.26 if a test fails it shows me: result.message is not a function
It doesn't matter what I try to test. If it fails, I don't get any meaningful message.
My test:
it('should pass', async () => {
const foo = 2;
expect(foo).toBe(3);
});
Result:
result.message is not a function
TypeError: result.message is not a function
at new JestAssertionError (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-chain-npm-1.1.5-5b9906685f-cc8cb9b33a.zip/node_modules/jest-chain/dist/chain.js:10:18)
at Object.newMatcher [as toBe] (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-chain-npm-1.1.5-5b9906685f-cc8cb9b33a.zip/node_modules/jest-chain/dist/chain.js:31:17)
at _callee6$ (ROUTE_TO/GitHub/Flow/Flow_FE/src/components/forms/RequestSetNewPasswordForm/RequestSetNewPasswordForm.test.tsx:133:15)
at tryCatch (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/regenerator-runtime-npm-0.13.9-6d02340eec-65ed455fe5.zip/node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/regenerator-runtime-npm-0.13.9-6d02340eec-65ed455fe5.zip/node_modules/regenerator-runtime/runtime.js:294:22)
at Generator.next (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/regenerator-runtime-npm-0.13.9-6d02340eec-65ed455fe5.zip/node_modules/regenerator-runtime/runtime.js:119:21)
at asyncGeneratorStep (ROUTE_TO/GitHub/Flow/Flow_FE/src/components/forms/RequestSetNewPasswordForm/RequestSetNewPasswordForm.test.tsx:8:103)
at _next (ROUTE_TO/GitHub/Flow/Flow_FE/src/components/forms/RequestSetNewPasswordForm/RequestSetNewPasswordForm.test.tsx:10:194)
at ROUTE_TO/GitHub/Flow/Flow_FE/src/components/forms/RequestSetNewPasswordForm/RequestSetNewPasswordForm.test.tsx:10:364
at new Promise (<anonymous>)
at Object.<anonymous> (ROUTE_TO/GitHub/Flow/Flow_FE/src/components/forms/RequestSetNewPasswordForm/RequestSetNewPasswordForm.test.tsx:10:97)
at Promise.then.completed (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/utils.js:390:28)
at new Promise (<anonymous>)
at callAsyncCircusFn (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/utils.js:315:10)
at _callCircusTest (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/run.js:218:40)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at _runTest (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/run.js:155:3)
at _runTestsForDescribeBlock (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/run.js:66:9)
at run (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/run.js:25:3)
at runAndTransformResultsToJestFormat (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:167:21)
at jestAdapter (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-circus-npm-27.2.5-f729640db6-35a43f48d6.zip/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:82:19)
at runTestInternal (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-runner-npm-27.2.5-cb3234bfd1-12daf87276.zip/node_modules/jest-runner/build/runTest.js:389:16)
at runTest (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-runner-npm-27.2.5-cb3234bfd1-12daf87276.zip/node_modules/jest-runner/build/runTest.js:475:34)
at TestRunner.runTests (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/cache/jest-runner-npm-27.2.5-cb3234bfd1-12daf87276.zip/node_modules/jest-runner/build/index.js:111:12)
at TestScheduler.scheduleTests (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/__virtual__/#jest-core-virtual-30a9be5577/0/cache/#jest-core-npm-27.2.5-0bd8b654d5-e140b71fa5.zip/node_modules/#jest/core/build/TestScheduler.js:333:13)
at runJest (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/__virtual__/#jest-core-virtual-30a9be5577/0/cache/#jest-core-npm-27.2.5-0bd8b654d5-e140b71fa5.zip/node_modules/#jest/core/build/runJest.js:387:19)
at _run10000 (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/__virtual__/#jest-core-virtual-30a9be5577/0/cache/#jest-core-npm-27.2.5-0bd8b654d5-e140b71fa5.zip/node_modules/#jest/core/build/cli/index.js:320:7)
at runCLI (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/__virtual__/#jest-core-virtual-30a9be5577/0/cache/#jest-core-npm-27.2.5-0bd8b654d5-e140b71fa5.zip/node_modules/#jest/core/build/cli/index.js:173:3)
at Object.run (ROUTE_TO/GitHub/Flow/Flow_FE/.yarn/__virtual__/jest-cli-virtual-049064fa1a/0/cache/jest-cli-npm-27.2.5-de57d01272-403468c466.zip/node_modules/jest-cli/build/cli/index.js:155:37)
My Jest config:
/** #type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
verbose: false,
preset: 'ts-jest',
globals: {
'ts-jest': {
isolatedModules: true,
diagnostics: {
warnOnly: true,
},
babelConfig: true,
},
},
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['./src/jest/setupTests.ts'],
modulePathIgnorePatterns: ['<rootDir>/dist/'],
roots: ['<rootDir>', '<rootDir>/src/', '<rootDir>/src/jest'],
moduleNameMapper: {
'\\.(css|less|sass|scss)$': '<rootDir>/src/jest/__mocks__/styleMock.js',
'\\.(gif|ttf|eot|svg)$': '<rootDir>/src/jest/__mocks__/fileMock.js',
},
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.{ts,tsx}',
'!src/**/*.types.{ts,tsx}',
'!src/**/types.{ts,tsx}',
'!src/**/index.{ts,tsx}',
'!src/**/*.stories.{ts,tsx}',
'!src/**/clientApi.ts',
'!src/**/AxiosInstance.ts',
'!src/**/store.ts',
'!src/**/type.tsx',
'!src/storybookComponents/*.*',
],
};
setupTests.ts
import 'regenerator-runtime/runtime';
import '#testing-library/jest-dom';
import 'jest-extended';
import 'jest-chain';
import 'jest-mock-axios';
Dependences:
"#babel/core": "^7.12.10",
"#babel/plugin-proposal-class-properties": "^7.12.1",
"#babel/plugin-syntax-dynamic-import": "^7.8.3",
"#babel/preset-env": "^7.12.11",
"#babel/preset-react": "^7.12.10",
"#babel/preset-typescript": "^7.13.0",
"#mdx-js/react": "^1.6.22",
"#pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"#testing-library/dom": "^8.7.2",
"#testing-library/jest-dom": "^5.14.1",
"#testing-library/react": "^12.1.2",
"#testing-library/react-hooks": "^7.0.2",
"#testing-library/user-event": "^13.3.0",
"#typescript-eslint/eslint-plugin": "^4.10.0",
"#typescript-eslint/parser": "^4.10.0",
"#welldone-software/why-did-you-render": "^6.2.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.2.5",
"babel-loader": "^8.2.2",
"core-js": "^3.18.2",
"css-loader": "5.2.6",
"css-modules-typescript-loader": "^4.0.1",
"file-loader": "^6.2.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.3.2",
"image-webpack-loader": "^8.0.1",
"jest": "^27.2.5",
"jest-chain": "^1.1.5",
"jest-extended": "^1.0.0",
"jest-jasmine2": "^27.2.5",
"jest-mock-axios": "^4.4.1",
"js-yaml": "^4.1.0",
"mini-css-extract-plugin": "^2.4.2",
"mock-local-storage": "^1.1.17",
"prettier": "^2.4.1",
"react-hot-loader": "^4.13.0",
"react-refresh": "^0.10.0",
"react-test-renderer": "^17.0.2",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.5.4",
"redux-saga-test-plan": "^4.0.3",
"regenerator-runtime": "^0.13.9",
"sass": "^1.42.1",
"sass-loader": "10.1.1",
"style-loader": "2.0.0",
"ts-dedent": "^2.2.0",
"ts-jest": "^27.0.5",
"ts-loader": "^9.2.6",
"ts-node": "^10.2.1",
"type-fest": "^2.3.4",
"typescript": "^4.4.3",
"url-loader": "^4.1.1",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "^4.3.1"
},
Any ideas?
UPDATE
The problem in "jest-chain"

AWS SES - Nodemailer - transporter.sendEmail is not a function

const nodemailer = require('nodemailer');
const aws = require('aws-sdk');
aws.config.update({ region: 'myRegion');
const senderEmail = process.env.SENDER_EMAIL;
const destinationEmail = process.env.DESTINATION_EMAIL;
const transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
})
});
exports.handler = async (event) => {
let request = event.body;
try {
await this.sendEmail(request);
return {
'statusCode': 201,
'headers': {
'Access-Control-Allow-Origin': '*'
}
};
} catch (error) {
return {
'statusCode': 500
};
}
};
exports.sendEmail = async (request) => {
try {
await transporter.sendEmail({
from: senderEmail,
to: destinationEmail,
subject: 'Hello',
text: 'Hello using SES'
});
} catch (error) {
console.log(error);
throw error;
}
};
I have the following code which gives a error saying 'transporter.Email' is not a function. I have the following dependencies specified in my package.json (Some content is stripped but it is a valid JSON)
{
"devDependencies": {
"aws-sdk": "^2.267.1",
"chai": "^4.1.2",
"eslint": "^5.1.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"hippie-swagger": "^3.2.0",
"mocha": "^5.1.1",
"mochawesome": "^3.0.3",
"sinon": "^6.1.0",
"swagger-parser": "^5.0.2"
},
"dependencies": {
"axios": "^0.18.0",
"nodemailer": "^4.6.8",
"nodemailer-ses-transport": "^1.5.1"
}
}
At the first look, it does not look like a permissions issue, so ruling that out. Any pointers to fix it would be of great help.
I am using Node.js 8.10 in lambda.
Should be transporter.sendMail
http://nodemailer.com/usage/#sending-mail

Unit test with enzyme, mocha, sinon and reactjs. How to see what the spy is called with?

I have tried to work out why this test is failing but cannot determine the reason, because I cannot see what the sinon spy object is being called with.
Is there a better way to test sinon.calledWith so it will show the result and expected result?
In the test below the following check passes expect(onLoginClick.called).to.equal(true); but this does not expect(onLoginClick.calledWith(expected)).to.equal(true);.
Any ideas why?
How can I check myself by seeing the actual value onLoginClick is called with vs the expected?
I am running the tests via "npm run test", the project can be cloned and run from https://github.com/Rob-Leggett/react_redux_webpack
Thanks for any answers and time taken to assist with this question.
Test
import React from 'react';
import { mount, shallow } from 'enzyme';
import { expect } from 'chai';
import sinon from 'sinon';
import Login from '../app/components/login/Login';
describe('<Login/>', function () {
it('should click login button with credentials', () => {
// given
const expected = { username: 'test', password: 'user' };
const errors = [];
const onLoginClick = sinon.spy();
const wrapper = mount(<Login errors={errors} onLoginClick={onLoginClick} />);
// when
wrapper.ref('username').simulate('change', {target: {value: 'test'}});
wrapper.ref('password').simulate('change', {target: {value: 'user'}});
wrapper.find('button').simulate('click');
// then
//expect(onLoginClick.calledWith(expected)).to.equal(true);
expect(onLoginClick.called).to.equal(true);
});
});
Component
import React, { Component, PropTypes } from 'react'
export default class Login extends Component {
renderErrors() {
const { errors } = this.props;
return errors.map((error, i) => {
return (
<p key={i} style={{color:'red'}}>{error}</p>
);
});
}
render() {
return (
<div>
<input type='text' ref='username' className="form-control" style={{ marginRight: '5px' }} placeholder='Username'/>
<input type='password' ref='password' className="form-control" style={{ marginRight: '5px' }} placeholder='Password'/>
<button onClick={() => this.handleLogin()} className="btn btn-primary">
Login
</button>
{this.renderErrors()}
</div>
)
}
handleLogin() {
const { onLoginClick } = this.props;
const credentials = {
username: this.refs.username.value.trim(),
password: this.refs.password.value.trim()
};
onLoginClick(credentials)
}
}
Login.propTypes = {
onLoginClick: PropTypes.func.isRequired,
errors: PropTypes.arrayOf(PropTypes.string)
};
package.json
{
"name": "react_redux_webpack_client",
"version": "1.0.0",
"description": "A ReactJS Client",
"scripts": {
"test": "mocha test/helpers/browser.js test/**/*.spec.js",
"dev": "webpack-dev-server --content-base public/ --hot --inline",
"build": "webpack -p --display-error-details"
},
"repository": {
"type": "git",
"url": "https://github.com/Rob-Leggett/react_redux_webpack.git"
},
"author": "Robert Leggett",
"license": "MIT",
"homepage": "https://github.com/Rob-Leggett/react_redux_webpack",
"bugs": {
"url": "https://github.com/Rob-Leggett/react_redux_webpack/issues"
},
"devDependencies": {
"chai": "^3.5.0",
"css-loader": "^0.26.1",
"enzyme": "^2.7.1",
"extract-text-webpack-plugin": "^1.0.1",
"html-webpack-plugin": "^2.26.0",
"jsdom": "^9.9.1",
"mocha": "^3.2.0",
"node-sass": "^4.3.0",
"react-addons-test-utils": "^15.4.2",
"sass-loader": "^4.1.1",
"sinon": "^1.17.7",
"style-loader": "^0.13.1",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
},
"dependencies": {
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-register": "^6.22.0",
"body-parser": "^1.15.2",
"classnames": "^2.2.5",
"react": "^15.4.2",
"react-dom": "^15.4.2",
"react-redux": "^5.0.2",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"whatwg-fetch": "^2.0.1"
}
}
To find out more then true/false in your test, you can can get the args from the Sinon spy like this:
const spyCall = onLoginClick.getCall(0);
expect(spyCall.args[0]).to.equal(expected)
Now the failing test should show you the args you really got.
See http://sinonjs.org/docs/

Ionic2 Upgrade from beta to rc3: App.html”: Error: ENOENT: no such file or directory

I am in the process of upgrading from Ionic 2 beta to Ionic 2 rc3.
I have my app.component.ts file, that worked fine, when it was just displaying a root page. But as soon as I have tried to add menu items from my old working Ionic 2 beta version, I get the error below.
If anyone can advise how I can resolve this, I would appreciate the help.
Compile Error in CLI
[13:14:56] template error, "E:\Development\IDE\ionic-apps\WhatsAppClone\src\app\build\app.html": Error: ENOENT: no such
file or directory, open 'E:\Development\IDE\ionic-apps\WhatsAppClone\src\app\build\app.html'
Runtime Error in browser console
Unhandled Promise rejection: Failed to load build/app.html ; Zone: meteor-rxjs-zone ; Task: Promise.then ; Value: Failed to load build/app.html undefined polyfills.js:3:7730
Error: Uncaught (in promise): Failed to load build/app.html
Stack trace:
s#http://localhost:8100/build/polyfills.js:3:8568
s#http://localhost:8100/build/polyfills.js:3:8391
h/<#http://localhost:8100/build/polyfills.js:3:8902
sg</d</t.prototype.invokeTask#http://localhost:8100/build/polyfills.js:3:14040
sg</v</e.prototype.runTask#http://localhost:8100/build/polyfills.js:3:11392
i#http://localhost:8100/build/polyfills.js:3:8021
t/this.invoke#http://localhost:8100/build/polyfills.js:3:15204
app.component.ts
import { Component, ViewChild } from '#angular/core';
import { Storage } from "#ionic/storage";
import { Platform, Events, AlertController, Nav } from 'ionic-angular';
import { StatusBar, Push, Splashscreen } from 'ionic-native';
import { SearchJobsPage } from "../pages/searchjobs/searchjobs";
import { LoginPage } from '../pages/login/login';
import { LogoutPage } from '../pages/logout/logout';
import { PersonModel } from '../pages/model/personModel';
import { ChatsPage } from '../pages/chats/chats';
import { PersonPage } from '../pages/person/person';
import { SearchFavouriteJobsPage } from '../pages/searchfavouritejobs/searchfavouritejobs';
import { SearchPostingsPage } from '../pages/searchpostings/searchpostings';
import { SearchFavouritePostingsPage } from '../pages/searchfavouritepostings/searchfavouritepostings';
import { UtilityService } from '../pages/utils/utilityService';
import { NotificationService } from '../pages/service/notificationService';
import { JobService } from '../pages/service/jobService';
import { JobModel } from '../pages/model/jobModel';
import { MapLocationsPage } from '../pages/maplocations/maplocations';
import { MapRangePage } from '../pages/maprange/maprange';
//import { METEOR_PROVIDERS } from 'angular2-meteor';
// import * as Check from 'meteor/check';
// import * as EJSON from 'meteor/ejson';
//declare let Meteor;
#Component({
templateUrl: 'build/app.html'
})
export class MyApp {
#ViewChild(Nav) nav: Nav;
rootPage: any;
public storage: Storage = null;
public pages: Array<{ title: string, component: any }>;
public pages_person: Array<{ title: string, component: any }>;
public pages_person_admin: Array<{ title: string, component: any }>;
public menuTitle: string = 'Menu';
public personModel: PersonModel = null;
public utilityService: UtilityService = null;
public notificationService: NotificationService = null;
public personModelLoggedIn: PersonModel;
public jobService: JobService = null;
public events: Events = null;
public ios: boolean = false;
constructor(private platform: Platform, utilityService: UtilityService, notificationService: NotificationService, jobService: JobService, events: Events, private alertCtrl: AlertController, storage: Storage) {
this.storage = storage;
this.utilityService = utilityService;
this.jobService = jobService;
this.notificationService = notificationService;
this.events = events;
this.initializeApp();
if (this.platform.is('ios')) {
this.ios = true;
}
// this.rootPage = Meteor.user() ? TabsPage : LoginComponent;
this.rootPage = SearchJobsPage;
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.initializeApp();
StatusBar.styleDefault();
Splashscreen.hide();
});
// used for an example of ngFor and navigation
this.pages = [
{ title: 'Market', component: SearchJobsPage },
{ title: 'Postings', component: SearchPostingsPage },
{ title: 'Login', component: LoginPage }
];
this.pages_person = [
{ title: 'Market', component: SearchJobsPage },
{ title: 'Market Favourites', component: SearchFavouriteJobsPage },
{ title: 'Postings', component: SearchPostingsPage },
{ title: 'Favourite Postings', component: SearchFavouritePostingsPage },
{ title: 'Messages', component: ChatsPage },
{ title: 'Profile', component: PersonPage },
{ title: 'Logout', component: LogoutPage }
];
this.pages_person_admin = [
{ title: 'Market', component: SearchJobsPage },
{ title: 'Market Favourites', component: SearchFavouriteJobsPage },
{ title: 'Postings', component: SearchPostingsPage },
{ title: 'Favourite Postings', component: SearchFavouritePostingsPage },
{ title: 'Messages', component: ChatsPage },
{ title: 'Profile', component: PersonPage },
{ title: 'Logout', component: LogoutPage },
{ title: 'Map Locations', component: MapLocationsPage },
{ title: 'Map Range', component: MapRangePage }
];
}
initializeApp() {
StatusBar.styleDefault();
this.checkLogin();
this.utilityService.startUpChecks();
if (window['cordova']) {
this.utilityService.setLocalStrorage('this.chats.observe', 'false');
this.utilityService.setLocalStrorage('this.messages.observe', 'false');
this.utilityService.setLocalStrorage('this.messages.subscribe', 'false');
this.utilityService.setLocalStrorage('push:notifications.subscribe', 'false');
}
this.subscribeEvents();
}
// openPage(page) {
// // Reset the content nav to have just this page
// // we wouldn't want the back button to show in this scenario
// this.nav.setRoot(page.component);
// }
public subscribeEvents(): void {
this.events.subscribe('push:notifications', (data) => {
this.checkLogin();
});
}
public pushNotifications(): void {
let observedPromise: Promise<string> = this.utilityService.getLocalStrorage('push:notifications.subscribe');
observedPromise.then((observed: string) => {
if (!observed || observed != 'true') {
this.utilityService.setLocalStrorage('push:notifications.subscribe', 'true');
try {
if (window['cordova']) {
if (this.personModelLoggedIn) {
let promiseJobsForPerson: Promise<JobModel[]> = this.jobService.getJobsByPerson(this.personModelLoggedIn.id);
promiseJobsForPerson.then((data) => {
let jobModelsForPerson: JobModel[] = data;
let topics: string[] = [];
topics.push('P' + this.personModelLoggedIn.id);
for (let i = 0; i < jobModelsForPerson.length; i++) {
let jobModel: JobModel = jobModelsForPerson[i];
topics.push('J' + jobModel.id);
}
//topics.push('J65'); // deleteme
//topics.push('P9'); // deleteme
let push = Push.init({
android: {
senderID: "893141127008",
topics: topics
},
ios: {
alert: "true",
badge: false,
sound: "true",
topics: topics
},
windows: {}
});
push.on('registration', (data1) => {
this.events.subscribe('messages:notify', (data) => {
let promise: Promise<string> = this.notificationService.push('null', data[0].topic, data[0].message, data[0].title);
promise.then((data2) => {
// console.log('app.ts messages2:notify', data2);
});
});
});
push.on('notification', (data) => {
this.events.publish('messages:update');
if (this.nav.getActive().name != 'ChatsPage' && this.nav.getActive().name != 'MessagesPage') {
//if user using app and push notification comes
if (data.additionalData.foreground) {
//if application open, show popup
let confirmAlert = this.alertCtrl.create({
title: data.title,
message: data.message,
buttons: [{
text: 'Ignore',
role: 'cancel'
}, {
text: 'View',
handler: () => {
this.rootPage = ChatsPage;
}
}]
});
confirmAlert.present(confirmAlert);
} else {
this.rootPage = ChatsPage;
}
}
});
push.on('error', (e) => {
alert('Error: ' + e.message);
console.log(e);
});
});
}
}
} catch (e) {
alert('Push Notification: ' + e.message());
console.log('Push Notification: ' + e.message());
}
}
});
}
public checkLogin(): void {
let promise: Promise<string> = this.utilityService.getLoggedInPerson();
promise.then((data) => {
this.personModelLoggedIn = JSON.parse(data);
if (this.personModelLoggedIn) {
this.utilityService.setUpMenuItems();
this.pushNotifications();
}
});
}
}
app.html
<ion-menu [content]="content" id="unauthenticated">
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu [content]="content" id="authenticated-person">
<ion-toolbar [class]="ios ? 'menu-toolbar' : ''">
<ion-title [class]="ios ? 'menu-title' : ''">
<div class="item-avatar-img" id="menu-item-avatar-img-person"></div>
<div class="item-avatar-name" id="menu-item-avatar-name-person"></div>
</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages_person" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu [content]="content" id="authenticated-person-admin">
<ion-toolbar [class]="ios ? 'menu-toolbar' : ''">
<ion-title [class]="ios ? 'menu-title' : ''">
<div class="item-avatar-img" id="menu-item-avatar-img-person-admin"></div>
<div class="item-avatar-name" id="menu-item-avatar-name-person-admin"></div>
</ion-title>
</ion-toolbar>
<ion-content>
<ion-list>
<button menuClose ion-item *ngFor="let p of pages_person_admin" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<!-- Disable swipe-to-go-back because it's poor UX to combine STGB with side menus -->
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
Directory
You have set your templateUrl as build/app.html.
You shouldnt check it in build folder.
Try templateUrl: 'app.html' in app.component.ts

Unit Testing of Angular 2 Component using Jasmine

I am trying to unit test the Angular 2 Component using Jasmine. My Component is as follows
import { Component } from '#angular/core';
import {Employee} from './Employee';
#Component({
selector: 'emp-data',
templateUrl: './app/app.html'
})
export class EmployeeComponent {
emp:Employee;
private name: string = 'John';
constructor() {
this.emp =new Employee();
}
getTax():number{
console.log('sal' + this.emp.salary + ' desig ' + this.emp.designation);
if(this.emp.designation=='Manager'){
this.emp.tax = this.emp.salary*0.3;
}
if(this.emp.designation=='Lead'){
this.emp.tax = this.emp.salary*0.25;
}
console.log("Tax " + this.emp.tax);
return this.emp.tax;
}
printMessage():string{
return `Hello ${this.name}`;
};
}
The Spec file is as follows
import {EmployeeComponent} from './appcomponent';
describe('EmployeeComponent',()=>{
beforeEach(()=>{
this.app = new EmployeeComponent();
});
it('should have name property', function() {
expect(this.app.name).toBe('Mahesh');
});
it('should say hello with name property', function() {
expect(this.app.printMessage()).toBe('Hello Mahesh');
});
});
The Tester.html file is as follows
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Ng App Unit Tests</title>
<link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<script src="../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../node_modules/reflect-metadata/Reflect.js"></script>
<script src="../node_modules/zone.js/dist/zone.js"></script>
<script src="../node_modules/#angular/core/testing/testing.js"></script>
<script src="systemjs.config.js"></script>
<script src="../app/appcomponent.js"></script>
<script src="../app/component.spec.js"></script>
</head>
<body>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script>
System.config({
packages: {
'app': {defaultExtension: 'js'}
}
});
System.import('app/component.spec')
.then(window.onload)
.catch(console.error.bind(console));
</script>
</body>
</html>
The Package.json is as follows
{
"name": "ng2-component-testing",
"version": "1.0.0",
"scripts": {
"start": "concurrently \"tsc -w\" \"node server.js\"",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install",
"testLite": "live-server --open=unit-tests.html",
"lite-server-test": "lite-server --config=liteserver-test-config.json",
"test": "tsc && concurrently \"npm run tsc:w\" \"npm run lite-server-test\" "
},
"license": "ISC",
"dependencies": {
"#angular/common": "2.0.0-rc.1",
"#angular/compiler": "2.0.0-rc.1",
"#angular/core": "2.0.0-rc.1",
"#angular/http": "2.0.0-rc.1",
"#angular/platform-browser": "2.0.0-rc.1",
"#angular/platform-browser-dynamic": "2.0.0-rc.1",
"#angular/router": "3.0.0-alpha.3",
"bootstrap": "^3.3.6",
"es6-shim": "^0.35.1",
"jasmine-core": "~2.4.1",
"koa": "^1.2.0",
"koa-static": "^2.0.0",
"livereload": "^0.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "^0.19.24",
"zone.js": "0.6.6"
},
"devDependencies": {
"concurrently": "^2.0.0",
"jasmine-core": "2.4.1",
"lite-server": "^2.1.0",
"node-gyp": "^3.3.1",
"typescript": "^1.8.7",
"typings": "^0.7.5"
}
}
When I run the test, the following result is displayed
The following error messages are displayed in Console of the browser
I have tries various solutions on Stackoverflow but not successful in it.
So can anybody help me on this?
Thanks in advance.