Avoid extensive usages of `.toMatchInlineSnapshot()` in tests to make it more useful
See original GitHub issueDescription
The extensive usages of .toMatchInlineSnapshot()
assertion causes unnecessary snapshot changes that are weakly related with the changes we made in each PRs. It renders the snapshots to be less useful.
We have to replace those assertions with more meaningful assertions.
Implementation model
We need to avoid snapshot testing using .toMatchInlineSnapshot()
in favour of testing components the way the user would use it. This means using meaningful assertions as much as possible.
To quote Kent C. Dodds:
The more your tests resemble the way your software is used, the more confidence they can give you.
Further reading material: Effective Snapshot Testing by Kent C. Dodds.
Tasks
Tests using .toMatchInlineSnapshot()
:
-
~/components/__tests__/report-button.test.tsx
-
~/components/__tests__/search-filter.test.tsx
-
~/components/__tests__/search-form.test.tsx
-
~/components/home/__tests__/homepage-contributing.test.tsx
-
~/components/home/__tests__/homepage-header.test.tsx
-
~/components/home/__tests__/homepage-start.test.tsx
-
~/components/home/__tests__/homepage-telemedicine-cta.test.tsx
-
~/components/home/__tests__/homepage-whatsapp-cta.test.tsx
-
~/components/kontak-darurat/__tests__/chatbot-section.test.tsx
-
~/components/layout/__tests__/global-header.test.tsx
-
~/components/layout/__tests__/navigation.test.tsx
-
~/components/ui/__tests__/alert.test.tsx
-
~/components/ui/__tests__/badge.test.tsx
-
~/components/ui/__tests__/button.test.tsx
-
~/components/ui/__tests__/feedback-section.test.tsx
-
~/components/ui/__tests__/responsive-img.test.tsx
-
~/components/ui/forms/__tests__/input-text.test.tsx
-
~/components/ui/forms/__tests__/input-textarea.test.tsx
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
What's wrong with snapshot tests. Since snapshot ... - Medium
In this article I'll try to explain why. I'll talk mostly about testing React components, because that's where I've used or have seen...
Read more >Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly.
Read more >Snapshot Testing - Jest - w3resource
Snapshot tests are a useful tool when you want to make sure your UI doesn't change unexpectedly. A typical snapshot test case for...
Read more >Jest testing: Top features and how to use them - LogRocket Blog
The first thing Jest does is load the tests and thus load the source code of your application, parsing the requires() ; Well,...
Read more >Snapshot Testing: Benefits and Drawbacks - SitePen
We explore some of the advantages and disadvantages of using snapshot testing as well as some tools and resources for using it successfully....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zainfathoni i see, noted for that thank you, I will trying to picking up this task ya mas 👌
Good luck @adibfirman !