Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check request body using cy.route2() #8695

Closed
Cesaario opened this issue Sep 29, 2020 · 3 comments · Fixed by #8739
Closed

Check request body using cy.route2() #8695

Cesaario opened this issue Sep 29, 2020 · 3 comments · Fixed by #8739

Comments

@Cesaario
Copy link

Cesaario commented Sep 29, 2020

Current behavior

When I use cy.wait('@test') to check the request that was mocked using cy.route2(), it does not contain a request body.
image

Desired behavior

I expected a behavior similar to the one using cy.route().
image

Test code to reproduce

/// <reference types="cypress"/>

describe('Patch Test', () => {
  before(() => {
    cy.visit('https://www.test-cors.org/');
  })

  const method = 'POST';

  it('Using cy.route2()', () => {
    cy.route2(method, '**', {}).as('Route2');

    cy.get('#client_method').select(method);
    cy.get('#client_postdata').type("test");
    cy.get('#btnSendRequest').click();

    cy.wait('@Route2').then(req => {
      console.log(req);
      cy.wrap(req.request).its('body').should('contain', 'test');
    })
  })
  it('Using cy.route()', () => {
    cy.server();
    cy.route(method, '**', {}).as('Route');

    cy.get('#client_method').select(method);
    cy.get('#client_postdata').type("test");
    cy.get('#btnSendRequest').click();

    cy.wait('@Route').then(req => {
      console.log(req);
      cy.wrap(req.request).its('body').should('contain', 'test');
    })
  })
})

Versions

Cypress 5.3.0
Windows 10
Chrome 85

@flotwig
Copy link
Contributor

flotwig commented Oct 2, 2020

Thanks for reporting this @Cesaario. This appears to be the "request" counterpart to the unexpected behavior reported here: #8536

As a workaround, you can intercept the request on the browser-side. This will cause the request body to be sent to the browser.

  it('Using cy.route2()', () => {
    // stub via request interceptor to get body sent to driver
    cy.route2(method, '**', (req) => { req.reply({}) }).as('Route2');

    cy.get('#client_method').select(method);
    cy.get('#client_postdata').type("test");
    cy.get('#btnSendRequest').click();

    cy.wait('@Route2').then(req => {
      console.log(req);
      cy.wrap(req.request).its('body').should('contain', 'test');
    })
  })

@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review and removed stage: work in progress There is an open PR for this issue [WIP] labels Oct 2, 2020
@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: needs review The PR code is done & tested, needs review labels Oct 6, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Oct 6, 2020

The code for this is done in cypress-io/cypress#8739, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@jennifer-shehane
Copy link
Member

Released in 5.4.0.

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

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Oct 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants