Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/query-core/src/__tests__/utils.test.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ import {
hashQueryKeyByOptions,
isPlainArray,
isPlainObject,
isValidTimeout,
keepPreviousData,
matchMutation,
partialMatchKey,
Expand DownExpand Up@@ -166,6 +167,18 @@ describe('core/utils', () => {
const b = [{ a: null, c: 'c', d: [{ d: 'd ' }] }]
expect(partialMatchKey(a, b)).toEqual(false)
})

it('should treat undefined object properties as matching missing properties', () => {
const queryKeyWithUndefined = ['todos', { filters: undefined }]
const queryKeyWithoutProperty = ['todos', {}]

expect(
partialMatchKey(queryKeyWithoutProperty, queryKeyWithUndefined),
).toEqual(true)
expect(
partialMatchKey(queryKeyWithUndefined, queryKeyWithoutProperty),
).toEqual(true)
})
})

describe('replaceEqualDeep', () => {
Expand DownExpand Up@@ -559,6 +572,28 @@ describe('core/utils', () => {

expect(hashKey(nested1)).toEqual(hashKey(nested2))
})

it('should hash undefined object properties the same as missing properties', () => {
const withUndefined = ['todos', { filters: undefined }]
const withoutProperty = ['todos', {}]

expect(hashKey(withUndefined)).toEqual(hashKey(withoutProperty))
})
})

describe('isValidTimeout', () => {
it('should accept valid timeout values', () => {
expect(isValidTimeout(0)).toEqual(true)
expect(isValidTimeout(1_000)).toEqual(true)
})

it('should reject invalid timeout values', () => {
expect(isValidTimeout(-1)).toEqual(false)
expect(isValidTimeout(Number.NaN)).toEqual(false)
expect(isValidTimeout(Number.POSITIVE_INFINITY)).toEqual(false)
expect(isValidTimeout('1000')).toEqual(false)
expect(isValidTimeout(undefined)).toEqual(false)
})
})

describe('ensureQueryFn', () => {
Expand Down
Loading