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` request.body is ArrayBuffer for JSON requests with long Cyrillic strings

See original GitHub issue

Current behavior

When sending request with cyrillic strings in json data to url, stubbed by cy.intercept, request.body object is ArrayBuffer, not plain object.

// intercept some url with any data
cy.intercept(URL, {
  body: { result: 'ok' },
}).as('testRequest');

// send json request with cyrillic string in data (length must be more than 6)
sendRequest({name: "Фрауиванович"})
cy.wait('@testRequest')
    .its('request')
    .then((req) => {
      console.log(req.body); // is ArrayBuffer object, not plain object
});

// send json request without cyrillic in data
sendRequest({name: "FrausIvanovich"})
cy.wait('@testRequest')
    .its('request')
    .then((req) => {
      console.log(req.body); // is plain object, as expected
});

Desired behavior

When sending request with cyrillic strings in json data to url, stubbed by cy.intercept, request.body is plain object

// send json request with cyrillic string in data (length must be more than 6)
sendRequest({name: "Фрауиванович"})
cy.wait('@testRequest')
    .its('request')
    .then((req) => {
      console.log(req.body); // is plain object
});

Test code to reproduce

Test code to reproduce: https://github.com/KarKarbI4/cypress-cyrillic-intercept-issue/blob/main/cypress/integration/spec.js Test repo: https://github.com/KarKarbI4/cypress-cyrillic-intercept-issue

Versions

Cypress: cypress@7.1.0, cypress@7.2.0 Browser: Google Chrome 90 OS: MacOS Big Sur 11.2.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
sainthkhcommented, Jun 2, 2021

I submited PR at https://github.com/bevry/istextorbinary/pull/214. It’s now awaiting external fix.

3reactions
jennifer-shehanecommented, May 3, 2021

The example you gave would ‘sometimes fail’ the other assertions because the requests were being made synchronously, so sometimes the 3rd definition had already run by the time the first wait ran.

Regardless, the last test below will always reliably fail, as the response is an ArrayBuffer when the response data is Фраусиванович. Seems unexpected to me.

it('cy.intercept cyrillyc issue test', () => {
  cy.intercept('https://example.com/test', {
    body: { result: 'ok' },
  }).as('testRequest');

  cy.window().then(() => {
    let xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://example.com/test');
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify({ name: 'Frausivanovich' }))
  })
  cy.wait('@testRequest')
    .its('request')
    .then((req) => {
      expect(req.body).to.not.be.an('ArrayBuffer'); // ✅ passes
      expect(req.body).to.be.an('object'); // ✅ passes
    });

  cy.window().then(() => {
    let xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://example.com/test');
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify({ name: 'Фраус' }))
  })

  cy.wait('@testRequest')
    .its('request')
    .then((req) => {
      expect(req.body).to.not.be.an('ArrayBuffer'); // ✅ passes
      expect(req.body).to.be.an('object');  // ✅ passes
    });

  cy.window().then(() => {
    let xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://example.com/test');
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.send(JSON.stringify({ name: 'Фраусиванович' }))
  })

  cy.wait('@testRequest')
    .its('request')
    .then((req) => {
      expect(req.body).to.be.an('ArrayBuffer'); // ✅ passes
      expect(req.body).to.be.an('object'); // ❗️ fails
    });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

intercept - Cypress Documentation
Spy and stub network requests and responses. ... See "Intercepted requests" and Request/Response Modification with ... Stub a response with a JSON body:....
Read more >
Cypress 9.6.0 - response returned from cy.request has a body ...
The issue is that instead of an ArrayBuffer I should be getting normal JSON format response (ofc during the test in the app...
Read more >
Software-Pakete in »bionic«, Unterbereich web - Ubuntu
JavaScript utility for merging multiple objects into one. libjs-microplugin.js (0.0.3+dfsg-1) [universe]: Lightweight plugin / dependency system for libraries ...
Read more >
Falcon Sandbox v8.48.12 © Hybrid Analysis
Sets a global windows hook to intercept mouse events ... DNS Requests. Login to Download DNS Requests (CSV) ... Download All Memory Strings...
Read more >
cypress-intercept-formdata-identt - npm
This package is intended to be used with Cypress.io intercept command. As of version 6.2 or 6.3 the request.body accessed from the intercept...
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