'cy.intercept randomly not work when "delay" is set

I use cy.intercept to mock an api.

But I can't understand why the requests are not always intercepted by cy.intercept. The failure is random.

Here is my intercept function

  cy.intercept('GET', '**/api/search?searchValue=**', {fixture: 'searchFixutre.json', delay: 500}).as('api');

Randomly, when this route is called several times quickly, Cypress does not intercept the request and it is sent directly to the api server.

Note that this problem does not occur when I delete the "delay" property

cy.intercept('GET', '**/api/search?searchValue=**', {fixture: 'searchFixutre.json'}).as('api');


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source