]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: query params
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 23 Jan 2026 20:00:13 +0000 (21:00 +0100)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Thu, 29 Jan 2026 16:38:08 +0000 (17:38 +0100)
packages/router/src/experimental/route-resolver/matchers/matcher-pattern-query.spec.ts
packages/router/src/unplugin/codegen/generateRouteResolver.spec.ts

index f4c0ce6dccb1975b4edd2cc7ee9334d24eb58476..1602f09b4d8fd3983aa3ca700462e585c0f170c4 100644 (file)
@@ -356,6 +356,19 @@ describe('MatcherPatternQueryParam', () => {
       expect(() => matcher.match({ c: 'invalid' })).toThrow(MatchMiss)
     })
 
+    it('falls back to default on parser error even when required', () => {
+      const matcher = new MatcherPatternQueryParam(
+        'count',
+        'c',
+        'value',
+        PARAM_PARSER_INT,
+        0, // default value
+        true // required
+      )
+      // Invalid value should fallback to default instead of throwing
+      expect(matcher.match({ c: 'invalid' })).toEqual({ count: 0 })
+    })
+
     it('returns empty array for missing optional param with array format', () => {
       const matcher = new MatcherPatternQueryParam(
         'items',
index 9dd51098b1a6c2676e5e4fedbbbbbb427c159c67..55bb1f2503045204d141a2109862a236c655e3d2 100644 (file)
@@ -195,6 +195,20 @@ describe('generateRouteRecordQuery', () => {
     `)
   })
 
+  it('generates query param with required and default', () => {
+    const node = new PrefixTree(DEFAULT_OPTIONS).insert('a', 'a.vue')
+    node.value.setEditOverride('params', {
+      query: { page: { parser: 'int', default: '1', required: true } },
+    })
+    expect(
+      generateRouteRecordQuery({ importsMap, node, paramParsersMap: new Map() })
+    ).toMatchInlineSnapshot(`
+      "query: [
+          new MatcherPatternQueryParam('page', 'page', 'value', PARAM_PARSER_INT, 1, true)
+        ],"
+    `)
+  })
+
   it('generates mixed query params with different configurations', () => {
     const node = new PrefixTree(DEFAULT_OPTIONS).insert('a', 'a.vue')
     node.value.setEditOverride('params', {