1- import * as React from 'react '
1+ import type { ThunkDispatch , UnknownAction } from '@reduxjs/toolkit '
22import type { BaseQueryFn } from '@reduxjs/toolkit/query/react'
33import { createApi , fetchBaseQuery } from '@reduxjs/toolkit/query/react'
4- import { http , HttpResponse } from 'msw'
5- import type { AxiosError , AxiosRequestConfig , AxiosResponse } from 'axios'
6- import axios from 'axios'
7- import { expectExactType , hookWaitFor , setupApiStore } from './helpers'
8- import { server } from './mocks/server'
94import {
5+ act ,
106 fireEvent ,
117 render ,
12- waitFor ,
13- screen ,
14- act ,
158 renderHook ,
9+ screen ,
10+ waitFor ,
1611} from '@testing-library/react'
12+ import type { AxiosError , AxiosRequestConfig , AxiosResponse } from 'axios'
13+ import axios from 'axios'
14+ import { HttpResponse , http } from 'msw'
15+ import * as React from 'react'
1716import { useDispatch } from 'react-redux'
18- import type { UnknownAction , ThunkDispatch } from '@reduxjs/toolkit '
17+ import { expectExactType , hookWaitFor , setupApiStore } from './helpers '
1918import type { BaseQueryApi } from '../baseQueryTypes'
19+ import { server } from './mocks/server'
2020
2121const baseQuery = fetchBaseQuery ( { baseUrl : 'https://example.com' } )
2222
@@ -34,8 +34,10 @@ const api = createApi({
3434
3535const storeRef = setupApiStore ( api )
3636
37- const failQueryOnce = http . get ( '/query' , ( ) =>
38- HttpResponse . json ( { value : 'failed' } , { status : 500 } ) , { once : true }
37+ const failQueryOnce = http . get (
38+ '/query' ,
39+ ( ) => HttpResponse . json ( { value : 'failed' } , { status : 500 } ) ,
40+ { once : true }
3941)
4042
4143describe ( 'fetchBaseQuery' , ( ) => {
@@ -86,7 +88,7 @@ describe('query error handling', () => {
8688 test ( 'success' , async ( ) => {
8789 server . use (
8890 http . get ( 'https://example.com/query' , ( ) =>
89- HttpResponse . json ( { value : 'success' } )
91+ HttpResponse . json ( { value : 'success' } )
9092 )
9193 )
9294 const { result } = renderHook ( ( ) => api . endpoints . query . useQuery ( { } ) , {
@@ -107,7 +109,7 @@ describe('query error handling', () => {
107109 test ( 'error' , async ( ) => {
108110 server . use (
109111 http . get ( 'https://example.com/query' , ( ) =>
110- HttpResponse . json ( { value : 'error' } , { status : 500 } )
112+ HttpResponse . json ( { value : 'error' } , { status : 500 } )
111113 )
112114 )
113115 const { result } = renderHook ( ( ) => api . endpoints . query . useQuery ( { } ) , {
@@ -131,7 +133,7 @@ describe('query error handling', () => {
131133 test ( 'success -> error' , async ( ) => {
132134 server . use (
133135 http . get ( 'https://example.com/query' , ( ) =>
134- HttpResponse . json ( { value : 'success' } )
136+ HttpResponse . json ( { value : 'success' } )
135137 )
136138 )
137139 const { result } = renderHook ( ( ) => api . endpoints . query . useQuery ( { } ) , {
@@ -149,8 +151,10 @@ describe('query error handling', () => {
149151 )
150152
151153 server . use (
152- http . get ( 'https://example.com/query' , ( ) =>
153- HttpResponse . json ( { value : 'error' } , { status : 500 } ) , { once : true }
154+ http . get (
155+ 'https://example.com/query' ,
156+ ( ) => HttpResponse . json ( { value : 'error' } , { status : 500 } ) ,
157+ { once : true }
154158 )
155159 )
156160
@@ -175,12 +179,14 @@ describe('query error handling', () => {
175179 test ( 'error -> success' , async ( ) => {
176180 server . use (
177181 http . get ( 'https://example.com/query' , ( ) =>
178- HttpResponse . json ( { value : 'success' } )
182+ HttpResponse . json ( { value : 'success' } )
179183 )
180184 )
181185 server . use (
182- http . get ( 'https://example.com/query' , ( ) =>
183- HttpResponse . json ( { value : 'error' } , { status : 500 } ) , { once : true }
186+ http . get (
187+ 'https://example.com/query' ,
188+ ( ) => HttpResponse . json ( { value : 'error' } , { status : 500 } ) ,
189+ { once : true }
184190 )
185191 )
186192 const { result } = renderHook ( ( ) => api . endpoints . query . useQuery ( { } ) , {
@@ -218,7 +224,7 @@ describe('mutation error handling', () => {
218224 test ( 'success' , async ( ) => {
219225 server . use (
220226 http . post ( 'https://example.com/mutation' , ( ) =>
221- HttpResponse . json ( { value : 'success' } )
227+ HttpResponse . json ( { value : 'success' } )
222228 )
223229 )
224230 const { result } = renderHook ( ( ) => api . endpoints . mutation . useMutation ( ) , {
@@ -243,7 +249,7 @@ describe('mutation error handling', () => {
243249 test ( 'error' , async ( ) => {
244250 server . use (
245251 http . post ( 'https://example.com/mutation' , ( ) =>
246- HttpResponse . json ( { value : 'error' } , { status : 500 } )
252+ HttpResponse . json ( { value : 'error' } , { status : 500 } )
247253 )
248254 )
249255 const { result } = renderHook ( ( ) => api . endpoints . mutation . useMutation ( ) , {
@@ -271,7 +277,7 @@ describe('mutation error handling', () => {
271277 test ( 'success -> error' , async ( ) => {
272278 server . use (
273279 http . post ( 'https://example.com/mutation' , ( ) =>
274- HttpResponse . json ( { value : 'success' } )
280+ HttpResponse . json ( { value : 'success' } )
275281 )
276282 )
277283 const { result } = renderHook ( ( ) => api . endpoints . mutation . useMutation ( ) , {
@@ -295,8 +301,10 @@ describe('mutation error handling', () => {
295301 }
296302
297303 server . use (
298- http . post ( 'https://example.com/mutation' , ( ) =>
299- HttpResponse . json ( { value : 'error' } , { status : 500 } ) , { once : true }
304+ http . post (
305+ 'https://example.com/mutation' ,
306+ ( ) => HttpResponse . json ( { value : 'error' } , { status : 500 } ) ,
307+ { once : true }
300308 )
301309 )
302310
@@ -324,12 +332,14 @@ describe('mutation error handling', () => {
324332 test ( 'error -> success' , async ( ) => {
325333 server . use (
326334 http . post ( 'https://example.com/mutation' , ( ) =>
327- HttpResponse . json ( { value : 'success' } )
335+ HttpResponse . json ( { value : 'success' } )
328336 )
329337 )
330338 server . use (
331- http . post ( 'https://example.com/mutation' , ( ) =>
332- HttpResponse . json ( { value : 'error' } , { status : 500 } ) , { once : true }
339+ http . post (
340+ 'https://example.com/mutation' ,
341+ ( ) => HttpResponse . json ( { value : 'error' } , { status : 500 } ) ,
342+ { once : true }
333343 )
334344 )
335345
@@ -443,7 +453,7 @@ describe('custom axios baseQuery', () => {
443453 test ( 'axios errors behave as expected' , async ( ) => {
444454 server . use (
445455 http . get ( 'https://example.com/success' , ( ) =>
446- HttpResponse . json ( { value : 'error' } , { status : 500 } )
456+ HttpResponse . json ( { value : 'error' } , { status : 500 } )
447457 )
448458 )
449459 const { result } = renderHook ( ( ) => api . endpoints . query . useQuery ( ) , {
@@ -481,8 +491,10 @@ describe('error handling in a component', () => {
481491
482492 test ( 'a mutation is unwrappable and has the correct types' , async ( ) => {
483493 server . use (
484- http . get ( 'https://example.com/success' , ( ) =>
485- HttpResponse . json ( mockErrorResponse , { status : 500 } ) , { once : true }
494+ http . get (
495+ 'https://example.com/success' ,
496+ ( ) => HttpResponse . json ( mockErrorResponse , { status : 500 } ) ,
497+ { once : true }
486498 )
487499 )
488500
0 commit comments