Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cy.invoke doesn't retain this context on object methods #3871

Closed
dwelle opened this issue Apr 3, 2019 · 2 comments · Fixed by #17189
Closed

cy.invoke doesn't retain this context on object methods #3871

dwelle opened this issue Apr 3, 2019 · 2 comments · Fixed by #17189

Comments

@dwelle
Copy link

dwelle commented Apr 3, 2019

Current behavior:

cy.invoke doesn't retain (properly bind) this context on object methods.

Steps to reproduce: (app code and test code)

describe(`test`, () => {
    it.only(`test`, () => {
        cy.window().then( win => {
            win.obj = {
                val: 42,
                get () { return this.val; }
            };

            // shallow invoke is fine
            cy.wrap(win.obj).invoke(`get`).should(`eq`, 42);

            // lodash's invoke works as correctly
            cy.wrap( Cypress._.invoke(win, `obj.get`) ).should(`eq`, 42);
            
            // but not Cypress' invoke
            cy.window().invoke(`obj.get`).should(`eq`, 42); // undefined
        });
    });
});

Versions

cypress: 3.1.3 (haven't seen any cy.invoke-related fixes in changelog, so I assume it's still not fixed in newer versions)

@sainthkh
Copy link
Contributor

sainthkh commented Nov 11, 2020

Confirmed that it fails:

it('t', () => {
  const a = {
    x: {
      f: () => 42,
    },
    g: () => 24,
  }

  cy.wrap(a).invoke('g').should('equal', 24) // passes
  cy.wrap(a).invoke('x.f').should('equal', 42) // passes
})

it(`test`, () => {
  cy.window().then( win => {
      win.obj = {
          val: 42,
          get () { return this.val; }
      };

      // shallow invoke is fine
      cy.wrap(win.obj).invoke(`get`).should(`eq`, 42);

      // lodash's invoke works as correctly
      cy.wrap( Cypress._.invoke(win, `obj.get`) ).should(`eq`, 42);
      
      // but not Cypress' invoke
      cy.window().invoke(`obj.get`).should(`eq`, 42); // undefined
  });
});

@sainthkh sainthkh added stage: ready for work The issue is reproducible and in scope type: bug labels Nov 11, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress labels Jul 3, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 20, 2021

Released in 8.0.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v8.0.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Jul 20, 2021
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jul 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants