eugef / node-mocks-http

Mock 'http' objects for testing Express routing functions
Other
753 stars 133 forks source link

res.json(number) sets status code #182

Closed PtrBld closed 5 years ago

PtrBld commented 5 years ago

I have a express app where I set the status code before calling res.json() like this: res.status(number).json(obj);

The problem now is that my json can be just a number and therefor this library will set the statuscode of the response to the number specified in the json method and the actual json to undefined. I think setting a number as return value in json should be fine...

Since setting the status code in the json method is deprecated in express are there any plans to migrate to the newer version of the function? What is your opinion on this?

eugef commented 5 years ago

I think it is a bug in node-mock-http. Mock for json function doesn't check the length of arguments like express does

https://github.com/howardabrams/node-mocks-http/blob/f4b6b05ada8417e64ac0cf7095f56f2b2f860649/lib/mockResponse.js#L262

https://github.com/expressjs/express/blob/dc538f6e810bd462c98ee7e6aae24c64d4b1da93/lib/response.js#L243

PtrBld commented 5 years ago

Ok I will work on a pull request for that if that is ok for you. Should be a fast fix.