Skip to content

Commit ca18dd6

Browse files
committed
chore(test): fix unit test for 0 vs -0 and clarify
1 parent 6ec0106 commit ca18dd6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

__tests__/base.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,20 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
12781278
const nextState = produce(baseState, draft => {
12791279
draft.x = +0
12801280
})
1281+
// 0 === -0 // true
1282+
// Object.is(0, -0) // false
1283+
//
1284+
// MWE:
1285+
// Immer preserves the difference between -0 and +0,
1286+
// so a new state is created.
1287+
// This isn't defined anywhere explicitly, so could be changed
1288+
// in the future to follow === behavior, rather than Object.is.
1289+
// But I think this is fine as is.
12811290
expect(nextState).not.toBe(baseState)
1282-
expect(nextState).not.toEqual(baseState)
1291+
expect(nextState.x).toBe(-0)
1292+
expect(nextState.x).not.toBe(+0)
1293+
// however, toEqual treats -0 === +0 (which is true!)
1294+
expect(nextState).toEqual(baseState)
12831295
})
12841296

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

0 commit comments

Comments
 (0)