错误无内容提供程序:useLeafletContext() 只能在测试地图组件笑话时在 <Map Container> 的后代中使用

问题描述 投票:0回答:0

我正在 jest 上编写一个组件的测试,它渲染地图并在地图上的两点之间构建一条路线。我使用 ReactLeaflet 和传单路由机。组件代码是这样的:

function Component() {
  return (
    <MapContainer>
       center={[project.lat, project.lng]}
        zoom={16}
        maxZoom={18}
      <RoutingMachine />
    </MapContainer>
  );
}

测试代码:

it('Проверяем что карта в макетах отрисовалась', () => {
  const initialState = {
    mapSearch: {
      zoom: 5,
      dataRoutes: [],
    },
  };

  const store = createStore(reducers, initialState);

  // store.dispatch(replaceMarkersCreator());

  const mapLayout = (
    <Provider store={store}>
      <MapLayout directionsInfo={directionsInfo} mapUpdate={false} />
    </Provider>
  );

  render(mapLayout);

  expect(screen.getByTestId('mapWrapper')).toBeInTheDocument();
});

运行测试时,出现错误 No contextprovided: useLeafletContext() can only be used in ascendant of .

当然,应用程序运行时不会出现这样的错误。我是测试新手。有人怀疑某处有什么东西不是锁而是开着的。但我不明白在哪里和什么。我请你提出想法。我将通过排除方法寻找错误))。预先感谢您。

reactjs jestjs react-testing-library react-leaflet
© www.soinside.com 2019 - 2024. All rights reserved.