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
Add option to mountHook to use custom mount method #14672
Comments
Can you show a code example for the API you'd like to use for |
Hi, const result = mountHook(
() => useApiGet('/some/url/'),
{
wrapper: ({ children }) => (
<Provider store={store}>{children}</Provider>
),
},
); But if you prefer to do something similar to const result = mountHook(() => useApiGet('/some/url/'), {
createMount: (element: React.ReactElement) => {
mount(<Provider store={store}>{element}</Provider>);
},
}); I personally like the first one, as it's so simple. |
Is it possible to have some progress about the |
bump, also here for same thing. I have context, that needs a provider. Sure I could just use EDIT: I am actually using |
We're currently discussing improvements to the Any changes we decide make to the support/commands.jsximport { mount as cypressMount } from '@cypress/react'
const theme = {/* ... */}
const i18n = {/* ... */}
Cypress.Commands.add('mount', (children) => {
return cypressMount(<ThemeProvider theme={theme}>
<I18nProvider i18n={i18n}>
{ children }
</I18nProvider>
</ThemeProvider>)
}) component.spec.jsxit('renders', () => {
cy.mount(<YourComponent/>) // Will get wrapped in the proper providers
}) I'll keep this issue open and we'll close it when we make a decision on the final API, but that won't be for a while. |
What would the equivalent of this be for Vue? Trying to wrap components for testing in a from Vuetify. If I try and use the above Webpack complains that it doesn't know the required loader (Vue Loader already included as per the docs) |
The current documented method of using a custom mount also breaks
In a test:
I believe RTL had the same problem as this, and that's where the |
I like this solution, and it works great for Cypress Component testing, but I'm having issues as it relates to using ES modules. When I regular Cypress E2E testing, I'll get a SyntaxError related to the |
This has been resolved with #19633 in Cypress v10.0.0 |
I'm trying to do something similar where I am trying to fake a hook response from a 3rd party library ( |
From what I can tell #19633 does not appear to resolve this. This issue is about adding functionality to cy.mountHook (from cypress/react) to allow for easily wrapping the mounted hook with providers and such. #19633 appears to merely allow one to override cy.mount or cy.hover no? |
I'm glad it's not just me! I was beginning to think I totally missed the point :) |
We removed |
The correct link for the relevant docs is now - https://docs.cypress.io/guides/references/migration-guide#React---mountHook-Removed. There are additional hyphens in the fragment at the end of the URL. |
What would you like?
It would be great to have the option to use a custom
mount
method when usingmountHook
.Why is this needed?
Currently I have to
mount
a component to test hooks that depend on aReact.Context
or a Provider. With a custom version ofmount
as described in https://github.com/cypress-io/cypress/blob/develop/npm/react/docs/providers-and-composition.md, this would be possible without creating components.The text was updated successfully, but these errors were encountered: