[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

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.

Enzyme

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:

https://hackernoon.com/react-unit-test-example-tutorial-jest-enzyme-jsdom-mocha-chai-state-props-component-7ec850a98566#.lgd1p1a51

#react #unit #test #tutorial #example

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

​© 2013 by Waheng

  • Untitled-1
  • 51a5bd_6e89080215274fd7975c23895800b7b1-mv2
  • Blogger - Grey Circle
  • Twitter - Grey Circle
  • LinkedIn - Grey Circle