question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid extensive usages of `.toMatchInlineSnapshot()` in tests to make it more useful

See original GitHub issue

Description

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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
adibfirmancommented, Aug 14, 2021

@zainfathoni i see, noted for that thank you, I will trying to picking up this task ya mas 👌

1reaction
rubiagatracommented, Aug 15, 2021

Good luck @adibfirman !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found