Supertest not returning correct status

时间:2017-03-02 23:42:25

标签: express supertest

Having an issue getting supertest to assert the proper status response. What am I doing wrong?

/// server.js /////
var app = express();

app.get('/', function(req, res) {
    res.status(200).json({ message: 'v1.0' });
});


// test.js ////
it('should fail but passes', function(done) {
    request
        .get('/')
        .expect(500, done);
});

1 个答案:

答案 0 :(得分:0)

原来这是由于使用了茉莉花。显然,jasmine中的done()函数取代了supertest中的done函数,因此您必须使用end()方法处理错误。

https://github.com/jasmine/jasmine-npm/issues/31

it('should fail & does', function(done) {
    request
        .get('/doesNotExist')
        .expect(200)
        .end(function(err, res) {
            if (err) {
                done.fail(err);
            } else {
                done();
            }
        });
});