【发布时间】:2018-10-02 13:31:00
【问题描述】:
我正在使用 Mocha 和 Chai + ChaiHttp 来测试我的 API。我遇到的问题是,当 expect 语句失败时,我看不到任何错误消息。
这是我的代码:
it('POST /signup : should create a new user', async () => {
const user = {
name: 'Felix',
email: 'felix@gmail.com',
password: 'test',
};
const res = await chai.request(app).post('/signup').send(user);
expect(res).to.be.json;
expect(res).to.have.status(200);
expect(res.body).to.be.an('object');
expect(res.body.success).to.equal(true);
expect(res.body.user).to.have.property('falseAttribute'); // <- test passes with "name"
expect(res.body.user).to.have.property('token');
});
当它因为返回的使用预期具有falseAttribute 而失败时,它只会向我显示以红色突出显示的“it”文本:
Authentication tests
1) POST /signup : should create a new user`)
在我的 package.json 脚本中,我输入了 "test": "NODE_ENV=test ./node_modules/.bin/mocha test"
我已经在互联网上搜索过类似的问题,但我还没有找到任何东西。谢谢您的帮助!
【问题讨论】:
-
我感受到了你的痛苦。你有没有解决这个问题??!??!?!?! xkcd.com/979
标签: node.js testing mocha.js chai ecmascript-2017