[英]Jest enzyme shallow test is not rendering all elements of the React component
[英]enzyme test, context not rendering elements
我正在使用酶来编写我的测试,在向我的consumer component
在这种情况下是consumer component
中添加上下文之前,渲染的快照没有显示任何元素,每次我添加一个dive()
或shallow()
我得到相同的错误如何在使用上下文时访问元素
const wrapper = shallow( <MyComponent {...initialProps} store={mockStore(initialState)} />, {context}, ); const contents = wrapper .dive() // dive in connect .dive() // dive in withLogss .dive() // dive in Motion .find("MyComponent") .dive(); // dive in Host expect(contents.context()).toEqual({myBoolean: true}); it("should render properly", () => { expect(contents).toMatchSnapshot(); }); Result: <ContextConsumer> <Component /> </ContextConsumer>
Enzyme
之前v3.10.0
缺乏支持阵营的新语境下的API 。
浅层:支持渲染和潜水()创建上下文()提供者和消费者(#1966)
确保您使用的是enzyme
v3.10.0
或更高版本和enzyme-adapter-react-16
v1.15.1
或更高版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.