-
Notifications
You must be signed in to change notification settings - Fork 308
Testing with Jest & Enzyme: Class constructors cannot be invoked without 'new' #869
Comments
I got this issue recently the solution our Senior developer came up with is really nice: Which is you need to test your raw component without the Radium decorator, to do so you have to export two things out of the component:
ie: test file: import raw component |
Thanks @mhd999, very helpful 👍 |
Much appreciated @mhd999. We can make a lot of progress with that workaround. |
Hi guys. I tried exporting the non-Radium-wrapped component and testing that but I'm getting an error related to the media query:
The media query is why I'm using Radium in the first place, so if I'm not missing something then this doesn't seem ideal. Thanks in advance for any help! -d |
@mhd999's suggestion is a workaround, not a fix! |
@jariz fair enough. I suppose it's worth continuing to pursue it. Because of the way Radium is built I think it'd take quite an overhaul to make it compatible with the newer |
Fair enough, but yes, the class syntax is basically default now in most react setups I've worked with, so this is something that's really desperately needed. |
Hey, guys. We're using Radium and running into a hang up during testing. We started a project using create-react-app so our config boilerplate is pretty minimal.
When I make a simple component:
And try to test it by mounting it:
It's throwing the exception
TypeError: Class constructors cannot be invoked without 'new'
. I read through issue #443 and understand that we could switch over to declaring the components like this:const DumbComponent = React.createClass ({ ... })
which does in fact work and pass the test.Are there any other workarounds for this issue? Because we have the babel config bottled up in the npm module it's difficult to add the plugin suggested.
Thanks for your help!
The text was updated successfully, but these errors were encountered: