Skip to content

Commit

Permalink
chore(test): fix unit test for 0 vs -0 and clarify
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 2, 2023
1 parent 6ec0106 commit ca18dd6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion __tests__/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,20 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
const nextState = produce(baseState, draft => {
draft.x = +0
})
// 0 === -0 // true
// Object.is(0, -0) // false
//
// MWE:
// Immer preserves the difference between -0 and +0,
// so a new state is created.
// This isn't defined anywhere explicitly, so could be changed
// in the future to follow === behavior, rather than Object.is.
// But I think this is fine as is.
expect(nextState).not.toBe(baseState)
expect(nextState).not.toEqual(baseState)
expect(nextState.x).toBe(-0)
expect(nextState.x).not.toBe(+0)
// however, toEqual treats -0 === +0 (which is true!)
expect(nextState).toEqual(baseState)
})

it("should handle equality correctly - 3", () => {
Expand Down

0 comments on commit ca18dd6

Please sign in to comment.