We are building an application using nodejs and writing asynchronous tests for it using Jest. There is a problem we have been facing for a while now in regards to tests; sometimes tests fail on CircleCI while other times they pass. And yes, we are using async/await method to wait for the data to be fetched first before doing an assertion. Here is a snippet from the tests file:
it('should return the expected number of trips', async () => {
const postResp = await request(app)
.post('/api/v1/requests')
.set('authorization', token)
.send(mockRequest);
const createdRequestId = postResp.body.request.id;
const getResp = await request(app)
.get(`/api/v1/requests/${createdRequestId}`)
.set('authorization', token);
expect(getResp.body.requestData.trips).toHaveLength(2);
});
And this is the error that was thrown by CircleCI in regards to this block of test: TypeError: Cannot read property 'trips' of undefined
Aucun commentaire:
Enregistrer un commentaire