File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
libs/providers/go-feature-flag/src/lib Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,9 @@ describe('GoFeatureFlagApi', () => {
4848 await api . retrieveFlagConfiguration ( ) ;
4949
5050 const request = mockFetch . getLastRequest ( ) ;
51- expect ( request ! . url ) . toBe ( 'http://localhost:8080/v1/flag/configuration' ) ;
52- expect ( request ! . options . method ) . toBe ( 'POST' ) ;
53- expect ( request ! . options . body ) . toBe ( JSON . stringify ( { flags : [ ] } ) ) ;
51+ expect ( request ? .url ) . toBe ( 'http://localhost:8080/v1/flag/configuration' ) ;
52+ expect ( request ? .options . method ) . toBe ( 'POST' ) ;
53+ expect ( request ? .options . body ) . toEqual ( JSON . stringify ( { flags : [ ] } ) ) ;
5454 } ) ;
5555
5656 it ( 'should include API key in authorization header when provided' , async ( ) => {
@@ -64,7 +64,7 @@ describe('GoFeatureFlagApi', () => {
6464 await api . retrieveFlagConfiguration ( ) ;
6565
6666 const request = mockFetch . getLastRequest ( ) ;
67- expect ( request ! . options . headers ) . toHaveProperty ( 'Authorization' , 'Bearer my-api-key' ) ;
67+ expect ( request ? .options . headers ) . toHaveProperty ( 'Authorization' , 'Bearer my-api-key' ) ;
6868 } ) ;
6969
7070 it ( 'should not include authorization header when API key is not provided' , async ( ) => {
Original file line number Diff line number Diff line change @@ -67,13 +67,23 @@ export class MockFetch {
6767
6868 // Check if we have a specific response for this URL
6969 if ( this . responses . has ( url ) ) {
70- return this . responses . get ( url ) ! as unknown as Response ;
70+ const response = this . responses . get ( url ) ;
71+ if ( typeof response === 'function' ) {
72+ // Allow for dynamic response functions (for advanced mocking)
73+ return ( response as any ) ( url , options ) as Response ;
74+ }
75+ return response as unknown as Response ;
7176 }
7277
7378 // Check if we have a response by status code
7479 const statusMatch = url . match ( / ( \d { 3 } ) / ) ;
7580 if ( statusMatch && this . responses . has ( statusMatch [ 1 ] ) ) {
76- return this . responses . get ( statusMatch [ 1 ] ) ! as unknown as Response ;
81+ const response = this . responses . get ( statusMatch [ 1 ] ) ;
82+ if ( typeof response === 'function' ) {
83+ // Allow for dynamic response functions (for advanced mocking)
84+ return ( response as any ) ( url , options ) as Response ;
85+ }
86+ return response as unknown as Response ;
7787 }
7888
7989 // Check if we have a response by status code in the responses map
You can’t perform that action at this time.
0 commit comments