|
1 | 1 | import { setConsole, queryCache, queryCaches } from '../' |
2 | | -import { deepEqual } from '../utils' |
| 2 | +import { deepEqual, shallowEqual } from '../utils' |
3 | 3 |
|
4 | 4 | describe('core/utils', () => { |
5 | 5 | afterEach(() => { |
@@ -28,17 +28,76 @@ describe('core/utils', () => { |
28 | 28 | setConsole(console) |
29 | 29 | }) |
30 | 30 |
|
31 | | - it('deepequal should return `false` for different dates', () => { |
32 | | - const date1 = new Date(2020, 3, 1) |
33 | | - const date2 = new Date(2020, 3, 2) |
| 31 | + describe('deepEqual', () => { |
| 32 | + it('should return `true` for equal objects', () => { |
| 33 | + const a = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] } |
| 34 | + const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] } |
| 35 | + expect(deepEqual(a, b)).toEqual(true) |
| 36 | + }) |
34 | 37 |
|
35 | | - expect(deepEqual(date1, date2)).toEqual(false) |
| 38 | + it('should return `false` for non equal objects', () => { |
| 39 | + const a = { a: { b: 'b' }, c: 'c' } |
| 40 | + const b = { a: { b: 'c' }, c: 'c' } |
| 41 | + expect(deepEqual(a, b)).toEqual(false) |
| 42 | + }) |
| 43 | + |
| 44 | + it('should return `false` for different dates', () => { |
| 45 | + const date1 = new Date(2020, 3, 1) |
| 46 | + const date2 = new Date(2020, 3, 2) |
| 47 | + expect(deepEqual(date1, date2)).toEqual(false) |
| 48 | + }) |
| 49 | + |
| 50 | + it('return `true` for equal dates', () => { |
| 51 | + const date1 = new Date(2020, 3, 1) |
| 52 | + const date2 = new Date(2020, 3, 1) |
| 53 | + expect(deepEqual(date1, date2)).toEqual(true) |
| 54 | + }) |
36 | 55 | }) |
37 | 56 |
|
38 | | - it('should return `true` for equal dates', () => { |
39 | | - const date1 = new Date(2020, 3, 1) |
40 | | - const date2 = new Date(2020, 3, 1) |
| 57 | + describe('shallowEqual', () => { |
| 58 | + it('should return `true` for empty objects', () => { |
| 59 | + expect(shallowEqual({}, {})).toEqual(true) |
| 60 | + }) |
| 61 | + |
| 62 | + it('should return `true` for equal values', () => { |
| 63 | + expect(shallowEqual(1, 1)).toEqual(true) |
| 64 | + }) |
| 65 | + |
| 66 | + it('should return `true` for equal arrays', () => { |
| 67 | + expect(shallowEqual([1, 2], [1, 2])).toEqual(true) |
| 68 | + }) |
| 69 | + |
| 70 | + it('should return `true` for equal shallow objects', () => { |
| 71 | + const a = { a: 'a', b: 'b' } |
| 72 | + const b = { a: 'a', b: 'b' } |
| 73 | + expect(shallowEqual(a, b)).toEqual(true) |
| 74 | + }) |
| 75 | + |
| 76 | + it('should return `true` for equal deep objects with same identities', () => { |
| 77 | + const deep = { b: 'b' } |
| 78 | + const a = { a: deep, c: 'c' } |
| 79 | + const b = { a: deep, c: 'c' } |
| 80 | + expect(shallowEqual(a, b)).toEqual(true) |
| 81 | + }) |
| 82 | + |
| 83 | + it('should return `false` for non equal values', () => { |
| 84 | + expect(shallowEqual(1, 2)).toEqual(false) |
| 85 | + }) |
| 86 | + |
| 87 | + it('should return `false` for equal arrays', () => { |
| 88 | + expect(shallowEqual([1, 2], [1, 3])).toEqual(false) |
| 89 | + }) |
| 90 | + |
| 91 | + it('should return `false` for non equal shallow objects', () => { |
| 92 | + const a = { a: 'a', b: 'b' } |
| 93 | + const b = { a: 'a', b: 'c' } |
| 94 | + expect(shallowEqual(a, b)).toEqual(false) |
| 95 | + }) |
41 | 96 |
|
42 | | - expect(deepEqual(date1, date2)).toEqual(true) |
| 97 | + it('should return `false` for equal deep objects with different identities', () => { |
| 98 | + const a = { a: { b: 'b' }, c: 'c' } |
| 99 | + const b = { a: { b: 'b' }, c: 'c' } |
| 100 | + expect(shallowEqual(a, b)).toEqual(false) |
| 101 | + }) |
43 | 102 | }) |
44 | 103 | }) |
0 commit comments