问题
From the Enzyme docs shallow, render, and mount are described, but when to use which method?
回答1:
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.
来源:https://stackoverflow.com/questions/44082820/enzyme-when-to-use-shallow-render-or-mount