Skip to content

Commit

Permalink
fix: prevented overwriting stickiness of a route
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Feb 4, 2025
1 parent f62e3d6 commit 87f8c9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/fetch-mock/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ export default class Router {
);
}

if ('sticky' in options) {
throw new Error(
`Altering the stickiness of route \`${routeName}\` is not supported`,
);
}

const newConfig = { ...route.config, ...options };
Object.entries(options).forEach(([key, value]) => {
if (value === null) {
Expand Down
9 changes: 9 additions & 0 deletions packages/fetch-mock/src/__tests__/FetchMock/routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ describe('Routing', () => {
'Cannot rename the route `named` as `new name`: renaming routes is not supported',
);
});

it("errors when trying to alter a route's stickiness", () => {
fm.route('http://a.com/', 200, { name: 'named' });
expect(() =>
fm.modifyRoute('named', {
sticky: true,
}),
).toThrow('Altering the stickiness of route `named` is not supported');
});
});
describe('removeRoute', () => {
testChainableMethod(`removeRoute`);
Expand Down

0 comments on commit 87f8c9b

Please sign in to comment.