-
Notifications
You must be signed in to change notification settings - Fork 114
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
How to access base component instance from higher-order component instance #225
Comments
@christophercliff Not sure what you are asking here, can you elaborate a bit? |
var MyComponent = React.createClass()
var MyConnectedComponent = connectoToStores(MyComponent)
var myConnectedComponent = TestUtils.renderIntoDocument(React.createElement(MyConnectedComponent)) Given the above, is it possible to access, for example, |
The HoC does not keep a |
I'm re-opening this because I think we should expose the wrapped component e.g. for testing purposes. I looked around a bit and I don't think there's an existing convention in the React community, but perhaps something as simple as |
I might have been a bit overzealous here. For testing purposes exposing the wrapped component might be a good idea. But that means that you will have to test your component without being wrapped. If I understand the question correctly the idea is to get a reference to the rendered component instance, in order to check stuff there or to call methods on it. Then we'd need to attach a @christophercliff Did I understand you correctly? |
Just exposing the wrapped class is sufficient. Then as @christophercliff noted above, you can use |
Ok so we're just talking about a shorter way for testing here. |
@johanneslumpe Not just shorter — if you're using decorators, then it's actually necessary, because you don't have any reference to the inner component.
In most cases, that's exactly what you want. The advantage of using higher-order components is that the wrapped component doesn't care about the underlying Flux implementation — it just receives props. So in your tests, rather than creating mock Flux dependencies, you pass some props. |
@acdlite oh yeah, decorators. Ok sure, it's not hard to fix this :) Also: true about not wanting to mock all the stuff - silly me. |
Yeah this will be a one-liner, just need to decide on the right name for the property. |
Actually, if you have multiple HoCs on the same base component, you need to loop through them. I like this approach: |
I think |
I say we go with |
No, not necessary. Linking to the repo is fine. We should just really make sure that stuff like this is made really clear in some kind of FAQ section or a separate testing section :) |
Is this possible?
The text was updated successfully, but these errors were encountered: