我已经在堆栈溢出中看到了几个类似的条目,但是与我面临的这个问题并不完全相关。我们正在使用Jest进行测试,并使用redux-saga进行存储。
[最近,我们试图摆脱茉莉花,走向杰斯特。该测试曾经适用于Jasmine,但不适用于Jest。
这是违规测试,
describe('componentWillReceiveProps method', () => {
it('should call dispatch if entityType is changed', (done) => {
const {wrapper, props} = setup();
wrapperInstance = wrapper.instance();
wrapperInstance.isPagePoppedFromHistory = false;
setTimeout(() => {
expect(props.dispatch).toHaveBeenCalled();
done();
}, 300);
wrapperInstance.UNSAFE_componentWillReceiveProps(Object.assign({}, props, {
entityType: {key: ENTITY_TYPE_HCO}
}));
});
});
收到的错误是
Error: Uncaught [TypeError: Cannot read property 'then' of undefined]
at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)
at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:645:7)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) TypeError: Cannot read property 'then' of undefined
at UNSAFE_componentWillReceiveProps.setTimeout (/index.js:294:11)
at Timeout.callback [as _onTimeout] (/Window.js:643:19)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
违反组件的代码行是这些
componentWillReceiveProps(){
...
setTimeout(() => {
dispatch(fetchTableResults(resultsLimit, filterParams, qString, currentOrderOption,
undefined, undefined, resultBounds))
.then(() => {
dispatch(changePageNumber(nextPage));
});
});
...
}
关于我们为什么要看到这个的任何想法?任何帮助将不胜感激。
按照xdeepakv的建议结束了模拟调度方法。