Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm test failing on initial install #10

Open
jkoren opened this issue Jan 14, 2022 · 2 comments
Open

npm test failing on initial install #10

jkoren opened this issue Jan 14, 2022 · 2 comments

Comments

@jkoren
Copy link

jkoren commented Jan 14, 2022

This seems to be a very good video.
I installed the repo and npm test failed: Invariant failed: You should not use <Switch> outside a <Router>
Here's the steps:
➜ git clone https://github.com/harblaith7/React-Testing-Library-Net-Ninja.git
➜ React-Testing-Library-Net-Ninja git:(main) npm install
➜ React-Testing-Library-Net-Ninja git:(main) npm start
➜ React-Testing-Library-Net-Ninja git:(main) git checkout 01-Starter-Project
➜ React-Testing-Library-Net-Ninja git:(main) npm test

  ● renders learn react link
    Invariant failed: You should not use <Switch> outside a <Router>

      3 |
      4 | test('renders learn react link', () => {
    > 5 |   render(<App />);
        |   ^
      6 |   const linkElement = screen.getByText(/learn react/i);
      7 |   expect(linkElement).toBeInTheDocument();
      8 | });

@jkoren
Copy link
Author

jkoren commented Jan 15, 2022

I fixed this by surrounding the switch in in App.js with BrowserRouter, as described in stackoverflow

      <BrowserRouter>
        <Switch>
          <Route strict exact path="/" component={TodoPage}/>
          <Route strict exact path="/followers" component={FollowersPage}/>
        </Switch>
      </BrowserRouter>

@Alireza-ce
Copy link

This seems to be a very good video. I installed the repo and npm test failed: Invariant failed: You should not use <Switch> outside a <Router> Here's the steps: ➜ git clone https://github.com/harblaith7/React-Testing-Library-Net-Ninja.git ➜ React-Testing-Library-Net-Ninja git:(main) npm install ➜ React-Testing-Library-Net-Ninja git:(main) npm start ➜ React-Testing-Library-Net-Ninja git:(main) git checkout 01-Starter-Project ➜ React-Testing-Library-Net-Ninja git:(main) npm test

  ● renders learn react link
    Invariant failed: You should not use <Switch> outside a <Router>

      3 |
      4 | test('renders learn react link', () => {
    > 5 |   render(<App />);
        |   ^
      6 |   const linkElement = screen.getByText(/learn react/i);
      7 |   expect(linkElement).toBeInTheDocument();
      8 | });

you can watch the solution of this error in video #8 - Assertions.
you should wrap your component around browser router.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants