Node Chai and Mocha tests end up red and dont show assertion errors
Node Chai and Mocha tests end up red and dont show assertion errors
So I have been trying to mess around with mocha, chai and chai-http for integration testing and I have a very weird problem. Sometimes when I run my tests my assertion errors show up and sometimes they dont. They end up getting logged by my application though. When I run these tests in my terminal I get an output like this:
failure output image
As you can see, the failed test just shows up in red and the assertion error gets logged. This is the code (starting from first describe) of my test. I added the done callback to every "it" as described in the mocha documentation. Im running different setups before each test to set up proper conditions with beforeEach, afterEach, before and after.
describe('Customer', () => {
before(async () => {
testTokens = await testUtils.mockTestRequirements(testUserId, testPlatform);
});
after(async () => {
await testUtils.removeTestRequirements(testUserId, testPlatform);
});
describe('GET /has-premium', () => {
describe('No subscription case', () => {
before(async () => {
await testUtils.mockPaymentTestRequirements(testUserId);
});
after(async () => {
await testUtils.removePaymentTestRequirements(testUserId);
});
it('should respond false if the customer does not have a subscription', (done) => {
chai.request(app)
.get('/customer/has-premium')
.set('x-access-token', testTokens.accessToken)
.set('x-refresh-token', testTokens.refreshToken)
.query({unique_id: testUserId})
.end((err, res) => {
expect(res).to.be.json;
expect(res).to.have.status(200);
expect(res.body.success).to.equal(true);
expect(res.body.premium).to.equal(false);
done();
})
});
});
});
I have no idea why this keeps failing and I tried debugging but I cant figure out the error.
Thanks in advance!
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment