arunoda / react-komposer

Feed data into React components by composing containers.
MIT License
732 stars 70 forks source link

Testing: When a component contains a container as child, enzyme will call the depsMapper function. #106

Closed macrozone closed 7 years ago

macrozone commented 7 years ago

I have a component that contains a komposed container

<MainLayout>
  <MyContainer />
</MainLayout>

If I test this with enzyme, it will crash, because it runs MyContainer's compose function that uses actions or other things from the context which isn't available on test.

Any idea?

clayne11 commented 7 years ago

You can stub the container or you can create a separate container component and test the inside component with props that don't depend on the container.

The whole point of the container concept is to separate the data-fetching concerns from the rendering concerns.

You should be testing the component with plain data, not with whatever data is being fetched and passed in from the container.

macrozone commented 7 years ago

I am aware of this. The problem is, that i am testing a component that contains a container-component as child. The component under test itself is just a component, not a container.

E.g. the component under test is MainLayout:

<MainLayout>
  <MyContainer />
  (...)
</MainLayout>

MyContainer in this sample just happens to be a container. It should not matter if it is a component or a container. When I test MainLayout i just want to make sure that MyContainer is there (or other aspects of MainLayout).

As far as i know, enzyme's shallow should not render child-components, but it does in this case.

clayne11 commented 7 years ago

And you tried using the stubbing flag as well and it's still not working?

arunoda commented 7 years ago

I think now we've better support for stubbing.

arunoda commented 7 years ago

I am open to suggestion with the 2.x - https://github.com/kadirahq/react-komposer/issues/123