Unit Testing #42
Replies: 3 comments 1 reply
-
|
I have included the React Testing Library and Jest-DOM with our project. Be sure to import your component in your test file along with testing-library and jest-dom (optional), so you can write your test statements. Please check the documentation on React Testing Library to become familiar with testing and check the current repo to see how I've done some testing in the |
Beta Was this translation helpful? Give feedback.
-
|
This was also a good article: https://jkettmann.com/beginners-guide-to-testing-react/ |
Beta Was this translation helpful? Give feedback.
-
|
From @dwidjaja945 (Summary of his video notes and conversations with me).
Check out Dylan's segment about Unit Testing here |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's continue the conversations around unit testing here.
The simplest way to add a unit test to your Component folder is to just create a file with structure:
<ComponentName>.test.js | .tsxin a folder called /tests inside your Component's folder.MyComponentFolder/ tests/ MyComponent.test.js | .tsx mycomponent.css MyComponent.js | .tsx MyComponent.stories.js | .tsx index.js | .tsxBy default, jest will look through all files and folders in this project and if it finds any files ending in
.test.jsor.test.tsx, those will be picked up by the test runner. Note: If you create an empty test file, it will throw an error with jest, so if you haven't written any tests yet but have a test file, add the following code to your test file so that jest doesn't complain.Run tests with
yarn testfrom the command line.Beta Was this translation helpful? Give feedback.
All reactions