我正在使用sinon和ava进行测试。我正在存根一些函数,并检查这些函数是否被调用。我检查了控制台,正在调用函数。但取而代之的是,sinon将其返回为notCalled(.false)。下面是一段代码。
test('test',(t)=>{
const transformerStub = sandbox.stub(transformer,'getActivity').resolves(JSON.stringify({"componentTypeID":1234}));
const getAuthTokenStub = sandbox.stub(getToken,'getToken').resolves({"Token":"Value"});
const axiosGetRequest = sandbox.stub(utils,'axiosGetRequest');
app.test(organizationId,learning);
t.is(transformerStub.called,true); // it is getting called . it works well and returns true
t.is(getAuthTokenStub.called,true); // it is getting called but returns false
t.is(axiosGetRequest.called,true); // it is getting called but returns false
};
{{1}}
});
答案 0 :(得分:0)
使用存根包装现有函数时,不调用原始函数。 https://sinonjs.org/releases/latest/stubs/
首先对存根转换器进行存根时,不会调用getToken.getToken和utils.AxiosGetRequest,因为不会调用真正的getActivity。
有2种选择: