From 12b678232c094006d78887b197f53c2af89838c7 Mon Sep 17 00:00:00 2001 From: Sol Lee <82362278+saul-atomrigs@users.noreply.github.com> Date: Tue, 3 Dec 2024 00:31:52 +0900 Subject: [PATCH] test(query-core): add type check tests for `queryObserver` (#8304) Co-authored-by: Dominik Dorfmeister --- .../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'>() } })