-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
ReactTestUtils.mockComponent does not pass props #2660
Labels
Comments
I agree with awei01 - it would be nice to be able to easily assert the props that are being passed to a sub component. |
Any word/news/comment on this? |
|
This was referenced Apr 12, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In using mocked components in test, all props don't get passed to the
ConvenienceConstructor
mocked component. Only thethis.props.children
get passed. Is there a particular reason thatthis.props
don't get passed as well? I think it would make asserting that certain props get passed down to the sub-module easier.Looking at
ReactTestUtils.js
(https://github.com/facebook/react/blob/master/src/test/ReactTestUtils.js#L254):After doing a little more digging, I found some more info. Given the module:
The props do get passed properly and can be asserted when accessing the mocked component using a named ref. Thus, you can assert that
component.refs.props.someProp = "foo"
. However, unless I'm missing something, you cannot access all of the props of a sub-module that is iterated over:var children = TestUtils.scryRenderedDOMComponentsWithTag(component, 'CHILD'); children[0].props.somePassedProp
will always be undefined.The text was updated successfully, but these errors were encountered: