Testing - Now you don't have to even write tests anymore! (kind of)

For anyone who see the news, Jest now supports snapshot testing! This is an alternate model to the typical “ok, I’m going to sit down and write some tests, simulate the DOM, etc.” How it works, explained simply:

  • Run Jest
  • Snapshots of your components are made and stored on disk
  • Every time you run Jest after that, if you’ve altered your code and any of the snapshots fail to match, the tests fail

You can also get more detailed than that, of course. In your test code, you can:

  • Take a snapshot
  • Simulate a button click
  • Take another snapshot
  • Simulate entering some text and clicking another button
  • Take another snapshot

In other words, you can get up and running immediately with some very basic and easy-to-write tests. This is huge for people who always feel like there’s no time to write tests, especially when you’re trying to get an MVP off the ground!

My eventual plan is to use Jest for testing my React front-end, and use Meteor’s testing engine for the back end.

6 Likes

Thanks for posting. I must check this out!

Does it work for button clicks as well? I mean events too?

Yep! Check out this example.

I wonder if its as awesome as it sounds. Have to give it a try.

1 Like

Now that’s very interesting. My first impression from the FDA and regulatory perspective: it may be difficult to argue that this is a validation test (as the FDA considers them), however it would certainly qualify as a verification test.

The thinking with the FDA is they want developers to a) use at least one end-to-end walkthrough (such as Nightwatch), and b) more than one testing solution, so as to avoid systematic testing biases. Using multiple methodologies is specifically encouraged; and this would be welcomed as a part of most any testing strategy.

Good stuff here.

1 Like

Maybe it is. I’ve kinda drunk the Facebook kool-aid, so take it with a grain of salt. :wink: But seriously, as someone who is too lazy/has no time to write tests, I’m really liking this so far.

BTW, Dan Abramov’s tweet about what’s wrong with traditional unit tests.

Okay. That’s possible. That’s detecting state changes and UI updates.

I mean the othe kind of actions. Testing an action after a UI event. I know the how to get around with that too :wink:

Honestly I haven’t dug deep enough into it just yet, I’ve only scratched the surface.