Test Successful Async Form Submissions with React Router

InstructorJason Brown

Share this video with your friends

Send Tweet

In this lesson we'll explore how to test that an async form submission successfully happened using Jest. We'll also take advantage of react-testing-library to render our react components to a fake dom. We'll use MemoryRouter to mock what a browser would normally do in the event of a transition, and create a fake component route to confirm that the submission successfully redirected us to the url we wanted.

Mateusz Leonowicz
~ 5 years ago

What you do here is basically testing the behaviour of the Router. To truly (and simply) test just the App component in this case, I'd suggest just rendering it with mocked version of history with spied push, and just verify if after submitting the form that spied push function has been called.