Testing React Components Flashcards
What is JEST?
Is a test runner and test assertion library.
What is the first principle of unit tests?
Never trust a test until you have seen it fail.
When to write tests?
When the value of the tests outweigh the test execution time and the complexity it adds up to the code base.
What aspects of the application should my react unit tests cover?
The user interface.
What does the storybook library do?
Render the *.story.js files in a ‘listable’ and ‘searchable’ manner
What is the ‘React Testing Library’ guideline?
The more your tests resembles the way your software is used the more confidence you’ll get.
How would you test a label element that shows “Username:” following the React Testing Library guidelines and best practices? Why not looking for a label element containing a specific id or other very-specific css selector?
getByText(‘username’). Because it will make it hard to refactor/change that component since we’re testing the implementation and not the final result (which is ‘username:’ being render).