I have defined a function in a class with a file as I want to call the function in the spec file or we can say that want to test the async function delayedAlert.
How to test the function in the spec file.
home.ts
click(){
function delayedAlert(message: string, time: number, cb) {
return setTimeout(() => cb(message), time);
}
delayedAlert('Aditya3', 3000, (message) => console.log(message));
}}
home.spec.ts
describe('Asynchronous call', () => {
let fixture: ComponentFixture<HomePage>;
let comp: HomePage;
let de: DebugElement;
let el: HTMLElement;
let message: string;
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('test', function (done) {
//showing error=> delayedAlert(message, 3000, (response) => {
expect
/// test1
done();
});
})