我们正在使用sinon在reactjs应用程序中测试我们的api调用像这样: -
import * as Actions from 'routes/actions/Actions';
const requestAction = {
RequestShell() { Actions.request(); },
};
describe('testing for Actions', () => {
it('check whether request() method call is happening properly or not', () => {
const requestData = sinon.spy(requestAction, 'RequestShell');
requestAction.RequestShell();
sinon.assert.calledOnce(requestData);
requestData.restore();
});
现在我需要比较Actions.request()
返回类型是否为Json对象。如何使用 sinon 测试操作的返回类型?请帮助我。
答案 0 :(得分:1)
试试这个
<强> JS 强>
it('check whether request() method call is happening properly or not', () => {
const requestData = sinon.spy(requestAction, 'RequestShell');
requestAction.RequestShell();
assert(requestData.calledOnce);
requestAction.RequestShell.restore();
});
请参阅此链接sinon spies