cypress-testing-library
cypress-testing-library copied to clipboard
any `find*` command fails when is first to run in a test context
cypress-testing-libraryversion: 9.0.0nodeversion: 19.4.0npm(oryarn) version: 9.2.0 (npm)
What you did:
I was migrating from an older version of testing library where we have a Cypress test set up with a describe option of
{ testIsolation: false }, abeforeblock, twoitblocks, with the seconditblock beginning with afind*command.
What happened:
When the second
itblock ran, the following error was produced:TypeError: Cannot read properties of undefined (reading 'get') at $Command.command (webpack:///./src/index.js:40:29) From previous event: at CommandQueue.runCommand (http://localhost:50133/__cypress/runner/cypress_runner.js:149951:8) at next (http://localhost:50133/__cypress/runner/cypress_runner.js:150151:19)
Reproduction repository:
I've opened forked this repo with a quick fix for the issue, including a reproduction via your test suite.
Problem description:
It appears in this very specific circumstance,
this.get('prev')can yieldundefinedmaking the following.getfail.
Suggested solution:
Add a nullish check before accessing the second
.get. See forked repo's commit.
Thanks for continuing to provide an amazing utility. 🙏
I'm happy to PR the fix I've made in my fork, including the tests if desired.
Also, in case others run into this before its resolved, setting the following globally seems to ensure this.get('prev') is always defined by the time your test runs.
beforeEach(() => {
cy.then(() => null)
})
I ran into this today. Thank you for finding and providing a solution :smile:
I also ran into this issue. Thanks for the explanation & workaround! A MR would be appreciated :)
beforeEach(() => {
cy.then(() => null)
})
I put this in my e2e.ts file and it worked!
Any plans to release a fix for this? Thanks!