【发布时间】:2019-05-06 11:50:01
【问题描述】:
我在组件中有链接。我在 app.js 中指定了路由路径。
当我尝试使用 Swallow 和 Mount 在组件内查找 Link 控件时,它会抛出错误。
任何人都可以分享示例以在组件内查找链接按钮 代码
it('includes link to Next Exam', () => {
const home = shallow(
<StaticRouter>
<ComponentForm/>
</StaticRouter>,
);
expect(home.find(Link)).toHaveLength(1);
});
【问题讨论】:
-
请分享您尝试使用的代码,我们可以帮助您了解其中的问题。
-
@MatthewHerbst 更新了代码
-
是
Link在ComponentForm还是StaticRouter中? -
@MatthewHerbst 它在 ComponentForm 中。我放置的静态路由器是因为我在运行测试时遇到了一些错误。
标签: reactjs react-redux jestjs enzyme babel-jest