react-test-renderer:如何注入上下文?

时间:2019-06-05 06:26:38

标签: reactjs testing jestjs datacontext react-test-renderer

我的反应组件状态取决于其上下文。对于正常测试:

我的测试用例喜欢:

const wrapper= shallow(<Storage />,{context: {valley: valley}});
expect(wrapper.is('Fragment')).toBeTruthy();

上下文有效,但是我想像react文档https://react.docschina.org/docs/shallow-renderer.html一样应用react-test-renderer:

import ShallowRenderer from 'react-test-renderer/shallow';

const renderer = new ShallowRenderer();
renderer.render(<Storage />, {context: {valley: valley}});
const result = renderer.getRenderOutput();
console.log(restult);

,但是我发现上下文尚未注入到Component中。 如何将上下文注入ShallowRenderer和ReacterTestRender对象,如:

ReactTestRenderer = require('react-test-renderer');

const renderer = ReactTestRenderer.create(
 <Link page="https://www.facebook.com/">Facebook</Link>
);

0 个答案:

没有答案