angular - How to test an asynchronous function using karma/Jasmine in ionic2? -
below have written down code in there asynchronous function, uses settimeout() internally , prints message after 3seconds.
i have write spec using jasmine.
i have followed docs didn't how apply in code.
home.ts
//implementing function written in class.all imports done properly. click(){ function delayedalert(message: string, time: number, cb) { return settimeout(() => cb(message), time); } delayedalert('aditya3', 3000, (message) => console.log(message));//function called } }
home.spec.ts
describe('asynchronous call', () => { let fixture: componentfixture<homepage>; let comp: homepage; let de: debugelement; let el: htmlelement; beforeeach(async(() => { testbed.configuretestingmodule({ declarations: [homepage], imports: [ ionicmodule.forroot(homepage), ], providers: [navcontroller], }).compilecomponents(); })); beforeeach(() => { fixture = testbed.createcomponent(homepage); comp = fixture.componentinstance; de = fixture.debugelement }); it('asynchronous testing callback', ()=>{ //how write spec here asynchronous function wrriten in above class using karma/jasmine. }) });
in comments marked in test spec, need write spec.
use done() method. check out.
Comments
Post a Comment