简体   繁体   English

酶浅渲染呈现儿童组件

[英]Enzyme shallow render is rendering children components

I'm trying to shallow render a component to perform some basic unit tests. 我正在尝试浅显示一个组件来执行一些基本的单元测试。

The component I am doing this on has two child components which are rendered several times each depending on the parents props. 我正在执行此操作的组件有两个子组件,每个组件根据父级道具呈现多次。

When querying the shallow rendered component, the child elements are being rendered -fully- also, meaning that the children's HTML elements are also accessible. 在查询浅层渲染组件时,子元素也正在被渲染,这意味着子元素的HTML元素也是可访问的。

I am using Karma, Browserify, Jasmine and Enzyme, and can post the configs for each if needed. 我正在使用Karma,Browserify,Jasmine和Enzyme,并且可以根据需要发布每个配置。 Has anybody seen similar behaviour before? 以前有人见过类似的行为吗?

This is the correct behaviour. 这是正确的行为。 The different to the other render methods from enzyme is, that it does not call any lifecycle methods and that it does not convert to real html, but it will render all its childs and childs of the childs and so on. 与酶的其他渲染方法的不同之处在于,它不会调用任何生命周期方法,并且它不会转换为真正的html,但它将呈现其子项的所有子项和子项,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM