question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cy.intercept: delay is not working on 204 No Content

See original GitHub issue

Current behavior

When using cy.intercept('POST', url, { statusCode: 204, delay: 5000 }) delay (or delayMs) is not respected.

Is this intended behavior? If so, why?

When running tests below I see:

First spec: image

Second spec: image

Desired behavior

When a request responds with 204 No Content delay (or delayMs) should work.

Test code to reproduce

it('post a comment 200 OK', () => {
    cy.intercept('POST', 'https://jsonplaceholder.cypress.io/comments', {
            statusCode: 200,
            delay: 5000,
    }).as('success');

    cy.visit('https://example.cypress.io/commands/network-requests');

    cy.get('.network-post-comment').should('have.value', '')

    cy.get('.btn-success').click();

    cy.wait('@success'); // waits 5000 ms

    cy.get('.network-post-comment').should('contain', 'POST successful!')
});

it('post a comment 204 No Content', () => {
    cy.intercept('POST', 'https://jsonplaceholder.cypress.io/comments', {
            statusCode: 204, // delay is not respected
            delay: 5000,
    }).as('success');

    cy.visit('https://example.cypress.io/commands/network-requests');

    cy.get('.network-post-comment').should('have.value', '')

    cy.get('.btn-success').click();

    cy.wait('@success'); // resolves immediately

    cy.get('.network-post-comment').should('contain', 'POST successful!')
});

Versions

  • Cypress: 6.5.0
  • Chrome: 88.0.4324.182
  • MacOS: 10.15.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Feb 24, 2021

I can recreate this issue. The delay is not applying for 204 content.

it('post a comment 200 OK', () => {
  cy.intercept('POST', 'https://jsonplaceholder.cypress.io/comments', {
    statusCode: 200,
    delay: 5000,
  }).as('success');

  cy.visit('https://example.cypress.io/commands/network-requests');
  cy.get('.network-post-comment').should('have.value', '')
  cy.get('.btn-success').click();

  cy.wait('@success'); // waits 5000 ms
});

it('post a comment 204 No Content', () => {
  cy.intercept('POST', 'https://jsonplaceholder.cypress.io/comments', {
    statusCode: 204, // delay is not respected
    delay: 5000,
  }).as('success');

  cy.visit('https://example.cypress.io/commands/network-requests');
  cy.get('.network-post-comment').should('have.value', '')
  cy.get('.btn-success').click();

  // resolves immediately, should fail with only 1sec timeout
  cy.wait('@success', { timeout: 1000 }); 
});
Screen Shot 2021-02-23 at 8 23 45 PM
0reactions
cypress-bot[bot]commented, Jul 20, 2021

Released in 8.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v8.0.0, please open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

intercept - Cypress Documentation
cy.intercept can be used solely for spying: to passively listen for matching routes and apply aliases to them without manipulating the request or...
Read more >
Cypress intercept does not match route with status 204
I get your point, but that differs a bit from what the problem is: The route /api/security/logout is not recognised as the alias...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
A few common cy.intercept gotchas and how to avoid them · The intercept was registered too late · cy.wait uses the intercept ·...
Read more >
Risk and Prevalence of Developmental Delay in Young ... - NCBI
What's Known on This Subject: Children with congenital heart disease demonstrate a high prevalence of low-severity developmental problems in the areas of ...
Read more >
Report - Investigation of the Challenger Accident - GovInfo
the underlying problem which led to the Challenger acci- ... and current astronauts, the Committee could find no evi- ... The content and....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found