在我看来,这个测试不应该通过
chai test
const chai = require('chai')
const expect = chai.expect;
const chaiHttp = require('chai-http');
const request = chaiHttp.expect;
const config = require('../../app/config');
const worker = require('../../app/worker');
chai.use(chaiHttp);
describe('server response', function () {
.....
it('should return 200', function () {
chai.request(`http://localhost:${config.port}`)
.get('/')
.end(function (err, res) {
expect('as').to.have.status(200);
});
});
});
终端
> NODE_ENV=test mocha --timeout 20000 --recursive test/ --compilers js:babel-core/register
server response
✓ should return 200
1 passing (150ms)
答案 0 :(得分:1)
我认为您错过了done
回调。试试这个
it('should return 200', function (done) {
chai.request(`http://localhost:${config.port}`)
.get('/')
.end(function (err, res) {
expect('as').to.have.status(200);
done();
});
});
使用此代码,测试只会在
时通过expect('as').to.have.status(200);
为true(对于当前示例,它将始终为false)