diff --git a/src/utils/__tests__/shallowEqual-test.js b/src/utils/__tests__/shallowEqual-test.js index 522c62cda8..5b6a9304d3 100644 --- a/src/utils/__tests__/shallowEqual-test.js +++ b/src/utils/__tests__/shallowEqual-test.js @@ -41,6 +41,24 @@ describe('shallowEqual', function() { ).toBe(true); }); + it('returns false if arguments are not objects and not equal', function() { + expect( + shallowEqual( + 1, + 2 + ) + ).toBe(false); + }); + + it('returns false if only one argument is not an object', function() { + expect( + shallowEqual( + 1, + {} + ) + ).toBe(false); + }) + it('returns false if first argument has too many keys', function() { expect( shallowEqual( diff --git a/src/utils/shallowEqual.js b/src/utils/shallowEqual.js index 8b35d0d4dc..8339d2dd5f 100644 --- a/src/utils/shallowEqual.js +++ b/src/utils/shallowEqual.js @@ -27,6 +27,10 @@ function shallowEqual(objA, objB) { return false; } + if (typeof objA !== 'object' || typeof objB !== 'object') { + return false; + } + var key; // Test for A's keys different from B. for (key in objA) {