|
| 1 | +import expect from 'expect'; |
| 2 | +import shallowEqualScalar from '../../src/utils/shallowEqualScalar'; |
| 3 | +import shallowEqual from '../../src/utils/shallowEqual'; |
| 4 | + |
| 5 | +describe('Utils', () => { |
| 6 | + // More info: https://github.com/gaearon/redux/pull/75#issuecomment-111635748 |
| 7 | + describe('shallowEqualScalar', () => { |
| 8 | + it('returns true if both arguments are the same object', () => { |
| 9 | + const o = { a: 1, b: 2 }; |
| 10 | + expect(shallowEqualScalar(o, o)).toBe(true); |
| 11 | + }); |
| 12 | + |
| 13 | + it('returns false if either argument is null', () => { |
| 14 | + expect(shallowEqualScalar(null, {})).toBe(false); |
| 15 | + expect(shallowEqualScalar({}, null)).toBe(false); |
| 16 | + }); |
| 17 | + |
| 18 | + it('returns true if arguments fields are equal', () => { |
| 19 | + expect( |
| 20 | + shallowEqualScalar( |
| 21 | + { a: 1, b: 2, c: undefined }, |
| 22 | + { a: 1, b: 2, c: undefined } |
| 23 | + ) |
| 24 | + ).toBe(true); |
| 25 | + |
| 26 | + expect( |
| 27 | + shallowEqualScalar( |
| 28 | + { a: 1, b: 2, c: 3 }, |
| 29 | + { a: 1, b: 2, c: 3 } |
| 30 | + ) |
| 31 | + ).toBe(true); |
| 32 | + }); |
| 33 | + |
| 34 | + it('returns false if first argument has too many keys', () => { |
| 35 | + expect( |
| 36 | + shallowEqualScalar( |
| 37 | + { a: 1, b: 2, c: 3 }, |
| 38 | + { a: 1, b: 2 } |
| 39 | + ) |
| 40 | + ).toBe(false); |
| 41 | + }); |
| 42 | + |
| 43 | + it('returns false if second argument has too many keys', () => { |
| 44 | + expect( |
| 45 | + shallowEqualScalar( |
| 46 | + { a: 1, b: 2 }, |
| 47 | + { a: 1, b: 2, c: 3 } |
| 48 | + ) |
| 49 | + ).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + it('returns false if arguments have keys dont have same value', () => { |
| 53 | + expect( |
| 54 | + shallowEqualScalar( |
| 55 | + { a: 1, b: 2 }, |
| 56 | + { a: 1, b: 3 } |
| 57 | + ) |
| 58 | + ).toBe(false); |
| 59 | + }); |
| 60 | + |
| 61 | + it('returns false if arguments have field that are objects', () => { |
| 62 | + const o = {}; |
| 63 | + expect( |
| 64 | + shallowEqualScalar( |
| 65 | + { a: 1, b: 2, c: o }, |
| 66 | + { a: 1, b: 2, c: o } |
| 67 | + ) |
| 68 | + ).toBe(false); |
| 69 | + }); |
| 70 | + |
| 71 | + it('returns false if arguments have different keys', () => { |
| 72 | + expect( |
| 73 | + shallowEqualScalar( |
| 74 | + { a: 1, b: 2, c: undefined }, |
| 75 | + { a: 1, bb: 2, c: undefined } |
| 76 | + ) |
| 77 | + ).toBe(false); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + describe('shallowEqual', () => { |
| 82 | + it('returns true if arguments fields are equal', () => { |
| 83 | + expect( |
| 84 | + shallowEqual( |
| 85 | + { a: 1, b: 2, c: undefined }, |
| 86 | + { a: 1, b: 2, c: undefined } |
| 87 | + ) |
| 88 | + ).toBe(true); |
| 89 | + |
| 90 | + expect( |
| 91 | + shallowEqual( |
| 92 | + { a: 1, b: 2, c: 3 }, |
| 93 | + { a: 1, b: 2, c: 3 } |
| 94 | + ) |
| 95 | + ).toBe(true); |
| 96 | + |
| 97 | + const o = {}; |
| 98 | + expect( |
| 99 | + shallowEqual( |
| 100 | + { a: 1, b: 2, c: o }, |
| 101 | + { a: 1, b: 2, c: o } |
| 102 | + ) |
| 103 | + ).toBe(true); |
| 104 | + }); |
| 105 | + |
| 106 | + it('returns false if first argument has too many keys', () => { |
| 107 | + expect( |
| 108 | + shallowEqual( |
| 109 | + { a: 1, b: 2, c: 3 }, |
| 110 | + { a: 1, b: 2 } |
| 111 | + ) |
| 112 | + ).toBe(false); |
| 113 | + }); |
| 114 | + |
| 115 | + it('returns false if second argument has too many keys', () => { |
| 116 | + expect( |
| 117 | + shallowEqual( |
| 118 | + { a: 1, b: 2 }, |
| 119 | + { a: 1, b: 2, c: 3 } |
| 120 | + ) |
| 121 | + ).toBe(false); |
| 122 | + }); |
| 123 | + |
| 124 | + it('returns false if arguments have different keys', () => { |
| 125 | + expect( |
| 126 | + shallowEqual( |
| 127 | + { a: 1, b: 2, c: undefined }, |
| 128 | + { a: 1, bb: 2, c: undefined } |
| 129 | + ) |
| 130 | + ).toBe(false); |
| 131 | + }); |
| 132 | + }); |
| 133 | + |
| 134 | +}); |
0 commit comments