mercredi 3 août 2016

Creating fake components when testing subcomponents via __Rewire__

I've just started using React at our company, all great so far but I found myself writing quit a bit of a boilerplate(especially in specs).

Particularly when testing Parent => Child component interactions:

class ChildComponent extends React.Component {
  render = () => null
}

ParentComponent.__Rewire__('ChildComponent', ChildComponent)

Any suggestions how to extract this to a helper?

The API I imagined:

  • rewire(ParentComponent, 'ChildComponent')
  • ParentComponent.__RewireWithMock__('ChildComponent')

Aucun commentaire:

Enregistrer un commentaire