Cypress fixture returns an object that somehow is not an instanceof Object
See original GitHub issueCurrent behavior
cy.fixture("example.json").then(fixture => console.log(fixture instanceof Object))
Logs false
console.log(require("../../fixtures/example.json") instanceof Object);
Logs true
This is a problem because we use Immer to mutate state but it doesn’t work on the fixture data, breaking our app in Cypress tests.
Desired behavior
cy.fixture("example.json").then(fixture => console.log(fixture instanceof Object))
Logs true
Test code to reproduce
https://github.com/jordyvandomselaar/Cypress-fixture-no-instanceof-object-bug
Versions
- “cypress”: “^6.5.0”,
- MacOS Catalina 10.15.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
fixture | Cypress Documentation
cy.fixture() yields the contents of the file. Formatting is determined by its file extension. The yielded subject is not updated if the contents...
Read more >You provided an invalid object where a stream was expected ...
In my case I forgot to return an Observable in a switchMap. This caused that no Observable was received in the next RXJS...
Read more >Angular / Angular guidelines and best practices / Testing
Fixture is created for the host component and fixture.componentInstance will not be an instance of the component you want to test, it will...
Read more >Compare The Response To A Fixture - Gleb Bahmutov
Imagine a situation: you need to make an HTTP request from your Cypress test and compare the result to a JSON object stored...
Read more >cli/types/cypress.d.ts - Fossies
1 /* eslint-disable @typescript-eslint/no-unused-vars */ 2 ... 668 /** 669 * Returns a boolean indicating whether an object is a DOM object.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The code for fixtures can be found here: https://github.com/cypress-io/cypress/blob/develop/packages/server/lib/fixture.js#L39:L39
For now I would recommend requiring the fixtures as you showed where it will be
instanceof Object
.@jordyvandomselaar can I ask how you are using the object loaded from the fixture? Do you pass it to the application somehow? In the repo you provided you just have the spec code like
Which to me is fine, the above workarounds are enough. I would love to fix the application example if you can provide one.