Msw: Support more types passed to `context.json` helper

Created on 24 Aug 2020  路  2Comments  路  Source: mswjs/msw

Describe the bug

The json method on context object should support more types than Record<string, any>. Anything that results in a valid JSON.stringify should be supported.

Environment

  • msw: 0.20.5
  • nodejs: 12.16.1
  • npm: 6.13.4

Please also provide your browser version. (N/A)

To Reproduce

Steps to reproduce the behavior:

  1. Create a rest request handler.
  2. Use the context.json method.
  3. Try passing anything other than an object or array.
  4. See the type error.

Expected behavior

I would expect no type error to occur when passing anything that would result in a valid JSON.stringify call.

Screenshots

image

bug

Most helpful comment

Please, would you be interested in issuing a pull request to extend this support?

Definitely! I will work it up now.

All 2 comments

Hey, @wyze! Thank you for suggesting this.

This makes perfect sense, any valid JSON should be accepted as an argument to ctx.json(). Please, would you be interested in issuing a pull request to extend this support? I'd gladly assist on code review and any questions you may have. Let me know.

Please, would you be interested in issuing a pull request to extend this support?

Definitely! I will work it up now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukesmurray picture lukesmurray  路  3Comments

veronesecoms picture veronesecoms  路  3Comments

dashed picture dashed  路  3Comments

otaciliolacerda picture otaciliolacerda  路  3Comments

danielstreit picture danielstreit  路  3Comments