You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am making a JSONP call. The point is that I want to include some trusted thrid-party javascript to my site, and have it evald.
Assuming I would want to get jquery dynamically pulled in on production, while in the test I want to do some magic instead, I would create a jquery.js file in the fixtures directory and do:
An error was thrown while processing a network event: 'jquery.js' is not a valid JavaScript object.
SyntaxError: Unexpected token ';'
If I simply rename the file to jquery.txt, it works fine, but then I don't have any of the IDE tools to edit a js file.
Desired behavior
When a JS file is being used as a fixture in an intercept call, cypress does not even attempt to interpret it, and just passes down the content. This is because Cypress automatically assumes js files are js that is evaluated and returns a js object. It would be nice to have a first class mechanism to specify the type expected for files in general. If this were the case, you could treat a JS file appropriately in this scenario.
Hi @whydoievenneedthis, thank you for logging this issue. By default cypress treats the contents of a js file as a JSON object. I believe to accomplish what you will want to accomplish, you can jquery.js,null as the fixture. The null will tell it to just use the contents as is without trying to automatically convert it to an object (See the note at the bottom of this section https://docs.cypress.io/api/commands/fixture#Encoding). Does that work for you?
Hi @ryanthemanuel, this is what I was looking for, thanks. Now that I know what I am looking for, I was able to find the info in the documentation as well, but I still think it would make sense to have the ,null behaviour the default for the interception fixtures.
ryanthemanuel
changed the title
Cannot use fixture while intercepting JSONP requests
Create a first class API to explicitly define the type of response
Nov 22, 2022
@whydoievenneedthis I updated this to be a feature request. I think the experience we've seen thus far is for JS files to return JS objects; however, I could see a use case for specifying the type for a given fixture in a more first class fashion. Routing this to the e2e team for prioritization.
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
I also was able to use the fixture: 'myFile.js,null' workaround, but the docs on this were actually wrong- they say that ,null will always treat the data as Buffer:
You can specify null as the encoding in order to read the file as a Cypress.Buffer instance instead.
Current behavior
I am making a JSONP call. The point is that I want to include some trusted thrid-party javascript to my site, and have it evald.
Assuming I would want to get jquery dynamically pulled in on production, while in the test I want to do some magic instead, I would create a
jquery.js
file in thefixtures
directory and do:This however results in the well-known error:
If I simply rename the file to
jquery.txt
, it works fine, but then I don't have any of the IDE tools to edit a js file.Desired behavior
When a JS file is being used as a fixture in an intercept call, cypress does not even attempt to interpret it, and just passes down the content. This is because Cypress automatically assumes
js
files are js that is evaluated and returns a js object. It would be nice to have a first class mechanism to specify the type expected for files in general. If this were the case, you could treat a JS file appropriately in this scenario.Test code to reproduce
Failing test:
https://github.com/whydoievenneedthis/cypress-test-jsonp-js-fixture/blob/master/cypress/e2e/spec.cy.js
Cypress Version
11.0.0
Node version
18.10.0
Operating System
windows 10
Debug Logs
No response
Other
This is not a duplicate of #1271
The text was updated successfully, but these errors were encountered: