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.

http://www.htmlgoodies.com/html5/javascript/using-the-done-method-in-your-jasmine-driven-asynchronous-javascript-tests.html


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -