Open DFurnes opened 5 years ago
I was able to work around this issue by creating my own simple MockList
replacement that just works as a function (and so graphql-tools
doesn't need to conditionally call .mock()
on the object):
/**
* Return a list of N items for a field, with an optional
* list of field overrides for the items in the list.
*
* @param {Number} count
* @param {Object} overrides
*/
function mockList(count, overrides = {}) {
return new Array(count).fill().map(() => overrides);
}
Since this is a relatively unique problem to using a graphql-tools
mocked schema within Cypress, it might make sense to include something similar in this library as a suggested workaround?
I ran into a spooky issue when using graphql-tools'
MockList
to mock lists in my schema, where as soon as I returned aMockList
in mymocks
oroperations
object, I'd get an error like this:Here's an example Cypress test snippet that reproduces this error:
The error above gets thrown here, because the
result instanceof MockList
condition always returnsfalse
when trying to build the mocked GraphQL response (even though loggingresult
to the console clearly shows it as aMockList
).I believe this is an issue with objects that "travel" between the main Cypress test runner & the actual page via the
window:before:load
event or theinvoke
command, since usinginstanceof
to compare objects created in a different window will always returnfalse
. (See also: similar issues described in cypress-io/cypress#3420 and cypress-io/cypress#2794.)