Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当使用Promise进行测试时,Sinon.getCall(1)返回null_Javascript_Unit Testing_Promise_Sinon - Fatal编程技术网

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')