我试图使用sinon/chai/mocha来测试axios调用的参数,以确认某些参数的存在(理想情况下它们是有效的日期).
示例代码(在类myclass中)
fetch() {
axios.get('/test', { params: { start: '2018-01-01', end: '2018-01-30' } })
.then(...);
}
Run Code Online (Sandbox Code Playgroud)
示例测试
describe('#testcase', () => {
let spy;
beforeEach(() => {
spy = sinon.spy(axios, "get");
});
afterEach(() => {
spy.restore();
});
it('test fetch', () => {
myclass.fetch();
expect(spy).to.have.been.calledWith('start', '2018-01-01');
expect(spy).to.have.been.calledWith('end', '2018-01-30');
});
});
Run Code Online (Sandbox Code Playgroud)
不过,我已经尝试了许多选择,包括的匹配,expect(axios.get)
... expect(..).satisfy
,getCall(0).args
和爱可信-模拟适配器,但我无法弄清楚如何做到这一点.我错过了什么?