PracticaDS / pdes-tp-team_prog

Pdes-tp-team_prog
0 stars 0 forks source link

Useless boilerplate in storybooks and tests #74

Closed LaimeJesus closed 5 years ago

LaimeJesus commented 5 years ago

We are repeating the following code in every story that uses a connected component:

const state = {
 some: state
}
const mockStore = configureStore()
const store = mockStore(state)

storiesOf('story', module).add('some case', () => (
  <Provider store={store}>
    <MyConnectedComponent />
  </Provider>
))

but we are not "dispatching" any action or requiring any prop from the store, I think it just add a lot of 'bad' boilerplate for using storybooks. A cleaner way should be using only Functional(auto contained) Components in storybooks so we don't need to add that boilerplate, in resume not connecting every Component.

This is the same for testing:

const state = {
 some: state
}
const mockStore = configureStore()
const store = mockStore(state)

it('render something', () => {
  const tree = renderer.create(
    <Provider store={store}>
      <MyConnectedComponent />
    </Provider>,
  )
  expect(tree).toMatchSnapshot()
})

The problem is not that we are testing nothing at all but we have to add extra code just for nothing, it would be simpler if we only test components matching snapshots using jest or 'props' using enzyme for non connected components so we only test the single component(unit test i think). Although we should add some integration test of components connected to the store in that case we should mock the store of the application.

What do you think?

LaimeJesus commented 5 years ago

We have separated every component in functional and connected, so we are able to create storybooks and tests which uses a specific store data(behaviour) if we want to. So, it's already fixed on #107 .