Description
Problem
When using React 17 or React 18, findInstance
returns false
. The current algorithm seems to only support React 16.
Reproduction
I've created a minimal reproduction environment on CodeSandbox here.
This uses React 17 and returns false
. Upgrading to React 18 will have the same issue of returning false
.
Downgrading to React 16, however, will make findInstance
work.
I tried using this with React Testing Library as mentioned in the docs, but was unfortunately unable to do so.
I was able to get something working with React refs
instead though, but thought I'd file an issue anyway.
Small backstory
I was trying to get this working for testing one of my libraries, react-signature-canvas
, which needs to use instance methods as the Canvas API is an imperative API.
Per agilgur5/react-signature-canvas#64 (review), Enzyme has no official support for React 17 (enzymejs/enzyme#2429) or React 18 (enzymejs/enzyme#2524) yet, which has created a big blocker in the community and a shift to using React Testing Library (RTL).
RTL, however, is a pretty different library (more an integration testing library than a unit testing one like Enzyme, plus many other differences), and doesn't even support using instance methods, so this has been a pretty difficult shift in the community.
In agilgur5/react-signature-canvas#64 (comment), I found your blog post and so thought to use this library to bridge the gap therein.
I was able to use the unofficial, partial adapter for React 17 to stick with Enzyme for a bit, but there's no such workaround for React 18.
So I decided to try to get RTL with this library working in agilgur5/react-signature-canvas#76 (comment), and unfortunately hit upon this issue.
Fortunately, I was able to workaround this by using refs
(see agilgur5/react-signature-canvas#88), but thought I should file this issue nonetheless for community awareness or possible future support.