簡體   English   中英

酶測試,上下文不渲染元素

[英]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

v3.10.0日志

淺層:支持渲染和潛水()創建上下文()提供者和消費者(#1966)

確保您使用的是enzyme v3.10.0或更高版本enzyme-adapter-react-16 v1.15.1或更高版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM