TypeError: state.userInfo не повторяется в Jest-тестировании - PullRequest
0 голосов
/ 16 апреля 2020

Я получаю эту ошибку TypeError, когда запускаю шутливые тесты на одном из моих редукторов. Кажется, это связано с тем, что он не может найти состояние магазина?

Это именно та ошибка, которую я получаю в консоли при запуске теста пряжи --coverage в файле теста редуктора:

Ошибка консоли:

  TypeError: state.userInfo is not iterable

  63 |         allDocumentComments: action.payload.allDocumentComments ? _.cloneDeep(action.payload.allDocumentComments) : null,
  64 |         userInfo: [
> 65 |           ...state.userInfo,
     |                    ^
  66 |           ...action.payload.userInfo
  67 |         ]
  68 |       };

  at _default (src/reducers/sopCommentsReducer.js:65:20)
  at Object.test (src/tests/reducers/sopCommentsReducer.test.js:130:40)

Вот файл теста редуктора с тестом, который я пытаюсь пройти:

Файл теста редуктора:

import sopCommentsReducer from '../../reducers/sopCommentsReducer';
import * as mocks from '../../setupTests';
import _ from 'lodash';

// Testing tableActions.js reducer equivalents
describe('testing reducers to tableActions.js actions', () => {

    const allDocumentComments = {
        'comement-string' :{
            _id: "5e792",
            document_id: "1",
            commenter_id: "2",
            comment: "this is a comment",
            resolved: false,
            timestamp: "2020-03-23 21:31:36+00:00",
            resolved_timestamp: "2020-03-24 17:36:15+00:00",
            total_comments: 1,
            replies: [
                {
                    commenter_id: "3",
                    comment: "Reply",
                    timestamp: "2020-03-23 21",
                }
            ],
        }
    };

    const userAccountData = [{
        _id: "5e792",
        msid: "alex",
        roles: ["admin"],
        email_address: "alex@yahoo.com",
        family_name: "Pelo",
        given_name: "Alex",
    }];

    describe('testing addSOPComment action reducer', () => {
        test('Returns the correct reducer result given the action', () => {
            let expectedAction = {
                'payload': {
                    'allDocumentComments': allDocumentComments,
                    'userInfo': userAccountData
                },
                'type': 'ADD_SOP_COMMENT'
            };

            let addSOPCommentReducerResult = sopCommentsReducer(mocks.mockFullStore, expectedAction);
            expect(addSOPCommentReducerResult).toMatchSnapshot();
        });
    });

А вот редуктор файл, в котором тестовый пример не пройден

Уменьшить файл:

import {
  ADD_SOP_COMMENT,
} from '../actions/types';

import _ from 'lodash';

const INITIAL_STATE = {
  allDocumentComments: {},
  userInfo: [],
};

export default (state = INITIAL_STATE, action) => {
  switch(action.type){
    case ADD_SOP_COMMENT:
      return {
        ...state,
        allDocumentComments: action.payload.allDocumentComments ? _.cloneDeep(action.payload.allDocumentComments) : null,
        userInfo: [
          ...state.userInfo,
          ...action.payload.userInfo
        ]
      };
 default:
      return state;
  }
};
...