Javascript 当使用Promise进行测试时,Sinon.getCall(1)返回null
我正在尝试测试以下函数Javascript 当使用Promise进行测试时,Sinon.getCall(1)返回null,javascript,unit-testing,promise,sinon,Javascript,Unit Testing,Promise,Sinon,我正在尝试测试以下函数 function doThing(client, id) { return (dispatch, getState) => { dispatch(getThingRequest()); const {session} = getState(); return client.getThing(session, id) .then(thing => { dispatch(getThingSuccess(thi
function doThing(client, id) {
return (dispatch, getState) => {
dispatch(getThingRequest());
const {session} = getState();
return client.getThing(session, id)
.then(thing => {
dispatch(getThingSuccess(thing));
})
.catch(error => {
dispatch(getThingFailure(error));
});
};
}
function getThingRequest() {
return {
type: 'GET_THING_REQUEST'
};
}
function getThingSuccess(thing) {
return {
type: 'GET_THING_SUCCESS',
thing
};
}
function getThingFailure(error) {
return {
type: 'GET_THING_FAILURE',
error
};
}
这是我到目前为止所拥有的
test('get thing success', function() {
const client = {getThing: function() {}};
const thing = {'a': 123};
sinon.stub(client, 'getThing').returns(Promise.resolve(thing));
const fn = getThing(client, '1');
equal(typeof fn, 'function');
const dispatch = sinon.spy();
const getState = () => ({session: {}});
fn(dispatch, getState)
dispatch.getCall(0).calledWith({ type: 'GET_THING_REQUEST' });
dispatch.getCall(1).calledWith({ type: 'GET_THING_SUCCESS', thing: thing });
});
我得到的错误如下,但我不知道为什么会发生这种情况
TypeError:“null”不是对象(正在计算)
'dispatch.getCall(1.calledWith')