Enzyme: When to use shallow, render, or mount?

maasha picture maasha · May 20, 2017 · Viewed 7.6k times · Source

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

Answer

Balthazar picture Balthazar · May 20, 2017

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.