question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: remoteJQuery is not a function

See original GitHub issue

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.

screen shot 2018-03-27 at 3 46 33 pm

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
kashyaprahul94commented, May 5, 2021

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:

window.$ = document.querySelector.bind(document)

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.

Cypress.on("window:before:load", () => {
  /**
   * Thankfully, Cypress searches for "jQuery" property on the state
   *  variable (cy), if that's present, it takes the precedence
   *  over window.$
   *  https://github.com/cypress-io/cypress/blob/7.0-release/packages/driver/src/cy/jquery.js#L12
   */
  Cypress.cy.state("jQuery", Cypress.$);
});

We hope that this could help others too 😃

1reaction
XPuigAcommented, Jan 3, 2020

@marioparris-qless I think I fixed it with the following code:

cy.on('window:before:load', (win) => {
    if (win.jQuery === undefined && (win.$ === undefined || win.$ === {})) {
        win.$ = Cypress.cy.$$;
    }
});

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress: TypeError window.parent.$ is not a function
The message about window.parent.$ sounds like you are testing a login form that is usually embedded in an iframe.
Read more >
cypress-io/cypress - Gitter
Tried to break it down - getting error: THEN function(){} ... Its mad about: Error: TypeError: $els[0].forEach is not a function. Florian Goussin....
Read more >
Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError - Some selector is not a function - jQuery is not a function - owlCarousel...
Read more >
JavaScript / DHTML Blog Posts by Ben Nadel
Ben Nadel's complete list of blog entries about JavaScript / DHTML.
Read more >
validator $.validator.methods[method] is undefined
I have this validator form code I have inherited which I am getting this error: $.validator.methods[method] is undefined.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found