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

Set up Jest/React Testing Library tests. #66

Merged
merged 6 commits into from
Jan 20, 2023
Merged

Set up Jest/React Testing Library tests. #66

merged 6 commits into from
Jan 20, 2023

Conversation

ray-lee
Copy link
Contributor

@ray-lee ray-lee commented Jan 20, 2023

Description

This adds configuration needed to start writing tests using Jest and React Testing Library (instead of Mocha and Enzyme). Existing Mocha/Enzyme tests are unchanged. New Jest/RTL tests should be placed in the tests/jest directory. The npm test script now runs both the old Mocha/Enzyme tests as well as the new Jest/RTL tests.

Motivation and Context

The Enzyme test utility for React doesn't currently support React 17, and likely won't support React 18. In order to advance beyond React 16, we'll need an alternative for testing. The React team is recommending React Testing Library as a replacement. A common pattern for writing tests using React Testing Library is to mock components that are not under test using Jest's mock function, so Jest is included. While it's not necessary to use Jest as a test runner, mixing Mocha (as a test runner) and Jest (only for the mock function) would be confusing, so the new tests are configured to run using Jest.

Notion: https://www.notion.so/lyrasis/Set-up-React-Testing-Library-and-Jest-for-testing-in-admin-UI-ae75b457da19440a916b12a569dba289

How Has This Been Tested?

  • npm install in a clean directory (no lib, no node_modules) should work.
  • npm test should work.

Checklist:

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@ray-lee ray-lee marked this pull request as ready for review January 20, 2023 22:11
@ray-lee ray-lee requested a review from tdilauro January 20, 2023 22:12
Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 🚀

@ray-lee ray-lee merged commit 5b16633 into main Jan 20, 2023
@ray-lee ray-lee deleted the feature/jest branch January 20, 2023 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants