@@ -20,10 +20,9 @@ import {
2020 renderHook ,
2121} from '@testing-library/react'
2222import userEvent from '@testing-library/user-event'
23- import { rest } from 'msw'
23+ import { http , HttpResponse } from 'msw'
2424import {
2525 actionsReducer ,
26- ANY ,
2726 expectExactType ,
2827 expectType ,
2928 setupApiStore ,
@@ -104,7 +103,7 @@ const api = createApi({
104103 query : ( update ) => ( { body : update } ) ,
105104 } ) ,
106105 getError : build . query ( {
107- query : ( query ) => '/error' ,
106+ query : ( ) => '/error' ,
108107 } ) ,
109108 listItems : build . query < Item [ ] , { pageNumber : number } > ( {
110109 serializeQueryArgs : ( { endpointName } ) => {
@@ -119,7 +118,7 @@ const api = createApi({
119118 merge : ( currentCache , newItems ) => {
120119 currentCache . push ( ...newItems )
121120 } ,
122- forceRefetch : ( { currentArg , previousArg } ) => {
121+ forceRefetch : ( ) => {
123122 return true
124123 } ,
125124 } ) ,
@@ -757,7 +756,7 @@ describe('hooks tests', () => {
757756 }
758757
759758 // 1) Initial state: an active subscription
760- const { result , rerender, unmount } = renderHook (
759+ const { rerender, unmount } = renderHook (
761760 ( [ arg , options ] : Parameters <
762761 typeof pokemonApi . useGetPokemonByNameQuery
763762 > ) => pokemonApi . useGetPokemonByNameQuery ( arg , options ) ,
@@ -1752,14 +1751,14 @@ describe('hooks tests', () => {
17521751 test ( 'initially failed useQueries that provide an tag will refetch after a mutation invalidates it' , async ( ) => {
17531752 const checkSessionData = { name : 'matt' }
17541753 server . use (
1755- rest . get ( 'https://example.com/me' , ( req , res , ctx ) => {
1756- return res . once ( ctx . status ( 500 ) )
1754+ http . get ( 'https://example.com/me' , ( ) => {
1755+ return HttpResponse . json ( null , { status : 500 } )
1756+ } , { once : true } ) ,
1757+ http . get ( 'https://example.com/me' , ( ) => {
1758+ return HttpResponse . json ( checkSessionData )
17571759 } ) ,
1758- rest . get ( 'https://example.com/me' , ( req , res , ctx ) => {
1759- return res ( ctx . json ( checkSessionData ) )
1760- } ) ,
1761- rest . post ( 'https://example.com/login' , ( req , res , ctx ) => {
1762- return res ( ctx . status ( 200 ) )
1760+ http . post ( 'https://example.com/login' , ( ) => {
1761+ return HttpResponse . json ( null , { status : 200 } )
17631762 } )
17641763 )
17651764 let data , isLoading , isError
@@ -1977,39 +1976,41 @@ describe('hooks with createApi defaults set', () => {
19771976 posts = [ ...initialPosts ]
19781977
19791978 const handlers = [
1980- rest . get ( 'https://example.com/posts' , ( req , res , ctx ) => {
1981- return res ( ctx . json ( posts ) )
1979+ http . get ( 'https://example.com/posts' , ( ) => {
1980+ return HttpResponse . json ( posts )
19821981 } ) ,
1983- rest . put < Partial < Post > > (
1982+ http . put < { id : string } , Partial < Post > > (
19841983 'https://example.com/post/:id' ,
1985- ( req , res , ctx ) => {
1986- const id = Number ( req . params . id )
1984+ async ( { request, params } ) => {
1985+ const body = await request . json ( ) ;
1986+ const id = Number ( params . id )
19871987 const idx = posts . findIndex ( ( post ) => post . id === id )
19881988
19891989 const newPosts = posts . map ( ( post , index ) =>
19901990 index !== idx
19911991 ? post
19921992 : {
1993- ...req . body ,
1993+ ...body ,
19941994 id,
1995- name : req . body . name || post . name ,
1995+ name : body ? .name || post . name ,
19961996 fetched_at : new Date ( ) . toUTCString ( ) ,
19971997 }
19981998 )
19991999 posts = [ ...newPosts ]
20002000
2001- return res ( ctx . json ( posts ) )
2001+ return HttpResponse . json ( posts )
20022002 }
20032003 ) ,
2004- rest . post ( 'https://example.com/post' , ( req , res , ctx ) => {
2005- let post = req . body as Omit < Post , 'id' >
2004+ http . post < any , Omit < Post , 'id' > > ( 'https://example.com/post' , async ( { request } ) => {
2005+ const body = await request . json ( ) ;
2006+ let post = body
20062007 startingId += 1
20072008 posts . concat ( {
20082009 ...post ,
20092010 fetched_at : new Date ( ) . toISOString ( ) ,
20102011 id : startingId ,
20112012 } )
2012- return res ( ctx . json ( posts ) )
2013+ return HttpResponse . json ( posts )
20132014 } ) ,
20142015 ]
20152016
@@ -2377,11 +2378,6 @@ describe('hooks with createApi defaults set', () => {
23772378
23782379 test ( 'useQuery with selectFromResult option has a type error if the result is not an object' , async ( ) => {
23792380 function SelectedPost ( ) {
2380- const _res1 = api . endpoints . getPosts . useQuery ( undefined , {
2381- // selectFromResult must always return an object
2382- // @ts -expect-error
2383- selectFromResult : ( { data } ) => data ?. length ?? 0 ,
2384- } )
23852381
23862382 const res2 = api . endpoints . getPosts . useQuery ( undefined , {
23872383 // selectFromResult must always return an object
0 commit comments