Msw: There is no warning when using query params in the handler URL

Created on 18 Jun 2020  路  1Comment  路  Source: mswjs/msw

Describe the bug

The following mock will never work since the query strings are removed from the original URL but not from the handler URL:

rest.get("/foo?bar=10", (req, res, ctx) => {
  return res(
    ctx.json({
      foo: "bar",
    })
  );
}),

Environment

  • msw: 0.19.0
  • nodejs: 12.17.0
  • npm: 6.14.4

To Reproduce

Steps to reproduce the behavior:

  1. Add the handler mentioned above
  2. In the app, do a request to /foo?bar=10
  3. Error: the request is not mocked

Expected behavior

There should be an warning explaining why the mock won't work and how to fix the problem

bug

Most helpful comment

Hey, @rafaelalmeidatk! Nice to see you here! Thanks for bringing this in a form of an issue. The usage of query parameters in request handlers URLs should be discouraged and a warning message would help tremendously.

I'll try to plan and do this in the nearest future. Just in case you'd be interested in shipping a pull request with this, I'll always support you in code review to make this change awesome.

>All comments

Hey, @rafaelalmeidatk! Nice to see you here! Thanks for bringing this in a form of an issue. The usage of query parameters in request handlers URLs should be discouraged and a warning message would help tremendously.

I'll try to plan and do this in the nearest future. Just in case you'd be interested in shipping a pull request with this, I'll always support you in code review to make this change awesome.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

veronesecoms picture veronesecoms  路  3Comments

derekr picture derekr  路  3Comments

lukesmurray picture lukesmurray  路  3Comments

baker-travis picture baker-travis  路  3Comments

danielstreit picture danielstreit  路  3Comments