From e790062751f6abed9aae94c7978da052f1083b06 Mon Sep 17 00:00:00 2001 From: Matthieu Foucault Date: Fri, 23 Sep 2016 14:03:09 -0700 Subject: [PATCH 1/3] Add test showing bug: middleware throws if there is a NaN in the state --- test/index.spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/index.spec.js b/test/index.spec.js index dbe46ca..ddae1ed 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -84,4 +84,15 @@ describe('immutableStateInvariantMiddleware', () => { dispatch({type: 'SOME_ACTION', x}); }).toNotThrow(); }); + + it('works correctly with NaN', () => { + const next = action => action; + + const dispatch = middleware(next); + + state = {foo: NaN}; + expect(() => { + dispatch({type: 'SOME_ACTION'}); + }).toNotThrow(); + }) }); From b21595635a88d3c4e8223f2bb7203c140415fb72 Mon Sep 17 00:00:00 2001 From: Matthieu Foucault Date: Fri, 23 Sep 2016 14:14:08 -0700 Subject: [PATCH 2/3] Ensure the middleware doesn't throw if obj is a NaN --- src/trackForMutations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trackForMutations.js b/src/trackForMutations.js index 9357af1..751d460 100644 --- a/src/trackForMutations.js +++ b/src/trackForMutations.js @@ -25,7 +25,7 @@ function detectMutations(isImmutable, trackedProperty, obj, sameParentRef = fals const sameRef = prevObj === obj; - if (sameParentRef && !sameRef) { + if (sameParentRef && !sameRef && !Number.isNaN(obj)) { return { wasMutated: true, path }; } From dd32c346f3fcfbbed31918da2c0359afb2451358 Mon Sep 17 00:00:00 2001 From: Matthieu Foucault Date: Fri, 30 Sep 2016 10:29:07 -0700 Subject: [PATCH 3/3] Move the test into the proper file --- test/index.spec.js | 11 ----------- test/trackForMutations.spec.js | 4 ++++ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index ddae1ed..dbe46ca 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -84,15 +84,4 @@ describe('immutableStateInvariantMiddleware', () => { dispatch({type: 'SOME_ACTION', x}); }).toNotThrow(); }); - - it('works correctly with NaN', () => { - const next = action => action; - - const dispatch = middleware(next); - - state = {foo: NaN}; - expect(() => { - dispatch({type: 'SOME_ACTION'}); - }).toNotThrow(); - }) }); diff --git a/test/trackForMutations.spec.js b/test/trackForMutations.spec.js index 311d0b9..30c78da 100644 --- a/test/trackForMutations.spec.js +++ b/test/trackForMutations.spec.js @@ -226,6 +226,10 @@ describe('trackForMutations', () => { fn: (s) => { return {...s, foo: {}}; } + }, + 'having a NaN in the state': { + getState: () => ({ a:NaN, b: Number.NaN }), + fn: (s) => s } };