Reactjs 解析React路由器测试的React惰性组件
我在Jest测试惰性组件时遇到问题。惰性组件不解析为React组件,而是惰性对象,因此它抛出Reactjs 解析React路由器测试的React惰性组件,reactjs,react-router,jestjs,lazy-loading,Reactjs,React Router,Jestjs,Lazy Loading,我在Jest测试惰性组件时遇到问题。惰性组件不解析为React组件,而是惰性对象,因此它抛出不变冲突:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:object。错误。我如何解析它们,以便它们可以作为要测试的元素?我的设置如下 我正在使用React路由器和Redux。尝试测试每个路由是否显示某些组件 测试包装器函数的设置如下: const mountWithPath = async (path, newProps = {}) => { const wr
不变冲突:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:object。
错误。我如何解析它们,以便它们可以作为要测试的元素?我的设置如下
我正在使用React路由器和Redux。尝试测试每个路由是否显示某些组件
测试包装器函数的设置如下:
const mountWithPath = async (path, newProps = {}) => {
const wrapper = mount(
<MemoryRouter initialEntries={[path]}>
<Provider store={store}>
<Suspense fallback={<div />}>
<CompAppNoRouter {...modProps} />
</Suspense>
</Provider>
</MemoryRouter>
);
await People;
await DashboardPage;
await ActivityPage;
await Analysis;
await Upload;
return wrapper;
即使我也是新的反应,但我可以肯定地说,没有必要 对于aysnc/等待处理悬念组件
const SomeMemoryFunction = (path, newProps) => {
// sry for redefining a function with same parameter
// and I don't have idea about passing newProps explicitly
// but pls refer the given blog for clear view.
return = modProps => (
<MemoryRouter initialEntries={[path]}>
<Provider store={store}>
<Suspense fallback={<div />}>
<CompAppNoRouter {...modProps} />
</Suspense>
</Provider>
</MemoryRouter>
)
}
const mountWithPath = (path, newProps = {}) => {
const wrapper = SomeMemoryFunction(path, newProps);
Analysis;
Upload;
return wrapper;
}
const SomeMemoryFunction=(路径,newProps)=>{
//sry用于重新定义具有相同参数的函数
//我不知道如何明确地传递newProps
//但请参考给定的博客以获得清晰的视图。
return=modProps=>(
)
}
const mountWithPath=(path,newProps={})=>{
const wrapper=SomeMemoryFunction(路径,newProps);
分析
上传;
返回包装器;
}
如果你在这个概念上仍然面临一些问题,我强烈建议你阅读这篇文章
const SomeMemoryFunction = (path, newProps) => {
// sry for redefining a function with same parameter
// and I don't have idea about passing newProps explicitly
// but pls refer the given blog for clear view.
return = modProps => (
<MemoryRouter initialEntries={[path]}>
<Provider store={store}>
<Suspense fallback={<div />}>
<CompAppNoRouter {...modProps} />
</Suspense>
</Provider>
</MemoryRouter>
)
}
const mountWithPath = (path, newProps = {}) => {
const wrapper = SomeMemoryFunction(path, newProps);
Analysis;
Upload;
return wrapper;
}