23

From the Enzyme docs shallow, render, and mount are described, but when to use which method?

Preview
  • 35,317
  • 10
  • 92
  • 112
maasha
  • 1,926
  • 3
  • 25
  • 45
  • Does this answer your question? [When should you use render and shallow in Enzyme / React tests?](https://stackoverflow.com/questions/38710309/when-should-you-use-render-and-shallow-in-enzyme-react-tests) – Michael Freidgeim Aug 23 '23 at 22:12

1 Answers1

33

shallow

  • No children rendering
  • Isolated, you know for sure the error comes from here

render

  • No lifecycles
  • Render children
  • Less APIs (setState, debug...)

mount

Will require jsdom or similar.

  • Lifecycle methods, like componentDidMount
  • Render children

If some of your children are connected components, you probably don't want to use mount, or you will need to setup a <Provider> and store creation, which would be a bit painful, just use shallow in this case.

This post is really insightful about the subject.

Preview
  • 35,317
  • 10
  • 92
  • 112