Reactjs 反应测试库&x2B;路由器

Reactjs 反应测试库&x2B;路由器,reactjs,testing,react-router,react-testing-library,Reactjs,Testing,React Router,React Testing Library,我想在同一个测试文件中呈现不同的路由 例如,这是我的cooltest.test.js import { App } from '../App.js' import { renderWithRouter } from './renderHelper' test('Example - Render View', async () => { const route = '/dummy/Seguros' const { getByText, getByTestId } = render

我想在同一个测试文件中呈现不同的路由

例如,这是我的
cooltest.test.js

import { App } from '../App.js'
import { renderWithRouter } from './renderHelper'

test('Example - Render View', async () => {

  const route = '/dummy/Seguros'
  const { getByText, getByTestId } = renderWithRouter(<App />, { route })

  getByTestId('dummyHeader');
  getByText(route)
});

test('Example - Render Another View', async () => {

  const route = '/dummy/Ayuda/Seguros'
  const { getByText, getByTestId } = renderWithRouter(<App />, {
    route
  })

  getByText(route);
});
import { App } from './App.js'

ReactDOM.render(
  <React.StrictMode>
    <Router>
      <App/>
    </Router>
  </React.StrictMode>,
  document.getElementById('root')
);
问题是它总是进入我的主页或
“/”
网站


我做错什么了吗?

react testing discord上的一位用户帮助我发现了问题

如果任何人都有这个问题,这是一个关于路由器和它的位置的问题。 出于某种原因,路由器被直接放置在
app.js
文件上,而不是
index.js

这是将路由器置于
index.js中的正确方法

import { App } from '../App.js'
import { renderWithRouter } from './renderHelper'

test('Example - Render View', async () => {

  const route = '/dummy/Seguros'
  const { getByText, getByTestId } = renderWithRouter(<App />, { route })

  getByTestId('dummyHeader');
  getByText(route)
});

test('Example - Render Another View', async () => {

  const route = '/dummy/Ayuda/Seguros'
  const { getByText, getByTestId } = renderWithRouter(<App />, {
    route
  })

  getByText(route);
});
import { App } from './App.js'

ReactDOM.render(
  <React.StrictMode>
    <Router>
      <App/>
    </Router>
  </React.StrictMode>,
  document.getElementById('root')
);
再次感谢“ljosberinn | Gerrit Alex”的帮助