From 9af301a7ea593642cc7b6d46f3685cf2ff9f2b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Sj=C3=B6str=C3=B6m?= <37512275+psjostrom@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:27:39 +0100 Subject: [PATCH] fix: feature "new URL()" in the redundant query params warning (#2102) Co-authored-by: Artem Zakharchenko --- src/core/handlers/HttpHandler.ts | 2 +- test/browser/rest-api/query-params-warning.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/handlers/HttpHandler.ts b/src/core/handlers/HttpHandler.ts index c4e7c47e7..fd8510035 100644 --- a/src/core/handlers/HttpHandler.ts +++ b/src/core/handlers/HttpHandler.ts @@ -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`, ) } diff --git a/test/browser/rest-api/query-params-warning.test.ts b/test/browser/rest-api/query-params-warning.test.ts index bc76170f1..d7358a731 100644 --- a/test/browser/rest-api/query-params-warning.test.ts +++ b/test/browser/rest-api/query-params-warning.test.ts @@ -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) => {