Reactjs 用'包裹的测试组件;带路由器';出口时

Reactjs 用'包裹的测试组件;带路由器';出口时,reactjs,enzyme,Reactjs,Enzyme,我在测试在其道具中使用历史记录的组件时出错。我的测试: describe('Widgetcomponent', () => { const fakeProps = { title: 'Test title', history: { location: { pathname: '/' } }, redirectPath: '/path', }; it('should match snapshot', () => { const compon

我在测试在其道具中使用历史记录的组件时出错。我的测试:

describe('Widgetcomponent', () => {
  const fakeProps = {
    title: 'Test title',
    history: { location: { pathname: '/' } },
    redirectPath: '/path',
  };

  it('should match snapshot', () => {
    const component = mount(
      <MemoryRouter initialEntries={[{ pathname: '/', key: 'testKey' }]}>
        <Widget{...fakeProps} />)
      </MemoryRouter>
    );
    expect(component).toMatchSnapshot();
  });
});
description('Widgetcomponent',()=>{
常数fakeProps={
标题:'测试标题',
历史记录:{位置:{路径名:'/'}},
重定向路径:'/path',
};
它('应该匹配快照',()=>{
常量组件=挂载(
)
);
expect(component.toMatchSnapshot();
});
});
我得到一个错误:

不变冲突:一个元素只能有一个子元素

如何测试它?我不想使用“浅”字。

您有一个小错误:

  it('should match snapshot', () => {
    const component = mount(
      <MemoryRouter initialEntries={[{ pathname: '/', key: 'testKey' }]}>
        <Widget{...fakeProps} />)  <---HERE
      </MemoryRouter>
    );
    expect(component).toMatchSnapshot();
  });
it('应该匹配快照',()=>{
常量组件=挂载(
)   {
常量组件=挂载(
);
expect(component.toMatchSnapshot();
});
  it('should match snapshot', () => {
    const component = mount(
      <MemoryRouter initialEntries={[{ pathname: '/', key: 'testKey' }]}>
        <Widget{...fakeProps} />
      </MemoryRouter>
    );
    expect(component).toMatchSnapshot();
  });