Below I wrote code that has an asynchronous function that uses setTimeout () inside and prints a message after 3 seconds.
I need to write a specification using Jasmine.
I followed the docs , but I did not understand how to apply this in the code.
home.ts
//implementing only function written in a class.All imports are done properly. click(){ function delayedAlert(message: string, time: number, cb) { return setTimeout(() => cb(message), time); } delayedAlert('Aditya3', 3000, (message) => console.log(message));//function is 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 with callback', ()=>{ //how to write the spec here for the asynchronous function wrriten in the above class using Karma/Jasmine. }) });
In the comments noted in the test spec, I need to write a spec.
angular jasmine ionic2 angular2-testing
Aditya
source share