Question · JavaScript and React course · Module 13: Testing React

Testing forms - submit

How do you check in a test that the onSubmit callback was called with the correct data?

Answer options

  • By setting a global event listener with window.addEventListener
  • By reading the component's internal state through component.state
  • By using console.log() and checking the browser console
  • By passing a jest.fn() mock as onSubmit and checking toHaveBeenCalledWith()

You can check the correct answer by solving this task in the CodeWorlds game.