[React] Review: Unit Test is easy


Unit Test of React Component is a bit different, rather than verifying output of functions, Unit Test in React requires 4 extra testing purpose (Ref Artem):

  1. Testing basic component rendering

  2. Testing props

  3. Testing events

  4. Testing event handlers

Two most popular options are Jest and Enzyme. After spending hours in try out those tools, I end up in the great Airbnb open sourced Enzyme.


Jest is a JavaScript test runner maintained by Facebook. Included performance, mocking, snapshot, code coverage, sandbox.

When using Jest to test a React or React Native application, you can write a snapshot test that will save the output of a rendered component to file and compare the component’s output to the snapshot on subsequent runs. This is useful in knowing when your component changes its behaviour.

jsdom + Mocha

jsdom provides React the required DOM to render to, implementing a suitable subset of browser’s DOM implementations entirely in node/io.js.


is a library that wraps packages like React TestUtils, JSDOM and CheerIO to create a simpler interface for writing unit tests (work with shallow rendering).

Read More:


#react #unit #test #tutorial #example

Featured Posts
Recent Posts
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square