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.