How to test the delayedAlert function which is asynchronous in nature usning Jasmine.Please help.

11 views
Skip to first unread message

aditya jain

unread,
Aug 4, 2017, 11:50:10 AM8/4/17
to Jasmine

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.


Please help me how to test this asyn function.



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();

        });   
    })
Reply all
Reply to author
Forward
0 new messages