[英]'TypeError: store.dispatch is not a function' redux action testing with jest
I'm trying to write a test for this redux action:我正在尝试为此 redux 操作编写测试:
export const clearError = () => (dispatch: Dispatch<IStoreState>) => dispatch({ type: actionTypes.CLEAR_ACTIVATION_ERRORS });
Don't understand why it's happened because I did everything from the example step by step.不明白为什么会发生这种情况,因为我一步一步地从示例中完成了所有操作。 This is my test:这是我的测试:
import configureMockStore from 'redux-mock-store';
import * as actionTypes from '@const/actions';
import './__mocks__/reactNativeConfig';
import * as actions from '../index';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('index.ts -> clearError', async () => {
it('clearError', () => {
const expectedAction = {
type: actionTypes.CLEAR_ACTIVATION_ERRORS,
};
const store = mockStore;
return store.dispatch(actions.clearError)
.then(() => {
expect(store.getActions()).toEqual(expectedAction);
}
);
});
});
and when I run my test I have an error:当我运行我的测试时,我有一个错误:
18 | const store = mockStore;
19 |
> 20 | return store.dispatch(actions.clearError)
| ^
21 | .then(() => {
22 | expect(store.getActions()).toEqual(expectedAction);
23 | }
Please, colud you help me figure out what I'm doing wrong.请你帮我弄清楚我做错了什么。 Thank you!谢谢!
try giving mock store data like the example below尝试提供模拟商店数据,如下例所示
import configureMockStore from 'redux-mock-store';
import * as actionTypes from '@const/actions';
import './__mocks__/reactNativeConfig';
import * as actions from '../index';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
describe('index.ts -> clearError', async () => {
it('clearError', () => {
const expectedAction = {
type: actionTypes.CLEAR_ACTIVATION_ERRORS,
};
const store = mockStore("mock store data should be given here({loading: false})");
return store.dispatch(actions.clearError)
.then(() => {
expect(store.getActions()).toEqual(expectedAction);
}
);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.