diff --git a/packages/query-core/src/__tests__/utils.test.tsx b/packages/query-core/src/__tests__/utils.test.tsx index 7e72376b35..da1b69bf46 100644 --- a/packages/query-core/src/__tests__/utils.test.tsx +++ b/packages/query-core/src/__tests__/utils.test.tsx @@ -10,6 +10,7 @@ import { hashQueryKeyByOptions, isPlainArray, isPlainObject, + isValidTimeout, keepPreviousData, matchMutation, partialMatchKey, @@ -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', () => { @@ -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', () => {