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:
- 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
- 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 ...