Skip to content

How to test React components that depend on usePage? #675

Answered by rhysemmerson
pascaldevink asked this question in Help
Discussion options

You must be logged in to vote

You don't need to render the App component in order to test Foobar. Something like this will work

jest.mock('@inertiajs/inertia-react', () => ({
  usePage: () => ({
    props: {
      authenticatedUser: {/* */}
    }
  })
}))

render(<Foobar />);

Replies: 5 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@claudiodekker
Comment options

@reinink
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

You must be logged in to vote
2 replies
@pascaldevink
Comment options

@progdog-ru
Comment options

Answer selected by pascaldevink
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
8 participants