-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Beef up tests for Stateless Functional Components #261
Comments
Recently started using enzyme for my first react native app. Looking forward to taking a look at this issue. |
I think I could help a little bit, especially that I am using SFC all over the place and it would be nice to have a possibility to test them correctly ;) Although I would need some guidance on what I can work on and maybe what would be the best approach to solving particular task. |
Related #262 |
One approach that I've considered, though it isn't very DRY, is to literally just go through each test for mount/shallow and duplicate it if it's using a component and use an SFC instead. Might be a better approach than that though... |
I find that sometimes it's nicer when tests do repeat themselves - that's probably the simplest approach here. |
+1 to this. Tests should prioritize ease of understanding any given example to make it easier on folks who run into failing specs and need to understand what is going on. |
I have finished adding tests for shallow, but have encountered issues writing tests for 'mount' (one of these issues is mentioned in #45). From what I can tell, stateless function components do not play well with findDOMNode. This means that calling .text() on the wrapper of an SFC will not work. Additionally, trying to get an SFC with .find() does not work either. I would appreciate some guidance on how to proceed. Should I write failing tests that attempt to use these functionalities (so that they can be fleshed out in future releases with fixes/enzyme-specific errors), or should I use work arounds like in the example below?
Will not work:
Will work:
A good example of a test that can't be directly translated into an SFC (but can be made to work) would be this one:
|
@gm758 are you still working on this? We recently fixed the incompatibility issue with SFCs and |
@aweary Haven't checked back in a while. Glad to see this compatibility issue fixed. Happy to get back to work on this now that this fix has been implemented. I'll start at it later today. |
#394 should allow this issue to be closed |
Enzyme was originally written to be compatible with React 0.13, before Stateless Functional components were a thing. It really seems like we've been getting a lot of PRs and Issues highlighting the incompatibility of SFCs with enzyme.
I love SFCs - so i'm hoping we can change this. i think the first step might be to increase the number of tests we have that use SFCs.
If anyone is interested in collaborating on enzyme, this is some relatively straight-forward work that I'd be hugely grateful for!
Help us make enzyme more stable!
The text was updated successfully, but these errors were encountered: