Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在使用酶并且非常喜欢它。它适用于 react 16,直到我想测试使用 react 的新上下文 api 的新项目。
如果我只使用浅层渲染我的基本组件,并且控制台记录组件的调试,我可以看到它的内容,但是当我将新的上下文 api 与提供者和消费者一起使用时,我会得到<undefined />渲染。酶不会渲染组件,但反应会。
<undefined />
有人可以提供一些指导。
谢谢你。
对这个和其他 React 16.3 功能的支持将包含在下一个酶版本中,该版本将于今年夏季中旬发生(如这里所说)。
目前,这里有一个解决方法:
const outer = shallow(<SimpleComp />); const Children = outer.props().children({ /* context */ }); const wrapper = shallow(Children);
要将 mount() 与新的 Context API 一起使用,请使用此酶补丁。