source: node_modules/@reduxjs/toolkit/src/query/tests/retry.test-d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.6 KB
Line 
1import { retry, type RetryOptions } from '@internal/query/retry'
2import {
3 fetchBaseQuery,
4 type FetchBaseQueryError,
5 type FetchBaseQueryMeta,
6} from '@internal/query/fetchBaseQuery'
7
8describe('type tests', () => {
9 test('RetryOptions only accepts one of maxRetries or retryCondition', () => {
10 // Should not complain if only `maxRetries` exists
11 expectTypeOf({ maxRetries: 5 }).toMatchTypeOf<RetryOptions>()
12
13 // Should not complain if only `retryCondition` exists
14 expectTypeOf({ retryCondition: () => false }).toMatchTypeOf<RetryOptions>()
15
16 // Should complain if both `maxRetries` and `retryCondition` exist at once
17 expectTypeOf({
18 maxRetries: 5,
19 retryCondition: () => false,
20 }).not.toMatchTypeOf<RetryOptions>()
21 })
22 test('fail can be pretyped to only accept correct error and meta', () => {
23 expectTypeOf(retry.fail).parameter(0).toEqualTypeOf<unknown>()
24 expectTypeOf(retry.fail).parameter(1).toEqualTypeOf<{} | undefined>()
25 expectTypeOf(retry.fail).toBeCallableWith('Literally anything', {})
26
27 const myBaseQuery = fetchBaseQuery()
28 const typedFail = retry.fail<typeof myBaseQuery>
29
30 expectTypeOf(typedFail).parameter(0).toMatchTypeOf<FetchBaseQueryError>()
31 expectTypeOf(typedFail)
32 .parameter(1)
33 .toMatchTypeOf<FetchBaseQueryMeta | undefined>()
34
35 expectTypeOf(typedFail).toBeCallableWith(
36 {
37 status: 401,
38 data: 'Unauthorized',
39 },
40 { request: new Request('http://localhost') },
41 )
42
43 expectTypeOf(typedFail).parameter(0).not.toMatchTypeOf<string>()
44 expectTypeOf(typedFail).parameter(1).not.toMatchTypeOf<{}>()
45 })
46})
Note: See TracBrowser for help on using the repository browser.