Set up Jest/React Testing Library tests. #66
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: