【发布时间】:2023-03-26 18:45:02
【问题描述】:
下面我写了一个异步函数的代码,它在内部使用 setTimeout() 并在 3 秒后打印消息。
我必须使用 Jasmine 编写规范。
我已关注docs,但我不知道如何在代码中应用它。
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.
})
});
在测试规范中标注的cmets中,我需要写规范。
【问题讨论】:
标签: angular ionic2 jasmine angular2-testing