-
Notifications
You must be signed in to change notification settings - Fork 47k
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
react-test-renderer.create does not work properly with forwardRef components #12693
Comments
I am running into a similar problem with testing components that render In my use-case, I am working in a library that exports components returned by a HOC using library/theme const withTheme = WrappedComponent =>
React.forwardRef((props, ref) => <WrappedComponent ref={ref} theme="light" {...props} />); library/button const InternalButton = props => <button {...props} />
const ButtonWithTheme = withTheme(InternalButton);
export default ButtonWithTheme; consumer.js import Button from 'library/button';
const App = () => <Button>Click me</Button>; consumer.test.js import Button from 'library/button';
import App from './consumer';
it('should render button that says Click me', () => {
const { root } = TestRenderer.create(<App />);
// this will not find anything
const button = root.findByType(Button);
expect(button.props.children).toEqual('Click me');
}); I had a look at what is returned by I am not very familiar with the |
Thanks, the use case for this is clear. It's not that we don't want it—it was just an omission. |
@petegleeson up for it? it should be essentially a tweak of your PR to my enzyme PR (lol) |
Fixed by #12725 |
I agree! Tho that's more of conversation to be had with an enzyme maintainer, I'm just a guy who sends PRs some times. Practically at the moment it's not feasible as the toTree behavior is different from enzes format |
Thanks everyone. I would have been happy to create a PR for this but it got done so quickly! |
any updates ? |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If you try to access the
.root
of a component tree of a component created withforwardRef
, you will get an errorIf the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
A minimal example is simply a component created with
forwardRef
:Now if you try to use
create
fromreact-test-renderer
and access.root
, you will gethttps://codesandbox.io/s/vm98x95wx5
What is the expected behavior?
You should be able to create components created with forwardRef with the test renderer.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
16.3 using jest (forwardRef did not exist previously).
The text was updated successfully, but these errors were encountered: