Skip to Main Content
React Projects
book

React Projects

by Roy Derks
December 2019
Intermediate to advanced content levelIntermediate to advanced
474 pages
10h 3m
English
Packt Publishing
Content preview from React Projects

Rendering a React component for testing

Jest is based upon Node.js, meaning that it can't use the DOM to render your component and test its functionality. Therefore, you need to add a React core package to your project, which can help you render the component without a DOM. Let's take a look at this here:

  1. From your Terminal, execute the following command, which will install react-test-renderer in your project. It can be installed as a devDependency as you don't need to run tests on the build version of your application:
npm install react-test-renderer --save-dev
  1. With react-test-renderer installed, you can now import this package into the src/components/Header/SubHeader.test.js file. This package returns a method called ShallowRenderer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React Projects - Second Edition

React Projects - Second Edition

Roy Derks
Test-Driven React

Test-Driven React

Trevor Burnham

Publisher Resources

ISBN: 9781789954937Supplemental Content