File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change 11export type Opaque < K , T > = T & { __TYPE__ : K } ;
22
3- export type JSONValue =
4- | null
5- | string
6- | number
7- | boolean
8- | JSONObject
9- | JSONArray ;
3+ export type JSONValue = null | string | number | boolean | JSONObject | JSONArray ;
104export type JSONObject = { [ member : string ] : JSONValue } ;
115export interface JSONArray extends Array < JSONValue > { }
126
@@ -47,9 +41,7 @@ export type MockHandler =
4741 | ( ( args : HandlerArgument ) => JSONValue )
4842 | JSONValue ;
4943
50- export type MockHandlerFunction = (
51- args : HandlerArgument
52- ) => Promise < ResponseData > ;
44+ export type MockHandlerFunction = ( args : HandlerArgument ) => Promise < ResponseData > ;
5345export type RequestUrl = Opaque < 'RequestUrl' , string > ;
5446export type MatcherUrl = Opaque < 'MatcherUrl' , string > ;
5547
@@ -62,7 +54,9 @@ export type Middleware = (
6254 request : HandlerArgument ,
6355 response : ResponseData
6456) => ResponseData | Promise < ResponseData > ;
57+
6558export interface Configuration {
6659 enableFallback : boolean ;
60+ ignoreMiddlewareIfFallback : boolean ;
6761 middleware : Middleware ;
6862}
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import MatcherUtils from './matcher-utils';
2020
2121const defaultConfiguration : Configuration = {
2222 enableFallback : true ,
23+ ignoreMiddlewareIfFallback : false ,
2324 middleware : ( request , response ) => response
2425} ;
2526
@@ -80,6 +81,9 @@ class FetchMock {
8081 `Did not find any matching route for: ${ method . toUpperCase ( ) } ${ url } . Defaulting to the real fetch-implementation.`
8182 ) ;
8283 response = this . realFetch . call ( this . scope , input , init ) ;
84+ if ( this . configuration . ignoreMiddlewareIfFallback ) {
85+ return response as Promise < Response > ;
86+ }
8387 } else {
8488 throw new Error ( `Did not find any matching route for: ${ method . toUpperCase ( ) } ${ url } .` ) ;
8589 }
You can’t perform that action at this time.
0 commit comments