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
Testing HOC returns null in wrapper.instance() #711
Comments
|
@laumair Thanks for your reply! This is what i though at first, but the function returns a component that renders another component. So when doing what you suggested, i still get null on instance(). Doing mount instead of shallow returns this instance
Updated test code
|
If you want to dive through an HOC, try |
@ljharb Thanks. Didn't know about |
@ljharb thanks, i will give it a go. UPD: Went through dive and found out that its there to give you chance to access inner component instance, i.e. not HOC itself. My issue here is that i am not able to access the instance of the HOC to test its methods. |
My hunch is that it's related to your jest mocking (i see the unmock call for that component). |
I want to test internal methods of my HOC, i cannot do that if its mocked, so i am unmocking it. ie
|
In that case no, it wouldn't work because the pure component is recreated every time you call I do note that you're doing |
The expect() assertion is not finalized, the main case here is that instance() is null. I think i should try separate class from function and import it as pure to test, maybe that would help. |
Also, in jsx, non-html element component names need to start with a capital letter - try |
I finally found a very good solution to get a wrapper from a decorated component. For shallowed components you can use const wrapper = mount(shallow(<MyComponent />).get(0)) Works like a charm :) |
Hi. I need some help here as i am quite stuck here.
I have a HOC
And i want to test its internal methods with instance() of shallow.
Here is my test.
When i am loggin wrapper.instance() in the fist suit i get null.
Am i missing something? I have other tests doing same for classes with no problems.
The text was updated successfully, but these errors were encountered: