Re:React: Mixins Considered Harmful
by thatswrong0 on Wednesday July 13, 2016 @02:59PM
(#12088720)
I'm a fan of HOCs as well. My only problem with them is that I'm also a fan of shallow testing, and HOCs don't play nicely with shallow testing. I'm waiting on something like this (https://github.com/airbnb/enzyme/issues/250) to get implemented
[ Parent
| on HN ]
Export every component like this:
export class MyComponent extends React.Component { ... }
export default SomeHOC(MyComponent)
And in your test simply import the non-hoc version:
import { MyComponent } from './mycomponent'
Now the HOC won't get in the way of your testing.
Why not just mock the HOC to be the identity fn? `(Component) => Component`
This is my preferred approach as well - and it (anecdotally) works great, since you can then just manually inject any props/spies as needed like any other "dumb" component.
Edit: But he might be pointing to the testing of the actual HOCs/component decorating functions.