Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何将URL注入jest+;反应组分的酶单元测试?_Unit Testing_Reactjs_Jestjs_Enzyme_React Router V4 - Fatal编程技术网

Unit testing 如何将URL注入jest+;反应组分的酶单元测试?

Unit testing 如何将URL注入jest+;反应组分的酶单元测试?,unit-testing,reactjs,jestjs,enzyme,react-router-v4,Unit Testing,Reactjs,Jestjs,Enzyme,React Router V4,我正在尝试使用jest+酶为react组件创建单元测试: it('renders the problem view without crashing', () => { // TODO: tell the test fixure that the current URL is /problems const wrapper = shallow(<App />); // ... check that the problem view is actually rende

我正在尝试使用jest+酶为react组件创建单元测试:

it('renders the problem view without crashing', () => {
  // TODO: tell the test fixure that the current URL is /problems
  const wrapper = shallow(<App />);
  // ... check that the problem view is actually rendered...
});
it('在不崩溃的情况下呈现问题视图',()=>{
//TODO:告诉测试修复程序当前URL存在问题
const wrapper=shallow()建议编写一种白盒单元测试,其中检索路由器对象并检查其URL->组件映射表的正确性。
然而,我想写一个黑盒单元测试:给定正确的环境(即URL),被测试的组件应该呈现正确的内容,而不管使用哪个客户端路由库


编辑2:Jest配置参数看起来几乎像我需要的,但似乎无法从测试内部设置。的答案给出了一些提示,但我在正式Jest文档中没有找到任何关于将测试中的自定义jsdom对象注入Jest的内容。

您的React路由器代码是什么样子的?它是了解您传递给应用程序组件的各种路由的道具可能会有所帮助@Michael:我不会将任何道具传递给应用程序组件:应用程序组件应该从URL中找出正确的路由并呈现正确的路径stuff@ValentinHuber-我认为您需要考虑测试您的路由组件不是您的应用程序组件。路由组件根据URL确定要传递到应用程序组件中的嵌套组件(作为props.children)。