cypress: TypeError: remoteJQuery is not a function
Current behavior:
cy.get(selector) works fine.
cy.get(selector).then((elem) => {}) with any callback results in TypeError: remoteJQuery, with no extra information
Desired behavior:
cy.get(selector).then((elem) => {}) should give me access to the element.
Test code:
it('example', () => {
cy.get('#cy-div')
.then(elem => {
elem;
})
})
I’ve tried cy v2.0.4 and v2.1
on Mac OS 10.13.3 using chrome.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 18 (3 by maintainers)
We were in the similar situation, where our website made use of window.$ as something than jQuery.
To give you a surprise, this is what we have:
It really made us worried initially that we would have to change all the occurrences of
$(...)to something else in order to make the Cypress work, but luckily, after gloating inside the cypress source code, we found something that could work for us & guess what, it did.We hope that this could help others too 😃
@marioparris-qless I think I fixed it with the following code:
For anyone else having the same problem, what the code does is, before loading every page in the spec, check if the Window object has the jQuery or $ properties, and if not, assign the jQuery that comes with Cypress to Window.$. As script tags are loaded after this, if the page uses a jQuery library, that one will override the one we set, so the page will still work and we can use jQuery from Cypress.