Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire event type is not updating the redux form store value with latest version of react-testing-library #639

Closed
nanivijay opened this issue Jun 7, 2020 · 13 comments · Fixed by testing-library/user-event#322

Comments

@nanivijay
Copy link

  • @testing-library/react version: 10.2.1
  • @testing-library/user-event version: 11.2.1
  • Testing Framework and version:
    Jest v24
  • DOM Environment:

Relevant code or config:

import React from "react";
import { Provider } from "react-redux";
import { combineReducers, createStore } from "redux";
import { reducer as reduxFormReducer, reduxForm, Field } from "redux-form";
import { render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

const RenderTextField = additionalProps => props => {
  const fabricProps = getFabricPropsFromReduxFormProps(props);
  return (
    <div>
      <TextField {...additionalProps} {...fabricProps} />
    </div>
  );
};
const getFabricPropsFromReduxFormProps = props => {
  const {
    input,
    id,
    type,
    rows,
    placeholder,
    label,
    autoComplete,
    required,
    disabled
  } = props;
  const { onBlur, ...inputRemaining } = input;
  const typedType = type;
  // wrapping onBlur without event object due to issue: https://github.com/erikras/redux-form/issues/2768
  return {
    ...inputRemaining,
    onBlur: () => onBlur(undefined),
    id,
    type: typedType,
    rows,
    placeholder,
    label,
    autoComplete,
    required,
    disabled
  };
};
test("RenderTextField sets initial value and responds to change", async () => {
  const title = "title-text";
  const component = RenderTextField({ title });
  const label = "label-text";
  const initialValue = "test";
  const formName = "foo";
  const fieldName = "bar";
  const onChange = jest.fn();
  const onBlur = jest.fn();
  const fieldProps = {
    autoComplete: "off",
    component,
    id: "id-text",
    key: "key-text",
    label,
    name: fieldName,
    onChange,
    onBlur,
    placeholder: "placeholder-text",
    required: true,
    rows: 2,
    type: "text"
  };
  const TestForm = reduxForm({
    form: formName,
    initialValues: { [fieldName]: initialValue }
  })(() => <Field {...fieldProps} />);
  const store = createStore(combineReducers({ form: reduxFormReducer }), {});
  const result = render(
    <Provider store={store}>
      <TestForm />
    </Provider>
  );
  // expect(result.container).toMatchSnapshot();
  expect(store.getState()).toEqual({
    form: {
      [formName]: expect.objectContaining({
        values: { [fieldName]: initialValue }
      })
    }
  });
  const input = result.getByLabelText(label);
  const newValue = "newvalue";
  userEvent.clear(input);
  await userEvent.type(input, newValue, { allAtOnce: true });
  expect(onChange).toHaveBeenCalledTimes(2);
  expect(store.getState()).toEqual({
    form: {
      [formName]: expect.objectContaining({ values: { [fieldName]: newValue } })
    }
  });
});

What you did:

Unit testing redux form field change event

What happened:

Redux form field value is not updated in store

Reproduction:

Issue is happening in the below code
https://codesandbox.io/s/basic-react-testing-library-w-setuptestsjs-skclz?file=/src/Sample.test.js:0-2582

Issue is not happening with the older versions of libraries
https://codesandbox.io/s/basic-react-testing-library-w-setuptestsjs-u3lx8?file=/src/Sample.test.js

Problem description:

Store is not updated with the new value

Please help me what could be wrong here.

Thanks

@kentcdodds kentcdodds transferred this issue from testing-library/react-testing-library Jun 8, 2020
@kentcdodds
Copy link
Member

Hi @nanivijay,

I'm pretty sure this is related to this issue: testing-library/user-event#316

kentcdodds referenced this issue in testing-library/user-event Jun 8, 2020
kentcdodds referenced this issue in testing-library/user-event Jun 8, 2020
kentcdodds referenced this issue in testing-library/user-event Jun 8, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @nanivijay for bugs

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @nanivijay! 🎉

@kentcdodds
Copy link
Member

Thanks :)

@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 11.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nanivijay
Copy link
Author

@kentcdodds issue is still happening with the latest version of user-event library. here is the codesandbox url
https://codesandbox.io/s/basic-react-testing-library-w-setuptestsjs-skclz?file=/src/Sample.test.js

@kentcdodds kentcdodds reopened this Jun 9, 2020
@kentcdodds
Copy link
Member

Hi @nanivijay,

Sorry about that. I looked at it and there's a lot of moving parts in there it's hard for me to determine what the problem is. Could you do a little more digging please? Try to isolate the problem further?

@nanivijay
Copy link
Author

@kentcdodds sure i will do

@nanivijay
Copy link
Author

@kentcdodds during my investigation i found that the issue starts happening from @testing-library/dom - 7.9.0 . I updated the example to use fire event instead of userevent. fireevent was working till version 7.8.0. i looked at the change in v7.9.0 i didn't find any breaking change but you may have more context on the change. please take a look at this codebox https://codesandbox.io/s/basic-react-testing-library-w-setuptestsjs-u3lx8?file=/src/Sample.test.js

@nickmccurdy nickmccurdy transferred this issue from testing-library/user-event Jun 14, 2020
@nickmccurdy

This comment has been minimized.

@kentcdodds

This comment has been minimized.

@nickmccurdy nickmccurdy changed the title User event type is not updating the redux form store value with latest version of user-event and react-testing-library Fire event type is not updating the redux form store value with latest version of react-testing-library Jun 16, 2020
@nanivijay
Copy link
Author

anyone get a chance to investigate this issue. This is currently blocking us to upgrade the @testing-library. i tried to identify the cause but couldn't be able to figure out. please help

@nanivijay
Copy link
Author

Not seeing this anymore with the latest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants