From 829d3de8ab20a434a103c5d7ee55911290072776 Mon Sep 17 00:00:00 2001 From: ghermeto Date: Sat, 7 May 2022 21:43:41 -0700 Subject: [PATCH] feat!: make `Response.status()` chainable BREAKING CHANGE: improves compatibility with express @see: https://github.com/expressjs/express/blob/master/lib/response.js#L67-L73 --- lib/response.js | 2 +- test/response.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/response.js b/lib/response.js index 87aced7ad..2e8d219af 100644 --- a/lib/response.js +++ b/lib/response.js @@ -596,7 +596,7 @@ function patch(Response) { assert.number(code, 'code'); this.statusCode = code; - return code; + return this; }; /** diff --git a/test/response.test.js b/test/response.test.js index 373bc2145..dde7d7b63 100644 --- a/test/response.test.js +++ b/test/response.test.js @@ -760,3 +760,15 @@ test('GH-1791: should send NaN as null with application/json', function(t) { t.end(); }); }); + +test('GH-1851: res.status should be chainable', function(t) { + SERVER.get('/418', function(req, res, next) { + res.status(418).json({ teapot: true }); + }); + + CLIENT.get(join(LOCALHOST, '/418'), function(err, _, res, data) { + t.equal(res.statusCode, 418); + t.ok(data.teapot); + t.end(); + }); +});