@samitouri / QOS-React-2 / commits / 6cd004f20a

Fixed shallowEqual implementation to handle the case when inputs are not objects.

If either argument is not an object and unequal, then shallowEqual should return false. If only one argument is an object, then shallowEqual should return false. Fixes #3369

Varun Rau committed Mar 10, 2015 at 18:03 UTC 6cd004f20ae6e2eb6168f853214c6880934ae4c9
2 files changed +22
src/utils/__tests__/shallowEqual-test.js
+18
@@ -41,6 +41,24 @@ describe('shallowEqual', function() {
41 ).toBe(true);
42 });
43
44 + it('returns false if arguments are not objects and not equal', function() {
45 + expect(
46 + shallowEqual(
47 + 1,
48 + 2
49 + )
50 + ).toBe(false);
51 + });
52 +
53 + it('returns false if only one argument is not an object', function() {
54 + expect(
55 + shallowEqual(
56 + 1,
57 + {}
58 + )
59 + ).toBe(false);
60 + })
61 +
62 it('returns false if first argument has too many keys', function() {
63 expect(
64 shallowEqual(
src/utils/shallowEqual.js
+4
@@ -27,6 +27,10 @@ function shallowEqual(objA, objB) {
27 return false;
28 }
29
30 + if (typeof objA !== 'object' || typeof objB !== 'object') {
31 + return false;
32 + }
33 +
34 var key;
35 // Test for A's keys different from B.
36 for (key in objA) {