Skip to content

Wrapping Router aware components in test #373

Answered by ryansolid
uhon asked this question in Q&A
Discussion options

You must be logged in to vote

The children of <Router> can only be <Route> components.. Children of <Route> components can only be <Route> components. So most of the examples aren't right.

const { queryByRole } = render(() => <Counter />, {
      wrapper: (props) => {
        return (
          <Router
            root={(props) => (
              <RouteAwareWrapper>{props.children}</RouteAwareWrapper>
            )}
          >
            <Route path="/" component={() => <>{props.children}</>} />
          </Router>
        );
      },
    });

I believe is the closest to being correct. I'm gathering props.children is a getter that executes the component so it should be inside a page component.

You could also do this …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@uhon
Comment options

Answer selected by uhon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #366 on February 12, 2024 18:34.