Closed reintroducing closed 3 years ago
mount
is not part of the Cypress.Chainable
interface and we cannot control what is returned by it. You could always create your own mount
for your tests:
// support.ts/js
import { mount } from '@cypress/react'
declare global {
namespace Cypress {
interface Chainable {
mount(node: React.ReactNode): Chainable<JQuery>
}
}
}
Cypress.Commands.add('mount', (node: React.ReactNode) => {
mount(node)
return cy.get('body');
})
@NicholasBoll thank you for your suggestion, and I did just try it out, but unfortunately just adding the import statement into the support file breaks the tests:
import {mount} from '@cypress/react';
results in
err, disregard that, i'm trying this out in a different setup than is normal and just realized the root-most node_modules did not have react as a dep. my apologies.
@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.
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 a cy.mount
command and instead require you to import mount
and use it.
cypress-testing-library
version: 7.0.6node
version: 12.13.0npm
(oryarn
) version: 6.12.0Relevant code or config
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: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:
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.