33 */
44
55import React from "react" ;
6- import { afterEach , beforeEach , describe , expect , it , vi , type MockInstance } from "vitest" ;
76import { act , renderHook , waitFor } from "@testing-library/react" ;
87import * as swrModule from "swr" ;
8+ import {
9+ afterEach ,
10+ beforeEach ,
11+ describe ,
12+ expect ,
13+ it ,
14+ vi ,
15+ type MockInstance
16+ } from "vitest" ;
917
1018import type { User } from "../../types/index.js" ;
1119import { useUser } from "./use-user.js" ;
@@ -137,7 +145,10 @@ describe.only("useUser Integration with SWR Cache", () => {
137145
138146 // Explicitly type fetchSpy using MockInstance and the global fetch signature
139147 let fetchSpy : MockInstance <
140- ( input : RequestInfo | URL , init ?: RequestInit | undefined ) => Promise < Response >
148+ (
149+ input : RequestInfo | URL ,
150+ init ?: RequestInit | undefined
151+ ) => Promise < Response >
141152 > ;
142153
143154 beforeEach ( ( ) => {
@@ -159,7 +170,9 @@ describe.only("useUser Integration with SWR Cache", () => {
159170 ) ;
160171
161172 const wrapper = ( { children } : { children : React . ReactNode } ) => (
162- < swrModule . SWRConfig value = { { provider : ( ) => new Map ( ) } } > { children } </ swrModule . SWRConfig >
173+ < swrModule . SWRConfig value = { { provider : ( ) => new Map ( ) } } >
174+ { children }
175+ </ swrModule . SWRConfig >
163176 ) ;
164177
165178 const { result } = renderHook ( ( ) => useUser ( ) , { wrapper } ) ;
@@ -233,12 +246,12 @@ describe.only("useUser Integration with SWR Cache", () => {
233246 result . current . invalidate ( ) ;
234247 } ) ;
235248
236- // Wait for the hook to reflect the error state, user should still be the initial one before error
249+ // Wait for the hook to reflect the error state, user should still be the initial one before error
237250 await waitFor ( ( ) => expect ( result . current . error ) . not . toBeNull ( ) ) ;
238251
239252 // Assert error state - SWR catches the rejection from fetch itself.
240253 // Check for the message of the error we explicitly rejected with.
241- expect ( result . current . user ) . toEqual ( initialUser ) ; // SWR might keep stale data upon rejection
254+ expect ( result . current . user ) . toBeNull ( ) ; // Expect null now, not stale data
242255 expect ( result . current . error ?. message ) . toBe ( fetchError . message ) ; // Correct assertion
243256 expect ( result . current . isLoading ) . toBe ( false ) ;
244257
0 commit comments