Created
December 21, 2016 17:47
-
-
Save ksummerlin/ab35ffed4907f94f65ba55c62ac7cd89 to your computer and use it in GitHub Desktop.
Unit test ImmutableJs collections using newState.equals(expectState) not expect(newState).toEqual(expectState)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import expect from 'expect'; | |
import whynotEqual from 'is-equal/why'; | |
import appLayoutReducer from '../reducer'; | |
import { | |
hideLeftMenuIcon, | |
showLeftMenuIcon, | |
} from '../actions'; | |
import { fromJS } from 'immutable'; | |
describe('appLayoutReducer', () => { | |
let state; | |
beforeEach(() => { | |
state = fromJS({ | |
showLeftMenuIcon: false, | |
}); | |
}); | |
it('should return the initial state', () => { | |
const expectedResult = state; | |
expect(appLayoutReducer(undefined, {})).toEqual(expectedResult); | |
}); | |
it('should handle the showLeftMenuIcon action correctly', () => { | |
const expectedResult = state | |
.set('showLeftMenuIcon', true); | |
expect(appLayoutReducer(state, showLeftMenuIcon())).toEqual(expectedResult); | |
}); | |
it('should handle the hideLeftMenuIcon action correctly', () => { | |
const initState = state | |
.set('showLeftMenuIcon', true); | |
const expectedResult = state | |
.set('showLeftMenuIcon', false); | |
const newState = appLayoutReducer(initState, hideLeftMenuIcon()); | |
expect(newState).toEqual(expectedResult, whynotEqual(newState, expectedResult)); | |
expect(newState.equals(expectedResult)).toEqual(true); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notice in the last test, that the test in line 40 fails, but line 41 works. The failure from line 40 is described by whyNotEqual() as: