]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: allow no parser
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 20 Aug 2025 11:38:56 +0000 (13:38 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 20 Aug 2025 11:38:56 +0000 (13:38 +0200)
packages/router/src/experimental/route-resolver/matchers/matcher-pattern-query.spec.ts
packages/router/src/experimental/route-resolver/matchers/matcher-pattern-query.ts

index 9c8b63e7ac6af5923a4fef5e05fe5e9d62a7719a..6293838593868b7ac67f321962f42fb0ecf7ed19 100644 (file)
@@ -401,7 +401,18 @@ describe('MatcherPatternQueryParam', () => {
     })
   })
 
-  describe('defaultValue', () => {
+  it('should work without parser parameter', () => {
+    const matcher = new MatcherPatternQueryParam('test', 'test_param', 'value')
+    // Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
+    expect(matcher.match({ test_param: 'value' })).toEqual({
+      test: 'value',
+    })
+    expect(matcher.build({ test: 'value' })).toEqual({
+      test_param: 'value',
+    })
+  })
+
+  describe('parser fallback', () => {
     describe('match', () => {
       it('should fallback to PARAM_PARSER_DEFAULTS.get when parser.get is undefined', () => {
         const matcher = new MatcherPatternQueryParam(
index 530a1c58d7933cc7107ffc71d27883e7f7241a62..183065173022ea8c3bcc6609fb6a7c1a20d2cbde 100644 (file)
@@ -23,10 +23,7 @@ export class MatcherPatternQueryParam<T, ParamName extends string>
     private paramName: ParamName,
     private queryKey: string,
     private format: 'value' | 'array' | 'both',
-    private parser: ParamParser<T>,
-    // TODO: optional values
-    // private format: 'value' | 'array' | 'both' = 'both',
-    // private parser: ParamParser<T> = PATH_PARAM_DEFAULT_PARSER,
+    private parser: ParamParser<T> = {},
     private defaultValue?: (() => T) | T
   ) {}