Jest + Enzyme + ReduxForm 单元测试渲染问题

时间:2021-01-25 00:40:23

标签: reactjs jestjs material-ui enzyme redux-form

我正在对我的 redux 表单进行一些单元测试,但遇到了很多问题。目前我的测试看起来像这样

descendant

我使用的是材质 ui,因此使用了 createShallow。当我调试浅渲染时

describe('testing ForgotPassword functionality', () => {
let ForgotPasswordForm;
let defaultProps = {
    handleSubmit: (fn) => fn
}
let shallow;
let props = {
    forgotPassword: jest.fn()
}
let store = createStore(combineReducers({ form: formReducer, auth: authReducer }));

beforeEach(() => {
    shallow = createShallow({ dive: true })
    ForgotPasswordForm = shallow(
        <Provider store={store}>
            <ForgotPassword {...defaultProps} {...props} />
        </Provider>
    );
});

it('ForgotPassword renders correctly with email', () => {
    expect(ForgotPasswordForm).toMatchSnapshot();
});

it('check event on `Submit` button', () => {
    console.log(ForgotPasswordForm.debug())
    const emailField = ForgotPasswordForm.find('input[name="email"]');
    emailField.simulate('change', { target: {value: 'test@123.com'} });
    const submitButton = ForgotPasswordForm.find(Button).find('button');
    submitButton.simulate('click').simulate('submit');
    expect(defaultProps.handleSubmit).toHaveBeenCalledTimes(10);
});
})

这给我尝试进行查找带来了问题,因为它找不到 html。我一定在这里遗漏了一些明显的东西。我曾尝试再次潜水,但出现错误

0 个答案:

没有答案