eugef / node-mocks-http

Mock 'http' objects for testing Express,js, Next.js and Koa routing functions
Other
761 stars 135 forks source link

res.send(null) causes TypeError #137

Closed hignatious closed 4 years ago

hignatious commented 7 years ago

Line 149 of lib/mockResponse is checking if (typeof data === 'object') before trying to extract any values out of data, but if you do something like res.status(303).send(null) to send a response without a body, it will bypass this check and cause a TypeError as it tries to extract values out of null. Because typeof null is broken in Javascript and returns 'object', so it passes this check. The TypeError then occurs on line 151 where it is trying to retrieve the statusCode from null, even though the statusCode of the response could have been set with .status().

github-actions[bot] commented 4 years ago

Stale issue message