From ca18dd63c86fd3895e47447ce39c93d5d718c31c Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 2 Jan 2023 12:30:44 +0100 Subject: [PATCH] chore(test): fix unit test for 0 vs -0 and clarify --- __tests__/base.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/__tests__/base.js b/__tests__/base.js index e37dba2a..654ebe4f 100644 --- a/__tests__/base.js +++ b/__tests__/base.js @@ -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", () => {