Skip to content

Commit 584a861

Browse files
committed
feat: implemented removeRoute method
1 parent e127a87 commit 584a861

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

docs/docs/API/more-routing-methods.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Creates a route that only responds to a single request using a particular http m
6969

7070
Modifies a route's behaviour, overwriting any options (including matcher and response) passed into the named route when first created. Useful when writing tests for special cases that require different behaviour to that required by the majority of your tests.
7171

72-
## deleteRoute(routeName)
72+
## removeRoute(routeName)
7373

7474
Removes a route. Useful when writing tests for special cases that do not require a route that's required by the majority of your tests.
7575

docs/docs/Usage/upgrade-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The same is true for `postOnce()`, `deleteOnce()` etc.
4343

4444
### Options removed
4545

46-
- `overwriteRoutes` - this reflects that multiple routes using the same underlying matcher but different options no longer throw an error. If you still need to overwrite route behaviour (equivalent to `overwriteRoutes: true`) use [`modifyRoute()` or `deleteRoute()`](/fetch-mock/docs/API/more-routing-methods#)
46+
- `overwriteRoutes` - this reflects that multiple routes using the same underlying matcher but different options no longer throw an error. If you still need to overwrite route behaviour (equivalent to `overwriteRoutes: true`) use [`modifyRoute()` or `removeRoute()`](/fetch-mock/docs/API/more-routing-methods#)
4747
- `warnOnFallback` - given the improved state of node.js debugging tools compared to when fetch-mock was first written, this debugging utilty has been removed.
4848
- `sendAsJson` - fetch-mock@12 implements streams more robustly than previous options, so the user no longer needs to flag when an object response should be converted to JSON.
4949
- `fallbackToNetwork` - The [`spyGlobal()` method](/fetch-mock/docs/API/mocking-and-spying#spyglobal) should now be used.

packages/fetch-mock/src/FetchMock.ts

+7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class FetchMock {
126126
this.router.addRoute(matcher, response, options);
127127
return this;
128128
}
129+
129130
catch(response?: RouteResponse): FetchMock {
130131
this.router.setFallback(response);
131132
return this;
@@ -137,6 +138,12 @@ export class FetchMock {
137138
this.router.removeRoutes(options);
138139
return this;
139140
}
141+
142+
removeRoute(routeName: string): FetchMock {
143+
this.router.removeRoutes({ names: [routeName] });
144+
return this;
145+
}
146+
140147
clearHistory(): FetchMock {
141148
this.callHistory.clear();
142149
return this;

packages/fetch-mock/src/__tests__/FetchMock/routing.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,17 @@ describe('Routing', () => {
251251
});
252252
});
253253
describe('modifyRoute', () => {});
254-
describe('deleteRoute', () => {
255-
testChainableRoutingMethod(`deleteRoute`);
256-
it('error informatively when name not found', () => {
254+
describe('removeRoute', () => {
255+
testChainableRoutingMethod(`removeRoute`);
256+
it.skip('error informatively when name not found', () => {
257257
fm.route('http://a.com/', 200).route('http://b.com/', 201, 'named');
258-
expect(() => fm.deleteRoute('misnamed')).toThrowError(
258+
expect(() => fm.removeRoute('misnamed')).toThrowError(
259259
'Could not delete route `misnamed` - route with that name does not exist',
260260
);
261261
});
262262
it('deletes a route', async () => {
263263
fm.route('http://a.com/', 200, 'named').route('http://a.com/', 201);
264-
fm.deleteRoute('named');
264+
fm.removeRoute('named');
265265
const res = await fm.fetchHandler('http://a.com');
266266
expect(res.status).toEqual(201);
267267
});

0 commit comments

Comments
 (0)