From 73ba1fd9b45bdbbd19c82c0156b9449c53ab84a7 Mon Sep 17 00:00:00 2001 From: Saul Lee Date: Tue, 19 Nov 2024 14:25:18 +0900 Subject: [PATCH] test(query-core): add type check tests for `queryObserver` --- .../src/__tests__/queryObserver.test-d.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/query-core/src/__tests__/queryObserver.test-d.tsx b/packages/query-core/src/__tests__/queryObserver.test-d.tsx index cc12bdd909..6ff4951a26 100644 --- a/packages/query-core/src/__tests__/queryObserver.test-d.tsx +++ b/packages/query-core/src/__tests__/queryObserver.test-d.tsx @@ -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 @@ describe('queryObserver', () => { if (result.isPending) { expectTypeOf(result.data).toEqualTypeOf() expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.isError).toEqualTypeOf() + expectTypeOf(result.isPending).toEqualTypeOf() expectTypeOf(result.isLoading).toEqualTypeOf() + expectTypeOf(result.isLoadingError).toEqualTypeOf() + expectTypeOf(result.isRefetchError).toEqualTypeOf() expectTypeOf(result.status).toEqualTypeOf<'pending'>() } if (result.isLoading) { expectTypeOf(result.data).toEqualTypeOf() expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.isError).toEqualTypeOf() expectTypeOf(result.isPending).toEqualTypeOf() + expectTypeOf(result.isLoading).toEqualTypeOf() + expectTypeOf(result.isLoadingError).toEqualTypeOf() + expectTypeOf(result.isRefetchError).toEqualTypeOf() + expectTypeOf(result.isSuccess).toEqualTypeOf() expectTypeOf(result.status).toEqualTypeOf<'pending'>() } if (result.isLoadingError) { expectTypeOf(result.data).toEqualTypeOf() - expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.isError).toEqualTypeOf() + expectTypeOf(result.isPending).toEqualTypeOf() + expectTypeOf(result.isLoading).toEqualTypeOf() + expectTypeOf(result.isLoadingError).toEqualTypeOf() + expectTypeOf(result.isRefetchError).toEqualTypeOf() + expectTypeOf(result.isSuccess).toEqualTypeOf() expectTypeOf(result.status).toEqualTypeOf<'error'>() } if (result.isRefetchError) { expectTypeOf(result.data).toEqualTypeOf<{ value: string }>() - expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.isError).toEqualTypeOf() + expectTypeOf(result.isPending).toEqualTypeOf() + expectTypeOf(result.isLoading).toEqualTypeOf() + expectTypeOf(result.isLoadingError).toEqualTypeOf() + expectTypeOf(result.isRefetchError).toEqualTypeOf() + expectTypeOf(result.isSuccess).toEqualTypeOf() expectTypeOf(result.status).toEqualTypeOf<'error'>() } if (result.isSuccess) { expectTypeOf(result.data).toEqualTypeOf<{ value: string }>() expectTypeOf(result.error).toEqualTypeOf() + expectTypeOf(result.isError).toEqualTypeOf() + expectTypeOf(result.isPending).toEqualTypeOf() + expectTypeOf(result.isLoading).toEqualTypeOf() + expectTypeOf(result.isLoadingError).toEqualTypeOf() + expectTypeOf(result.isRefetchError).toEqualTypeOf() + expectTypeOf(result.isSuccess).toEqualTypeOf() expectTypeOf(result.status).toEqualTypeOf<'success'>() } })