Skip to content

Commit

Permalink
fix: feature "new URL()" in the redundant query params warning (#2102)
Browse files Browse the repository at this point in the history
Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
  • Loading branch information
psjostrom and kettanaito committed Mar 21, 2024
1 parent 30bc5ac commit 9af301a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/handlers/HttpHandler.ts
Expand Up @@ -102,7 +102,7 @@ export class HttpHandler extends RequestHandler<
})

devUtils.warn(
`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`,
`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters using "new URL(request.url).searchParams" instead. Learn more: https://mswjs.io/docs/recipes/query-parameters`,
)
}

Expand Down
4 changes: 2 additions & 2 deletions test/browser/rest-api/query-params-warning.test.ts
Expand Up @@ -9,8 +9,8 @@ test('warns when a request handler URL contains query parameters', async ({
await loadExample(require.resolve('./query-params-warning.mocks.ts'))

expect(consoleSpy.get('warning')).toEqual([
`[MSW] Found a redundant usage of query parameters in the request handler URL for "GET /user?name=admin". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`,
`[MSW] Found a redundant usage of query parameters in the request handler URL for "POST /login?id=123&type=auth". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`,
`[MSW] Found a redundant usage of query parameters in the request handler URL for "GET /user?name=admin". Please match against a path instead and access query parameters using \"new URL(request.url).searchParams\" instead. Learn more: https://mswjs.io/docs/recipes/query-parameters`,
`[MSW] Found a redundant usage of query parameters in the request handler URL for "POST /login?id=123&type=auth". Please match against a path instead and access query parameters using \"new URL(request.url).searchParams\" instead. Learn more: https://mswjs.io/docs/recipes/query-parameters`,
])

await fetch('/user?name=admin').then(async (res) => {
Expand Down

0 comments on commit 9af301a

Please sign in to comment.