From 802e8f8e3259dbfd83d9d101ec297074bb59787e Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Tue, 2 Oct 2018 20:06:59 +0200 Subject: [PATCH] Fixed bug in function, add more tests --- .../utils/__tests__/__snapshots__/index.test.js.snap | 4 ++++ src/reducers/utils/__tests__/index.test.js | 10 +++++++++- src/reducers/utils/index.js | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap b/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap index f1703259..dc206e2a 100644 --- a/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap +++ b/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap @@ -18,6 +18,8 @@ exports[`reducers utils observeChanges shoud be the same - returns false 8`] = ` exports[`reducers utils observeChanges shoud be the same - returns false 9`] = `false`; +exports[`reducers utils observeChanges shoud be the same - returns false 10`] = `false`; + exports[`reducers utils observeChanges shoul NOT be the same - returns true 1`] = `true`; exports[`reducers utils observeChanges shoul NOT be the same - returns true 2`] = `true`; @@ -35,3 +37,5 @@ exports[`reducers utils observeChanges shoul NOT be the same - returns true 7`] exports[`reducers utils observeChanges shoul NOT be the same - returns true 8`] = `true`; exports[`reducers utils observeChanges shoul NOT be the same - returns true 9`] = `true`; + +exports[`reducers utils observeChanges shoul NOT be the same - returns true 10`] = `true`; diff --git a/src/reducers/utils/__tests__/index.test.js b/src/reducers/utils/__tests__/index.test.js index dc937181..d9d2f913 100644 --- a/src/reducers/utils/__tests__/index.test.js +++ b/src/reducers/utils/__tests__/index.test.js @@ -16,6 +16,10 @@ describe('reducers utils', () => { pervious: [], current: [], }, + { + pervious: [1, 1, 1], + current: [1, 1, 1], + }, { pervious: 'a', current: 'a', @@ -57,9 +61,13 @@ describe('reducers utils', () => { current: {}, }, { - pervious: [{}], + pervious: [{}, {}], current: [], }, + { + pervious: [1, 1, 1], + current: [1, 1], + }, { pervious: 'a', current: 'b', diff --git a/src/reducers/utils/index.js b/src/reducers/utils/index.js index d3a8e740..03662042 100644 --- a/src/reducers/utils/index.js +++ b/src/reducers/utils/index.js @@ -122,7 +122,7 @@ export const observeChanges = (prev: ?Object, current: ?Object, filter?: {[k: st // 2. one of the objects is null/undefined if (!prev || !current) return true; - const prevType = Object.prototype.toString.call(current); + const prevType = Object.prototype.toString.call(prev); const currentType = Object.prototype.toString.call(current); // 3. one of the objects has different type then other if (prevType !== currentType) return true;