This PR coerces the MockedRequest body to be a buffer from a string (or stringified object). This works well ifexpress.json() middleware has been mounted because we need to un-parse the work the middleware performed.
However, that in effect makes the express.json() middleware required, because otherwise we are undoing work that was never done and we end up stringifying the original Uint8Array buffer, which does not work as expected.
This change preserves the original body buffer if no express.json() (or similar) middleware has been mounted, allowing the subsequent req.json() call to work as expected, regardless.
This PR coerces the MockedRequest body to be a buffer from a string (or stringified object). This works well if
express.json()
middleware has been mounted because we need to un-parse the work the middleware performed.However, that in effect makes the
express.json()
middleware required, because otherwise we are undoing work that was never done and we end up stringifying the originalUint8Array
buffer, which does not work as expected.This change preserves the original body buffer if no
express.json()
(or similar) middleware has been mounted, allowing the subsequentreq.json()
call to work as expected, regardless.