Title: TypeError: state.userInfo is not iterable in Jest Testing
Tags: javascript;reactjs;redux;react-redux;jestjs
Question: I keep getting this TypeError when I run my jest tests on one of my reducers. It seems like it has to do with the fact that it can't find the state of the store? 

This is the exact error I get in the console when i run yarn test --coverage on the reducer test file:

Console Error:

```  TypeError: state.userInfo is not iterable

  63 |         allDocumentComments: action.payload.allDocumentComments ? _.cloneDeep(action.payload.allDocumentComments) : null,
  64 |         userInfo: [
&gt; 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)
```

Here is the reducer test file with the test I'm trying to pass:

Reducer Test File:

```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', () =&gt; {

    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: "brian77@example.net",
        family_name: "Pelo",
        given_name: "Alex",
    }];

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

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

And here is the reducer file where the test case is failing

Reduce file:

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

import _ from 'lodash';

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

export default (state = INITIAL_STATE, action) =&gt; {
  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;
  }
};
```

Comment: Try printing your `state`, to make sure what it contains

Comment: Could you provide a codesandbox link?


Here is another answer: I was also facing the same issue. I can share what mistake I was making and how I resolved it.
I was making a mistake while mocking ```axios``` request during writing integration tests.
For example:
Let's say once a user logs in successfully, we're making network calls to fetch wishlist, cart details and initializing the state for both. But, while writing test cases, we forgot to mock the response part for wishlist/cart, in that case, it might initialize the state as ```null``` if it's not handled correctly.
So, this was the mistake, I fixed this by correcting the mockup. Please check your mockups properly, maybe the same kind of mistake you're making.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:04/16/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><reactjs><redux><react-redux><jestjs>', 'Title': 'TypeError: state.userInfo is not iterable in Jest Testing', 'ViewCount': 691, 'id': 61252549, 'user_AboutMe': None, 'user_AccountId': 16438281.0, 'user_DisplayName': 'codemonkey', 'user_Reputation': 385.0, 'user_Views': 51.0, 'user_id': 11875319.0}}