From 8be738bf2ee0383e6ad1dab59e9c52acb35199bc Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 3 Oct 2018 12:02:08 +0200 Subject: [PATCH] Removed unnecesary case, add more tests --- .../utils/__tests__/__snapshots__/index.test.js.snap | 4 ++-- src/reducers/utils/__tests__/index.test.js | 10 +++++++--- src/reducers/utils/index.js | 4 ---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap b/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap index 8414ce19..5efb9857 100644 --- a/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap +++ b/src/reducers/utils/__tests__/__snapshots__/index.test.js.snap @@ -50,6 +50,6 @@ exports[`reducers utils observeChanges shoul NOT be the same - returns true 14`] exports[`reducers utils observeChanges shoul NOT be the same - returns true 15`] = `true`; -exports[`reducers utils observeChanges test filter 1`] = `true`; +exports[`reducers utils observeChanges test filter 1`] = `false`; -exports[`reducers utils observeChanges test filter 2`] = `false`; +exports[`reducers utils observeChanges test filter 2`] = `true`; diff --git a/src/reducers/utils/__tests__/index.test.js b/src/reducers/utils/__tests__/index.test.js index e7b57b7c..48c5d93b 100644 --- a/src/reducers/utils/__tests__/index.test.js +++ b/src/reducers/utils/__tests__/index.test.js @@ -65,7 +65,7 @@ describe('reducers utils', () => { current: {}, }, { - previous: { one: 1 }, + previous: { one: 1, three: 3 }, current: { one: 1, two: 2 }, }, { @@ -80,6 +80,10 @@ describe('reducers utils', () => { previous: 'a', current: 'b', }, + { + previous: ['a'], + current: ['b'], + }, { previous: 1, current: '1', @@ -125,12 +129,12 @@ describe('reducers utils', () => { const data = [ { previous: { one: { two: 2, three: 3 } }, - current: { one: { two: 2 } }, + current: { one: { two: 2, three: 4 } }, filter: { one: ['two'] }, }, { previous: { one: { two: 2, three: 3 } }, - current: { one: { two: 1 } }, + current: { one: { two: 1, three: 3 } }, filter: { one: ['two'] }, }, ]; diff --git a/src/reducers/utils/index.js b/src/reducers/utils/index.js index 98b89ea3..3d6a8de4 100644 --- a/src/reducers/utils/index.js +++ b/src/reducers/utils/index.js @@ -144,10 +144,6 @@ export const observeChanges = (prev: ?Object, current: ?Object, filter?: {[k: st const prevDifference = prevKeys.find(k => currentKeys.indexOf(k) < 0); if (prevDifference) return true; - // 7. "current" has keys which "prev" doesn't have - const currentDifference = currentKeys.find(k => prevKeys.indexOf(k) < 0); - if (currentDifference) return true; - // 8. observe every key recursive for (let i = 0; i < currentKeys.length; i++) { const key = currentKeys[i];