酶:何时使用浅色,渲染或镶嵌? [英] Enzyme: When to use shallow, render, or mount?

查看:69
本文介绍了酶:何时使用浅色,渲染或镶嵌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档渲染描述了,但是何时使用哪种方法?

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

推荐答案




  • 没有孩子渲染

  • 已隔离,您肯定知道错误来自这里


    • 无生命周期

    • 渲染儿童

    • 较少的API( setState 调试 ...)

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

    将需要jsdom或类似内容。

    Will require jsdom or similar.


    • 生命周期方法,例如 componentDidMount

    • 渲染子级en

    如果您的某些孩子是相连的组件,您可能不想要使用 mount ,或者您需要设置< Provider> 并创建存储,这会有点很痛苦,在这种情况下,只需使用 shallow

    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.

    这篇关于酶:何时使用浅色,渲染或镶嵌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆