Feature Request: Cypress mount is chainable but not with testing-library
See original GitHub issuecypress-testing-library
version: 7.0.6node
version: 12.13.0npm
(oryarn
) version: 6.12.0
Relevant code or config
mount(
<Button data-testid="test-id">
Button
</Button>
).findByTestId('test-id');
What you did:
Cypress v7 introduced the mount
method for component testing. Mount is chainable and you can run cypress commands against it, like the following, for example:
mount(<Button onClick={onClick}>Button onClick</Button>)
.get('.Button-root')
.click()
.get('@onClick')
.should('be.called');
What happened: I tried to apply this concept to a test using Cypress Testing Library with the aforementioned code and it failed in finding the testid. The following, however, works:
mount(
<Button data-testid="test-id">
Button
</Button>
);
cy.findByTestId('test-id');
Reproduction repository:
Problem description: You cannot chain cypress testing library calls off of mount.
Suggested solution: Add support for chaining off of mount to align with the rest of the Cypress API.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Chained cypress-testing-library commands don't work as ...
I want to chain commands from cypress-testing-library, so that they are executed in the same context. In the example above I want to ......
Read more >Cypress Testing Library
Cypress Testing Library supports both jQuery elements and DOM nodes. This is necessary because Cypress uses jQuery elements, while DOM Testing ...
Read more >Test The Interface Not The Implementation - Gleb Bahmutov
The cypress.json file has all Cypress global configuration settings, where I enable component testing and fetch polyfill experimental features.
Read more >Modern React testing, part 4: Cypress and ... - Artem Sapegin
You'll learn how to test React apps end-to-end with Cypress and Cypres Testing Library, how to mock network requests with Mock Service ...
Read more >BUILDING RESILIENT SUPPLY CHAINS, REVITALIZING ...
will reduce supply chain vulnerabilities, and to work with America's ... qualified producers and they require extensive testing to meet ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree. If Cypress Testing Library was a React-specific Cypress plugin, I think it would make sense to add a
cy.mount
. But Cypress and Cypress Testing Library do not require React. This is probably why Cypress didn’t add acy.mount
command and instead require you to importmount
and use it.@NicholasBoll Your approach does indeed work, but I’m left questioning if this is even necessary. At this point I’m fine with the additional
cy.
and not adding additional complexity into the setup. Thank you.