我有这个组件:
import React from 'react';
const UploadAsync = Loadable({
loader: () => import('components/Upload'),
loading: () => <LoadingComponent full />
});
const Component = () => {
return <UploadAsync />
}
export default Component
和测试:
import React from 'react';
import Component from './index';
describe('Component', () => {
it('should render correctly with upload component', () => {
const tree = create(<Component />).toJSON();
expect(tree).toMatchSnapshot();
});
});
如何在快照中看到上传组件而不是加载组件?
exports[`Content should render correctly with form component 1`] = `
<div>
<Loading
full={true}
/>
</div>
`;
到目前为止我已经尝试过setTimeOut
and Promises
.
Use Loadable.preloadAll()
在测试之前,您可以访问您需要的组件。
Docs https://github.com/jamiebuilds/react-loadable#preloading-ready-loadable-components-on-the-client
简单的例子:
all imports here
Loadable.preloadAll()
describe('TestName', () => {
//tests
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)