|
6 | 6 | matchMutation,
|
7 | 7 | scheduleMicrotask,
|
8 | 8 | sleep,
|
| 9 | + isPlainArray, |
9 | 10 | } from '../utils'
|
10 | 11 | import { Mutation } from '../mutation'
|
11 | 12 | import { createQueryClient } from '../../tests/utils'
|
@@ -56,6 +57,16 @@ describe('core/utils', () => {
|
56 | 57 | })
|
57 | 58 | })
|
58 | 59 |
|
| 60 | + describe('isPlainArray', () => { |
| 61 | + it('should return `true` for plain arrays', () => { |
| 62 | + expect(isPlainArray([1, 2])).toEqual(true) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should return `false` for non plain arrays', () => { |
| 66 | + expect(isPlainArray(Object.assign([1, 2], { a: 'b' }))).toEqual(false) |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
59 | 70 | describe('partialDeepEqual', () => {
|
60 | 71 | it('should return `true` if a includes b', () => {
|
61 | 72 | const a = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
|
@@ -258,6 +269,13 @@ describe('core/utils', () => {
|
258 | 269 | expect(result[1]).toBe(prev[1])
|
259 | 270 | })
|
260 | 271 |
|
| 272 | + it('should support objects which are not plain arrays', () => { |
| 273 | + const prev = Object.assign([1, 2], { a: { b: 'b' }, c: 'c' }) |
| 274 | + const next = Object.assign([1, 2], { a: { b: 'b' }, c: 'c' }) |
| 275 | + const result = replaceEqualDeep(prev, next) |
| 276 | + expect(result).toBe(next) |
| 277 | + }) |
| 278 | + |
261 | 279 | it('should replace all parent objects if some nested value changes', () => {
|
262 | 280 | const prev = {
|
263 | 281 | todo: { id: '1', meta: { createdAt: 0 }, state: { done: false } },
|
|
0 commit comments