-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
useImperativeHandle callback never called (when rendering w/ enzyme) #2039
Comments
Hi @rally25rs have you tried to wrap the code with act() ? act(function() {
mount(<Form ref={ref => (formRef = ref)}>{() => <span>test</span>}</Form>);
expect(formRef.setErrors).toBeDefined();
}) |
I just get |
@rally25rs enzyme doesn't support react alphas, so either way you'll have to upgrade to the actual 16.8 release. Separately, enzyme doesn't have explicit/official support for hooks at all yet, although that's in progress (see #2011 and related issues). |
This isn't really an issue with hook support directly anyway. workaround: const mountWithRef = (elWithRef, options) => {
const WithRef = () => el;
return mount(<WithRef />, options);
};
mountWithRef(<Foo ref={ref} />) |
Closing as a duplicate of #1852 |
( Cross posting this from facebook/react#15054 )
What is the current behavior?
I have the code:
When I use the component, the callback passed to
useImperativeHandle
is never called. (The debugger statement is never hit).The code that I have using the component is:
Repro Example:
https://codesandbox.io/s/v8rqy75mn5
If you check the console tab, it only logs the message form the callabck once, but the component is rendered twice (or if you comment out the normal react
render
then it is no longer console.logged)Environment
API
Version
Adapter
I noticed that when executed through
enzyme.mount
my component's functionForm(props, ref)
is called withnull
as theref
parameterIt looks like this comes from react's
workInProgress
is aFiberNode
andworkInProgress.ref
isnull
The initial
react-dom.render
is called with aWrapperComponent
that has aref
set to my inline function in the code, but it seems to get dropped somewhere between there and the actual call to my component.I suspect this may have something to do with how enzyme is wrapping components, but debugging
react-dom
isn't real fun 😄useImperativeHandle
is also listed in enzyme's hooks support checklist #2011 so linking that here. I guess support just isn't there yet? 🤷♂️The text was updated successfully, but these errors were encountered: