Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

egghead.io

Test Network Edge Cases with cy.intercept() Command in Cypress

via egghead.io

Overview

Your app can behave in various ways on different network conditions. Cypress has an excellent toolset for setting up those conditions, enabling you to test your app thoroughly. That way, you can ship your app with confidence.
Cypress .intercept() command is one of the most fun commands to use. And it’s also one of the most useful.
Especially when you are done with all your happy paths and want to increase your test coverage with some edge cases.
These edge cases can mean different data, headers, or server behavior. You can modify all of these dynamically or with a static fixture prepared beforehand.
What you'll learn
Statically and dynamically stub response body
Test your application with different status codes
Modify request headers
Prevent your server from providing a cached response
Modify your request URL and add a query to it
Test slower network conditions by throttling or delaying a response
Bypass UI login by adding authorization header to your request

Syllabus

  • Simulate a Network Error Using .intercept() Command
  • Stub an API Request Status Code and Error Message with cy.intercept
  • Change a Response Body with cy.intercept to Provide Your Own Data in an API Call
  • Use a Fixture in Cypress to Provide Response Data to Network Requests
  • Configure cy.intercept to Only Intercept a Network Request Once
  • Dynamically Add Queries in Cypress Intercept Function Requests
  • Dynamically Combine Real and Mocked Response Body Data in Cypress
  • Prevent Response Caching in Cypress by Deleting 'if-none-match' Request Header
  • Test Slow Network Conditions in Cypress by Throttling and Delaying Intercepted Requests
  • Send Network Requests with Authorization Headers in an Intercepted Request with Cypress

Taught by

Filip Hric

Reviews

4.4 rating at egghead.io based on 24 ratings

Start your review of Test Network Edge Cases with cy.intercept() Command in Cypress

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.