Skip to content

Commit 87f8c9b

Browse files
committed
fix: prevented overwriting stickiness of a route
1 parent f62e3d6 commit 87f8c9b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

packages/fetch-mock/src/Router.ts

+6
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ export default class Router {
406406
);
407407
}
408408

409+
if ('sticky' in options) {
410+
throw new Error(
411+
`Altering the stickiness of route \`${routeName}\` is not supported`,
412+
);
413+
}
414+
409415
const newConfig = { ...route.config, ...options };
410416
Object.entries(options).forEach(([key, value]) => {
411417
if (value === null) {

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

+9
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ describe('Routing', () => {
342342
'Cannot rename the route `named` as `new name`: renaming routes is not supported',
343343
);
344344
});
345+
346+
it("errors when trying to alter a route's stickiness", () => {
347+
fm.route('http://a.com/', 200, { name: 'named' });
348+
expect(() =>
349+
fm.modifyRoute('named', {
350+
sticky: true,
351+
}),
352+
).toThrow('Altering the stickiness of route `named` is not supported');
353+
});
345354
});
346355
describe('removeRoute', () => {
347356
testChainableMethod(`removeRoute`);

0 commit comments

Comments
 (0)