lundi 11 février 2019

Chai http-request does not assert correctly

When trying to run a test (mocha, chai) as shown in the code sample, the test always appears as to be successful, even when I tried to adding a line that should never be successful (expect(false).to.be.true;)

This is the code snipped: (if I debug, it will always reach the except lines of the code, and the post request goes trough like it should returning the approrpiate response) (I also tried the version with .end(err, res) instead of .then(res) but I had the same problem)

it('should login correctly', function () {
        chai.request('http://localhost:3000')
            .post('/user/login')
            .set({
                'client-token':clientToken,
                'Content-Type':content_type
            })
            .send({
                'username': 'wrongUsername',
                'password': 'wrongPassword'
            })
            .then(function (res) {
                expect(false).to.be.true;
                expect(res.body.success).to.be.true;
            });
});

Aucun commentaire:

Enregistrer un commentaire