Testing React with Enzyme

So far, we've managed to test our server and all GraphQL API functions. Currently, however, we're still missing the tests for our front end code. While we render the React code when requesting any server route, such as the /app path, we only have access to the final result and not to each component. We should change this to execute the functions of certain components that aren't testable through the back end. First, install some dependencies before using npm:

npm install --save-dev enzyme enzyme-adapter-react-16 ignore-styles jsdom isomorphic-fetch

The various packages are as follows:

  • The enzyme and enzyme-adapter-react-16 packages provide React with specific features to render and interact with the React tree. ...

Get Hands-On Full-Stack Web Development with GraphQL and React now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.