【发布时间】:2020-04-21 16:40:36
【问题描述】:
在我的测试函数中尝试从 sinon 创建存根时出现上述错误。我正在尝试测试一个负责对其他端点进行 http 调用的函数。我试图理解为什么它不能解析提供的输出。
const sinon = require('sinon');
const sandbox = sinon.createSandbox();
describe('test endpoint', () => {
it('should be test function', async () => {
const stub = sinon.stub(someServiceMock.POST, '/funcName').resolves({ status: 204 });
sinon.assert.calledOnce(stub);
});
});
});
并获得AssertError: expected '/funcName' to be called once but was called 0 times
我在存根中传递的对象是
const someServiceMock = {
POST: {
'/funcName': () => {},
},
};
【问题讨论】:
标签: node.js unit-testing sinon serverless-framework