3 ms·
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
by thatswrong0 10y ago
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 https://github.com/airbnb/enzyme/issues/250) to get implemented
- coderzach 10y agoWhy not just mock the HOC to be the identity fn? `(Component) => Component`
- eiriklv 10y agoThis 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.
- mg74 10y agoExport 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.