Add option to mountHook to use custom mount method
See original GitHub issueWhat would you like?
It would be great to have the option to use a custom mount
method when using mountHook
.
Why is this needed?
Currently I have to mount
a component to test hooks that depend on a React.Context
or a Provider. With a custom version of mount
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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Building Your Own Hooks - React
Custom Hooks are a mechanism to reuse stateful logic (such as setting up a subscription and remembering the current value), but every time...
Read more >Effective React Tests - Gleb Bahmutov
Let's create a few React components, and I will use react-scripts to bundle them ... import { mount } from 'cypress-react-unit-test'
Read more >React Examples | Cypress Documentation
Mounting Components Mounting a Component The first step in testing a component ... Below are a few examples that demonstrate using a custom...
Read more >How to use componentWillMount() in React Hooks?
You cannot use any of the existing lifecycle methods ( componentDidMount , componentDidUpdate , componentWillUnmount etc.) in a hook.
Read more >12 Recipes for testing React applications using cypress-react ...
We first create a routing environment similar to that in which we'll use the component. We set up that environment so we can...
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
bump, also here for same thing.
I have context, that needs a provider.
Sure I could just use
mount
and add the provider there, and the hook, but then I need to render items from the hook and check the rendered items. I’d rather just test the return of the hook directly and the above example with@testing-library/react-hooks
is exactly what I want with thatwrapper
option.EDIT: I am actually using
import {renderHook} from '@testing-library/react-hooks/dom';
in my cypress component testing setup, I can userenderHook
with thewrapper
option, get the return values, then set my assertions.We removed
mountHook
in v11. We recommend mounting your hook in a test component instead. Here are docs describing the way forward withoutmountHook