Home > front end >  cypress after all hook is called before async call completes
cypress after all hook is called before async call completes

Time:08-25

In my test I have async function call

describe('a', () => {

    after(() => {
        console.log('after call');
    });

    it('a', () => {
        myAsyncFunction().then(() => {
            console.log('async call');
        });
    });

});

Looking at console, first is after call and then async call.

How make after be called really after all async calls finish?

CodePudding user response:

You can pass Mocha's done() method and call it inside the async response

describe('a', () => {

    after(() => {
        console.log('after call');
    });

    it('a', (done) => {
        myAsyncFunction().then(() => {
            console.log('async call');
            done();                   // test finishes only after this call is made
                                      // then after() is called
        });
    });

});
  • Related