vendredi 29 juin 2018

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 before and each.

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', 'QueueFeed ' + 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).t.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!

Aucun commentaire:

Enregistrer un commentaire