cypress: Failed to read the 'responseXML' property from 'XMLHttpRequest', `responseType` was 'text'
Example from docs produces error.
From https://docs.cypress.io/guides/guides/network-requests.html#Assertions
// spy on POST requests to /users endpoint
cy.route('POST', '/users').as('new-user')
// trigger network calls by manipulating web app's user interface, then
cy.wait('@new-user')
.should('have.property', 'status', 201)
In my example, I used:
cy.wait('@create').should('have.property', 'status', 201);
Produces the following error:
InvalidStateError: Failed to read the 'responseXML' property from 'XMLHttpRequest': The value is only accessible if the object's 'responseType' is '' or 'document' (was 'text').
The following example works:
cy.wait('@create').then(({ status }) =>
assert(status === 201, 'status is 201'),
);
Desired behavior:
Would like the example from the documents to work.
Preferably, I’d like cy.wait(...) to fail by default if a 200 isn’t returned, or to have a really easy way of adding our preferred status code to return. Something like cy.wait('@create', 201).
Versions
4.0.1
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 16 (4 by maintainers)
Hello
I had the same issue when upgrading cypress from 3.6.0 to 4.1.0.
Failing code was
Changing my code to :
fixed the issue
The example from the website works for a standard XHR request and should work in your case, so there’s something amiss. The test below works for example.
It appears it’s saying the
responseTypeof your XHR request istext. It’s a bit weird that it’s warning this is only accessible isresponseTypeis''ordocumentbecause''defaults totext.FWIW, I ran into this issue as well.
The offending line was:
Changing it to this solved the problem: