Skip to content
Source
Sign inSign up
TanStack/query

test(query-core): add type check tests for `queryObserver` #8304

Mergedsaul-atomrigs(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/8304/headmerged by TkDodo View on GitHub

Showing 1 changed file with 30 additions and 3 deletions.

x
0 of 1 viewed, 1 left
30 additions and 3 deletionspackages/query-core/src/__tests__/queryObserver.test-d.tsxModified
View file
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expectTypeOf, it } from 'vitest'
import { QueryObserver } from '..'
import { createQueryClient, queryKey } from './utils'
-import type { QueryClient } from '..'
+import type { DefaultError, QueryClient } from '..'
​
describe('queryObserver', () => {
let queryClient: QueryClient
@@ -26,31 +26,58 @@
if (result.isPending) {
expectTypeOf(result.data).toEqualTypeOf<undefined>()
expectTypeOf(result.error).toEqualTypeOf<null>()
+ expectTypeOf(result.isError).toEqualTypeOf<false>()
+ expectTypeOf(result.isPending).toEqualTypeOf<true>()
expectTypeOf(result.isLoading).toEqualTypeOf<boolean>()
+ expectTypeOf(result.isLoadingError).toEqualTypeOf<false>()
+ expectTypeOf(result.isRefetchError).toEqualTypeOf<false>()
expectTypeOf(result.status).toEqualTypeOf<'pending'>()
if (result.isLoading) {
expectTypeOf(result.data).toEqualTypeOf<undefined>()
expectTypeOf(result.error).toEqualTypeOf<null>()
+ expectTypeOf(result.isError).toEqualTypeOf<false>()
expectTypeOf(result.isPending).toEqualTypeOf<true>()
+ expectTypeOf(result.isLoading).toEqualTypeOf<true>()