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

cypress request with FormData not parsed to json #24560

Open
yelhouti opened this issue Nov 7, 2022 · 4 comments
Open

cypress request with FormData not parsed to json #24560

yelhouti opened this issue Nov 7, 2022 · 4 comments
Labels
E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.

Comments

@yelhouti
Copy link

yelhouti commented Nov 7, 2022

Current behavior

When sending a request with FormData even if the server retrun application/json cypress keeps the response as ArrayBuffer

Desired behavior

It should parse it and have body as json

Test code to reproduce

const product = {};
formData.set('data', new Blob([JSON.stringify(product)], {type: 'application/json'}));
cy.request({
  method: 'POST',
  url: '/api/products',
  body: formData,
}).then(({ body }) => {
  console.log(body)
})

Cypress Version

10.8.0

Node version

16.13.0

Operating System

Fedora 36

Debug Logs

No response

Other

Workaround

cy.request({
    data
  }).then(res => {
    if (data.body instanceof FormData) {
      res.body = JSON.parse(new TextDecoder().decode(res.body));
      return res;
    } else {
      return res;
    }
  }).then(({ body }) => {
  console.log(body)
})
@marktnoonan
Copy link
Contributor

I was able to make a reproduction of this and is does seem to me that we shouldn't behave differently based on the contents of the outgoing request, for the same server response: https://github.com/marktnoonan/formdata-test

@yelhouti
Copy link
Author

@marktnoonan I totally agree, the solution should be to handle response based on response header content-type no matter the request type.

@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@demeralde
Copy link

I've been encountering this for all multipart/form-data tests I've run. This is for two APIs for separate projects, using separate tech on the back-end (Django and Node).

Not only that, this never happens when I've used Postman to test these endpoints. So it must exclusively be a Cypress problem.

Unfortunately I can't write complete tests because of this issue, so hopefully it gets fixed (it's been a long time since this was reported).

@effervescentia
Copy link

effervescentia commented Sep 27, 2023

I'm facing this too but using the TextDecoder work around for now, any plans for a fix in the near future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team.
Projects
None yet
Development

No branches or pull requests

5 participants