M
M
Maxim Korolsky2017-02-27 13:26:21
Unit testing
Maxim Korolsky, 2017-02-27 13:26:21

Shared library for React Redux GQL unit testing?

I have never been involved in testing, let alone unit testing (I don’t even know what it is)
We set the task of writing tests for components and a reducer, googled on this topic, each needs its own libraries
The application itself is based on React / Redux / GQL many forms (Redux -Form)
Recommend something or a bunch for testing

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-02-27
@maxfarseer

Reducers (from the redux world, and in general) are tested very conveniently. Your test in general looks like this:
1) there is an initial state
2) there is an action with such and such data (or without it)
3) there is a final state (manually set by you, the expected state)
4) I call the reducer (with the action specified in paragraph 2) and compare the result with point 3
Banal test. Check that isFetching is set to true at the time of the request.

// кусочек из reducer'a
  case GET_DETAILED_FILES_REQUEST:
      return {
        ...state,
        isFetching: true,
      }
...

  // код из теста
  it('GET_DETAILED_FILES_REQUEST', () => {

      const action = {
        type: GET_DETAILED_FILES_REQUEST,
      }

      const nextState = reducer(initialState, action) // где reducer = ваш настоящий редьюсер, например " import reducer from '../../src/reducers/detailedFiles' "

      expect(nextState).to.deep.equal({
        ...initialState,
        isFetching: true,
      })
    })

For testing reducers, the documentation has everything you need to get started.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question