问题描述
我想从 redux 商店模拟状态并使用 jest 测试它们
import React from 'react';
import { mount,shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import{ users,question,questions } from '../utils/_DATA';
import '../setupTests';
import { leaderBoard } from '../containers/leaderBoard';
import configureStore from 'redux-mock-store';
import renderer from 'react-test-renderer';
import { Provider } from 'react-redux';
const mockStore = configureStore([]);
const ComponentTest =(component) => expect(toJson(component)).toMatchSnapshot();
describe('Containers tests',() => {
let store;
let MyComponent;
beforeEach(() =>{
store = mockStore({
users,signUser:'tylermcginnis',questions
});
store.dispatch = jest.fn();
MyComponent = renderer.create(
<Provider store={store}>
<leaderBoard />
</Provider>
);
});
it('should render leaderboard without error',() => {
expect(MyComponent.toJson()).toMatchSnapshot();
})
写入 jest --watch
后,我发现此错误显示状态数据无法传递给组件
TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
The above error occurred in the <leaderBoard> component:
leaderBoard 组件可能会从商店检索传递的数据
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)