Some values not initialized in first test

141 Views Asked by At

I have a number of React/Redux actions & reducers that I want to test. I have successfully written a few tests, but I'm running into a problem on a reducer test where one value is being left as undefined in the first test, but properly initialized in the second test.

filesReducers.test.js

import reducer from './filesReducers';
import { filesActions } from '../actions/actionTypes';
import filesInitialState from '../../components/Files/initialState';

describe('files reducers', () => {
  describe('media library reducers', () => {
    it('should return the initial state', () => {
      const testInitialState = reducer(undefined, {});
      console.log({ testInitialState }); /* eslint-disable-line no-console */
      expect(testInitialState.multiMediaMediaLibraryItems).toEqual([]);
      // expect(testInitialState.logosMediaLibraryItems).toEqual([]); /* value is undefined */
      expect(testInitialState.logosMLibraryItems).toEqual([]);
    });
    it('should update the multiMedia list', () => {
      const updatedState = reducer(filesInitialState, { type : filesActions.STORE_MEDIA_LIBRARY_MULTIMEDIA_ITEMS, payload : ['1000002'] });
      console.log(updatedState); /* eslint-disable-line no-console */
      expect(updatedState.multiMediaMediaLibraryItems).toEqual(['1000002']);
    });
  });
});

initialState.js (roughly 20 variables here)

const filesInitialState = {
...
  logosMediaLibraryItems           : [],
  logosMLibraryItems               : [],
...

First console output snippet

  logosMediaLibraryItems: undefined, <=== one variable only undefined
  logosMLibraryItems: [], <=== this and all other variables OK

Second console output snippet

      logosMediaLibraryItems: [], <=== Now this is defined
      logosMLibraryItems: [],

What the heck is going on here? I saw a while back that reduxForm had a similar problem, but nothing like this.

0

There are 0 best solutions below