【发布时间】:2018-08-01 10:22:46
【问题描述】:
我已经阅读并尝试了很多方法来做到这一点,我有一个如下所示的模块。
//echo.js
module.exports = (services, request) => {
logger.debug('excecuting');
return true;
};
我想使用 sinon 为这个模块编写单元测试,到目前为止我所做的尝试是。
describe('test', function() {
const echo1 = require('./echo');
var spy1 = sinon.spy(echo1);
beforeEach(() => {
spy1.resetHistory();
});
it('Is function echo called once - true ', done => {
echo1(testData.mockService, testData.stubRequest); //calling module
spy1.called.should.be.true;
done();
});
});
我得到以下失败的输出,尽管我看到我的函数在输出窗口中被调用
1) test
Is function echo called once - true :
AssertionError: expected false to be true
+ expected - actual
-false
+true
at Context.done (echo_unit.js:84:27)
谁能告诉我如何在 nodejs 中测试模块
【问题讨论】: