Upgrade to Pro — share decks privately, control downloads, hide ads and more …

React testing with Enzyme - Basics

React testing with Enzyme - Basics

Fundamentals on how what Enzyme is and how to perform testing of React components.

Avatar for Olivier Robert

Olivier Robert

October 04, 2017
Tweet

More Decks by Olivier Robert

Other Decks in Programming

Transcript

  1. Intro http://airbnb.io/enzyme/ • Made by AirBnB • Can be used

    with many test runners e.g. Jasmine, Chai or Jest • Provide component rendering and testing utilities to make it easier: ◦ Writing assertions ◦ Traversing of the component output
  2. Usage with Jest How to set it up: • Add

    NPM dependency: `npm install enzyme` • For full DOM rendering: ◦ Add other dependencies: `npm install jsdom enzyme-to-json` ◦ Configure JEST ⇒ See Enzyme Guide
  3. Core rendering API shallow • Renders only the component but

    not its children ⇒ Great for Unit Testing • Use it in most cases
  4. Core rendering API mount • Renders the component and its

    children ⇒ Great for Integration Testing • Use it when testing that props are passed down properly
  5. Core rendering API render • Renders the component and its

    children to an HTML file ⇒ Never used • Most expensive and slow
  6. 1 million dollar question What if I don’t want to

    use Enzyme? • Jest snapshot testing • React test renderer
  7. Thanks! Contact Nimbl3 [email protected] 399 Sukhumvit Road, Interchange 21 Klongtoey

    nua, Wattana Bangkok 10110 20th Floor, Central Tower 28 Queen's Road Central, Hong Kong nimbl3.com