Reactjs 不变量失败:不应使用<;链接>;a<;路由器>;
我的测试中出现错误: 不变量失败:不应在Reactjs 不变量失败:不应使用<;链接>;a<;路由器>;,reactjs,react-redux,jestjs,enzyme,react-router-dom,Reactjs,React Redux,Jestjs,Enzyme,React Router Dom,我的测试中出现错误: 不变量失败:不应在外部使用 我能做些什么 483 | state, 484 | }) => { > 485 | const component = mount(<Testrun {...props} />); | ^ 486 | return component; 487 | }; 4
外部使用
我能做些什么
483 | state,
484 | }) => {
> 485 | const component = mount(<Testrun {...props} />);
| ^
486 | return component;
487 | };
488 | it('should have an input for the username', function () {
483 |状态,
484 | }) => {
>485 |常数组件=安装();
| ^
486 |返回组件;
487 | };
488 |它('应该有用户名的输入',函数(){
您必须在路由器的子级内部创建链接标记在实际项目中,您的
嵌套在某个父级中,该父级也与某个父级一起包装,而该父级中的某些父级也具有
或
。
它们提供了
所需的上下文(我的意思是React在这里)
所以你需要一些路由器版本在你的测试中
const component = mount(<MemoryRouter><Testrun {...props} /></MemoryRouter>);
const component=mount();
您可以使用任何其他路由器,但由于易于配置和控制,因此在测试中特别有用。必须有一个应用于组件外部的组件。因此,您得到以下错误: 不变量失败:不应在外部使用 在零部件内部移动零部件