Skip to content

Commit 9e211ef

Browse files
bartlomiejuclaude
andcommitted
test: verify first-registered-wins behavior on duplicate routes
The router changed from accumulating handlers (T[]) to storing a single handler (T | null) with first-registration priority. Add tests to document this behavior: duplicate registrations for the same method + pattern preserve the first handler, while different methods on the same pattern work independently. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f38d6eb commit 9e211ef

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

packages/fresh/src/router_test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,30 @@ Deno.test("mergePath", () => {
174174
expect(mergePath("/foo", "*", true)).toEqual("/foo");
175175
expect(mergePath("/foo", "/*", true)).toEqual("/foo/*");
176176
});
177+
178+
Deno.test("UrlPatternRouter - first registered route wins on duplicate", () => {
179+
const router = new UrlPatternRouter<() => string>();
180+
const first = () => "first";
181+
const second = () => "second";
182+
183+
router.add("GET", "/foo", first);
184+
router.add("GET", "/foo", second);
185+
186+
const res = router.match("GET", new URL("/foo", "http://localhost"));
187+
expect(res.item).toBe(first);
188+
});
189+
190+
Deno.test("UrlPatternRouter - duplicate registration different methods", () => {
191+
const router = new UrlPatternRouter<() => string>();
192+
const getHandler = () => "get";
193+
const postHandler = () => "post";
194+
195+
router.add("GET", "/foo", getHandler);
196+
router.add("POST", "/foo", postHandler);
197+
198+
const getRes = router.match("GET", new URL("/foo", "http://localhost"));
199+
expect(getRes.item).toBe(getHandler);
200+
201+
const postRes = router.match("POST", new URL("/foo", "http://localhost"));
202+
expect(postRes.item).toBe(postHandler);
203+
});

0 commit comments

Comments
 (0)