|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | import { createFixedResolver } from './route-resolver/resolver-fixed' |
3 | | -import { MatcherPatternPathDynamic } from './route-resolver/matchers/matcher-pattern' |
| 3 | +import { |
| 4 | + MatcherPatternPathDynamic, |
| 5 | + MatcherPatternPathStatic, |
| 6 | +} from './route-resolver/matchers/matcher-pattern' |
| 7 | +import { MatcherPatternQueryParam } from './route-resolver/matchers/matcher-pattern-query' |
4 | 8 | import { defineParamParserRaw } from './route-resolver/matchers/param-parsers' |
5 | 9 | import { mockWarn } from '../tests/vitest-mock-warn' |
6 | 10 |
|
@@ -118,3 +122,30 @@ describe('optional param removal diagnostics', () => { |
118 | 122 | }) |
119 | 123 | }) |
120 | 124 | }) |
| 125 | + |
| 126 | +describe('ignored query param diagnostics', () => { |
| 127 | + const r = createFixedResolver([ |
| 128 | + { |
| 129 | + name: 'list', |
| 130 | + path: new MatcherPatternPathStatic('/'), |
| 131 | + query: [new MatcherPatternQueryParam('page', 'page', 'value')], |
| 132 | + }, |
| 133 | + ]) |
| 134 | + const current = r.resolve('/?page=5') |
| 135 | + |
| 136 | + it('warns when a query value is ignored for a param', () => { |
| 137 | + expect(r.resolve({ query: { page: ['3'] } }, current)).toMatchObject({ |
| 138 | + fullPath: '/?page=5', |
| 139 | + }) |
| 140 | + if (__DEV__) { |
| 141 | + expect('VUE_ROUTER_R0123').toHaveBeenWarnedTimes(1) |
| 142 | + expect('"page"').toHaveBeenWarned() |
| 143 | + } |
| 144 | + }) |
| 145 | + |
| 146 | + it('does not warn when the query value is used', () => { |
| 147 | + r.resolve({ query: { ...current.query, other: ['x'] } }, current) |
| 148 | + r.resolve({ name: 'list', params: {}, query: { page: ['3'] } }) |
| 149 | + expect('VUE_ROUTER_R0123').not.toHaveBeenWarned() |
| 150 | + }) |
| 151 | +}) |
0 commit comments