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

 ̄綄美尐妖づ 提交于 2019-12-03 14:56:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!