【发布时间】:2020-01-26 04:58:18
【问题描述】:
尝试对我的控制器进行单元测试,但这样做时出现以下错误。
我乐于接受以不同方式测试我的控制器的答案。
错误:
TypeError: 预期的 sinon 对象
const test = require('sinon-test');
describe('index (get all)', function() {
beforeEach(function() {
res = {
json: sinon.spy(),
status: sinon.stub().returns({ end: sinon.spy() })
};
expectedResult = [{}, {}, {}];
});
it(
'should return array of vehicles or empty array',
test(() => {
this.stub(Vehicle, 'find').yields(null, expectedResult);
Controller.index(req, res);
sinon.assert.calledWith(Vehicle.find, {});
sinon.assert.calledWith(res.json, sinon.match.array);
})
);
});
【问题讨论】:
标签: javascript node.js express sinon chai