Description:
We are currently using fireEvent.change in our test helpers, which is generating a warning with the message: "Using fireEvent.change may lead to unexpected results. Please use fireEvent.update() instead."
Current Setup:
Helper Function: textInputChange uses fireEvent.change to simulate changes in text input fields.
Warning: Jest provides a warning that suggests using fireEvent.update instead.
Current Helper Function:
const textInputChange = (parentWrapper, newText) => { const textbox = within(parentWrapper).getByRole('textbox'); return fireEvent.change(textbox, { target: { value: newText } }); };
Objective:
- Update the textInputChange helper function to use fireEvent.update (or even better maybe: the userEvent plugin) instead of fireEvent.change to resolve the Jest warning and ensure that the test behavior is consistent with current best practices.
- Update unit tests accordingly.
Steps to Reproduce:
Run unit tests using the existing textInputChange helper function with fireEvent.change.
Observe the warning suggesting the use of fireEvent.update.
Impact:
Changing from fireEvent.change to fireEvent.update is expected to cause failures in approximately 6 existing tests. The goal is to update the helper function and then address any resulting test failures by making necessary adjustments.
Action Plan:
- Update Helper Function:
- Modify the textInputChange function to use fireEvent.update or decide to use userEvent instead (since it resembles user interaction better).
Example updateEvent:
const textInputChange = (parentWrapper, newText) => { const textbox = within(parentWrapper).getByRole('textbox'); return fireEvent.update(textbox, newText); };
- Identify Failing Tests:
Run the unit tests after updating the helper function.
Identify and document the tests that fail due to the change.
- Fix Failing Tests:
Update the affected tests to work with the new behavior introduced by fireEvent.update.
Ensure that all tests pass and the expected behavior is consistent.
- Update Documentation:
Document the change in the test helper and any implications for future tests.
Update any test documentation or comments affected by this change.
Acceptance Criteria:
- The textInputChange helper function is updated to use fireEvent.update or userEvent
- All relevant tests are updated and pass successfully.
- No additional warnings are generated related to fireEvent.change.
- Documentation and comments are updated if needed to reflect the change.