Skip to content

Commit 5105897

Browse files
authored
Merge pull request #18 from nutgaard/feat/no-warning
feat(logging): add feature-flag to suppress real-fetch warning
2 parents f32a3da + bc9c729 commit 5105897

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export type Middleware = (
5757

5858
export interface Configuration {
5959
enableFallback: boolean;
60+
suppressRealFetchWarning: boolean;
6061
ignoreMiddlewareIfFallback: boolean;
6162
middleware: Middleware;
6263
}

src/yet-another-fetch-mock.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import MockContext from './mock-context';
2323

2424
const defaultConfiguration: Configuration = {
2525
enableFallback: true,
26+
suppressRealFetchWarning: false,
2627
ignoreMiddlewareIfFallback: false,
2728
middleware: (request, response) => response
2829
};
@@ -100,9 +101,11 @@ class FetchMock {
100101

101102
if (typeof matchingRoute === 'undefined') {
102103
if (this.configuration.enableFallback) {
103-
console.warn(
104-
`Did not find any matching route for: ${method.toUpperCase()} ${url}. Defaulting to the real fetch-implementation.`
105-
);
104+
if (!this.configuration.suppressRealFetchWarning) {
105+
console.warn(
106+
`Did not find any matching route for: ${method.toUpperCase()} ${url}. Defaulting to the real fetch-implementation.`
107+
);
108+
}
106109
response = this.realFetch.call(this.scope, input, init);
107110
if (this.configuration.ignoreMiddlewareIfFallback) {
108111
return response as Promise<Response>;

0 commit comments

Comments
 (0)