【发布时间】:2018-12-18 08:01:21
【问题描述】:
我是使用 sequelize.js 在 node.js 中进行单元测试的新手。我关注了this tutorial to implement the api. 它工作正常,我需要对其进行测试以进行单元测试。 首先,我尝试测试 User 类的 post 操作。以下代码将使用 mocha 进行测试。
// create a user
app.post('/api/users', (req, res) => {
User.create(req.body)
.then(user => res.json(user))
})
我的尝试如下。
var index = require('../index');
describe('POST testing on user', function () {
it('should add a row', function (done) {
index.post('/api/users').send({ 'name': 'he' })
.end(function (err, res) {
chai.expect(res.status).to.equal(200);
done();
})
});
});
然后它会给出这个错误,说 index.post 不是一个函数。我应该在哪里出错以及如何纠正它以执行测试用例。
【问题讨论】:
标签: node.js mocha.js sequelize.js chai