Shallow Render a React Component with Enzyme

Tyler Clark
InstructorTyler Clark

Share this video with your friends

Send Tweet

In this lesson we will shallow render a component and pass through different config options. Shallow rendering is useful to test components as individual units. This helps ensure that tests aren’t indirectly asserting on behavior of child components. We’ll also use the debug method to show how we can easily view our component for debugging purposes.

Lorenzo Gamboa
Lorenzo Gamboa
~ 3 years ago

Why is it returning me the following error after running the script npm test

Error: Cannot find module 'C:\Users\username\courses\test-react-components-with-enzyme-and-jest\node_modules\jest-cli'
Jonatas Miguel
Jonatas Miguel
~ 3 years ago

I was having trouble getting things running, but once I created the project with create-react-app and ignored the advice to replace the test script in the package.json file with jest, I was finally able to start seeing the results shown in the video.

escapiststupor
escapiststupor
~ 3 years ago

I don't understand, how can you pass a test when there is no expect? Shouldn't you be adding expect(wrapper).toMatchSnapshot(); ?

Brendan Whiting
Brendan Whiting
~ 2 years ago

Is it true that we shouldn't use arrow functions with mocha? Are we even using mocha in this context or is describe here referring to something else?

Josh Calkins
Josh Calkins
~ 2 years ago

Getting ReferenceError: bool is not defined when adding context and disableLifecycleMethods to the wrapper function. Has anyone else seen this?

Cree
Cree
~ 2 years ago

To anyone having issues with bool being undefined I believe it's pseudocode here.

Use true or false 👍