【发布时间】:2020-08-10 17:55:03
【问题描述】:
如何测试我的 Redux-Form 组件?
我有这个测试:
describe('<SignIn />', () => {
let wrapper, store;
const props = {isWidthSmallThan750: true, classes: {}};
beforeEach(() => {
store = mockStore({});
wrapper = mountComponent(SignUp, props); //equal to mount(Component)
});
afterEach(() => {
wrapper = null;
store = null;
});
it('snapshot testing', () => {
expect(componentToJSON(SignIn, props)).toMatchSnapshot(); //equal to render.create(Component).toJSON
})
it('when form submitted, these actions may happen', () => {
const form = wrapper.find('form');
wrapper.find('input').at(0).simulate('change', {target: {value: 'Tigran'}});
wrapper.find('input').at(1).simulate('change', {target: {value: 'Tigran'}});
expect(wrapper.find('input').at(0).props().value).toBe('Tigran');
expect(wrapper.find('input').at(1).props().value).toBe('Tigran');
form.simulate('submit');
expect(store.getActions()).toEqual(null);
})
});
但是当 form.simulate 被调用时,我没有得到我的 onSubmit 函数调用。
我该如何解决这个问题?
【问题讨论】:
标签: reactjs redux jestjs enzyme redux-form