vendredi 26 octobre 2018

Testing Mocha/supertest/expect MEAN-stack HTTP Request 4 seconds delay done

I am testing a HTTP Request in MEAN-Stack with Mocha/supertest/expect library, that takes 4 seconds to return:

it('should return product data', (done) => {
    request(app)
    .get('/P/Product')
    .expect(200)
    .expect((res) => {
        expect(res.body[0]).toInclude({
            _id: 123456789
        });
        //expect(res.body[0]._id).toEqual('123456789')
    })
    .end(done);
});

The function should use the "done" callback at the end, after the HTTP Request finished. But I am getting error:

1) should return product data:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a
Promise, ensure it resolves. 

I think it works with unnested expect-calls. How would I do it with nested expect-calls inside other expect-calls, like in the example abouve?

Aucun commentaire:

Enregistrer un commentaire