Skip to content

How to test an API has NOT been called. #27470

Discussion options

You must be logged in to vote

Testing that an API call has not been made can sometimes be tricky due to the asynchronous nature of the test environment. It's possible that the randomness you're experiencing could be due to various factors, such as timing issues or the specific interactions between Cypress, cy.spy(), and cy.intercept(). Let's discuss some potential improvements to your test setup to ensure more reliable results.

  1. Ensure Spies are Reset:
    Before each test, it's a good practice to reset the spies to ensure that any state from previous tests doesn't carry over and affect the current test.

    beforeEach(() => {
      cy.spy().as("theSpy");
    });
  2. Using .wait() Command:
    Sometimes, adding a .wait() command after the…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@hamidmayeli
Comment options

@DevJSter
Comment options

@hamidmayeli
Comment options

@msmosavar
Comment options

Answer selected by hamidmayeli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants