@@ -9,18 +9,17 @@ import {
99 beforeEach ,
1010 jest ,
1111 afterAll ,
12- mock ,
12+ spyOn ,
1313} from "bun:test"
1414import { FetchProxy } from "../src/proxy"
1515import { CircuitState } from "../src/types"
1616import type { ProxyRequestOptions , CircuitBreakerResult } from "../src/types"
1717
18- // Mock fetch for testing
19- const mockFetch = jest . fn ( )
20- ; ( global as any ) . fetch = mockFetch
18+ // Spy on fetch for testing
19+ let fetchSpy : ReturnType < typeof spyOn >
2120
2221afterAll ( ( ) => {
23- mock . restore ( )
22+ fetchSpy ?. mockRestore ( )
2423} )
2524
2625describe ( "Enhanced Hook Naming Conventions" , ( ) => {
@@ -39,8 +38,9 @@ describe("Enhanced Hook Naming Conventions", () => {
3938 headers : new Headers ( { "content-type" : "application/json" } ) ,
4039 } )
4140
42- mockFetch . mockClear ( )
43- mockFetch . mockResolvedValue ( mockResponse )
41+ fetchSpy = spyOn ( global , "fetch" )
42+ fetchSpy . mockClear ( )
43+ fetchSpy . mockResolvedValue ( mockResponse )
4444 } )
4545
4646 describe ( "beforeRequest Hook" , ( ) => {
@@ -56,7 +56,7 @@ describe("Enhanced Hook Naming Conventions", () => {
5656
5757 expect ( beforeRequestHook ) . toHaveBeenCalledTimes ( 1 )
5858 expect ( beforeRequestHook ) . toHaveBeenCalledWith ( request , options )
59- expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 )
59+ expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 )
6060 } )
6161
6262 it ( "should handle async beforeRequest hooks" , async ( ) => {
@@ -139,7 +139,7 @@ describe("Enhanced Hook Naming Conventions", () => {
139139 const request = new Request ( "https://example.com/test" )
140140 const error = new Error ( "Network error" )
141141
142- mockFetch . mockRejectedValueOnce ( error )
142+ fetchSpy . mockRejectedValueOnce ( error )
143143
144144 const options : ProxyRequestOptions = {
145145 afterCircuitBreakerExecution : afterCircuitBreakerHook ,
@@ -166,7 +166,7 @@ describe("Enhanced Hook Naming Conventions", () => {
166166 const request = new Request ( "https://example.com/test" )
167167
168168 // Add some delay to the fetch
169- mockFetch . mockImplementationOnce (
169+ fetchSpy . mockImplementationOnce (
170170 ( ) =>
171171 new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( mockResponse ) , 50 ) ) ,
172172 )
@@ -296,8 +296,8 @@ describe("Enhanced Hook Naming Conventions", () => {
296296 await proxy . proxy ( request , undefined , options )
297297
298298 // Verify the mock was called (we can't easily verify exact headers due to internal processing)
299- expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 )
300- expect ( mockFetch ) . toHaveBeenCalledWith (
299+ expect ( fetchSpy ) . toHaveBeenCalledTimes ( 1 )
300+ expect ( fetchSpy ) . toHaveBeenCalledWith (
301301 expect . any ( String ) ,
302302 expect . objectContaining ( {
303303 headers : expect . any ( Headers ) ,
@@ -315,7 +315,7 @@ describe("Enhanced Hook Naming Conventions", () => {
315315 } ,
316316 } )
317317
318- mockFetch . mockResolvedValueOnce ( originalResponse )
318+ fetchSpy . mockResolvedValueOnce ( originalResponse )
319319
320320 const request = new Request ( "https://example.com/test" )
321321
0 commit comments