0
以下は、内部的にsetTimeout()を使用し、3秒後にメッセージを出力する非同期関数があるコードを書いたものです。ionic2でカルマ/ジャスミンを使って非同期関数をテストする方法は?
ジャスミンを使用して仕様を記述する必要があります。
私は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.
})
});
、私は仕様を記述する必要があります。
、あなたは私がjasmine.asyncのlibを使用せずに、この仕様を書くために助けることができますか? – Aditya
私はそれを実装することができません。あなたが助けますか? – Aditya