react-code-dataset / react-query /packages /angular-query-experimental /src /__tests__ /inject-mutation.test-d.ts
Download react-query/packages/angular-query-experimental/src/__tests__/inject-mutation.test-d.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/angular-query-experimental/src/__tests__/inject-mutation.test-d.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/angular-query-experimental/src/__tests__/inject-mutation.test-d.ts
-
curl -L -o inject-mutation.test-d.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/angular-query-experimental/src/__tests__/inject-mutation.test-d.ts
2.22 kB
| import { describe, expectTypeOf, test } from 'vitest' | |
| import { sleep } from '@tanstack/query-test-utils' | |
| import { injectMutation } from '..' | |
| import type { Signal } from '@angular/core' | |
| describe('Discriminated union return type', () => { | |
| test('data should be possibly undefined by default', () => { | |
| const mutation = injectMutation(() => ({ | |
| mutationFn: () => sleep(0).then(() => 'string'), | |
| })) | |
| expectTypeOf(mutation.data).toEqualTypeOf<Signal<string | undefined>>() | |
| }) | |
| test('data should be defined when mutation is success', () => { | |
| const mutation = injectMutation(() => ({ | |
| mutationFn: () => sleep(0).then(() => 'string'), | |
| })) | |
| if (mutation.isSuccess()) { | |
| expectTypeOf(mutation.data).toEqualTypeOf<Signal<string>>() | |
| } | |
| }) | |
| test('error should be null when mutation is success', () => { | |
| const mutation = injectMutation(() => ({ | |
| mutationFn: () => sleep(0).then(() => 'string'), | |
| })) | |
| if (mutation.isSuccess()) { | |
| expectTypeOf(mutation.error).toEqualTypeOf<Signal<null>>() | |
| } | |
| }) | |
| test('data should be undefined when mutation is pending', () => { | |
| const mutation = injectMutation(() => ({ | |
| mutationFn: () => sleep(0).then(() => 'string'), | |
| })) | |
| if (mutation.isPending()) { | |
| expectTypeOf(mutation.data).toEqualTypeOf<Signal<undefined>>() | |
| } | |
| }) | |
| test('error should be defined when mutation is error', () => { | |
| const mutation = injectMutation(() => ({ | |
| mutationFn: () => sleep(0).then(() => 'string'), | |
| })) | |
| if (mutation.isError()) { | |
| expectTypeOf(mutation.error).toEqualTypeOf<Signal<Error>>() | |
| } | |
| }) | |
| test('should narrow variables', () => { | |
| const mutation = injectMutation(() => ({ | |
| mutationFn: (_variables: string) => sleep(0).then(() => 'string'), | |
| })) | |
| if (mutation.isIdle()) { | |
| expectTypeOf(mutation.variables).toEqualTypeOf<Signal<undefined>>() | |
| } | |
| if (mutation.isPending()) { | |
| expectTypeOf(mutation.variables).toEqualTypeOf<Signal<string>>() | |
| } | |
| if (mutation.isSuccess()) { | |
| expectTypeOf(mutation.variables).toEqualTypeOf<Signal<string>>() | |
| } | |
| expectTypeOf(mutation.variables).toEqualTypeOf<Signal<string | undefined>>() | |
| }) | |
| }) | |