Using Jest, how can I test that clicking a form's 'Submit' button has sent an HTTP request?

This page summarizes the projects mentioned and recommended in the original post on /r/learnjavascript

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • jest-dom

    :owl: Custom jest matchers to test the state of the DOM

  • In my unit test file, I am using jest-dom to simulate a DOM.

  • jest

    Delightful JavaScript Testing.

  • to the page. I would now like to add a unit test which confirms the submit button sends an HTTP request. How can I do that using the Jest testing framework? Here are some more details: In my test file, I've successfully rendered the form to the test DOM, and simulated a click to the submit button. How can I now assert that an HTTP request has been made? Any HTTP request will do for now. And I don't need any specific response from the HTTP request. In my unit test file, I am using jest-dom to simulate a DOM. The element in-question is rendered using vanilla JS. I'm not using React or any other framework. Thanks in advance.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts