Skip to content

Commit 5a6999a

Browse files
committedJul 26, 2021
Mitigate array-of-statuses' impact on JSON bodies
fixes a regression in #715 / v6.1.4
1 parent cfeae1a commit 5a6999a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎lib/test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ function wrapAssertFn(assertFn) {
9898
* .expect(200, body)
9999
* .expect('Some body')
100100
* .expect('Some body', fn)
101+
* .expect(['json array body', { key: 'val' }])
101102
* .expect('Content-Type', 'application/json')
102103
* .expect('Content-Type', 'application/json', fn)
103104
* .expect(fn)
@@ -127,7 +128,7 @@ Test.prototype.expect = function(a, b, c) {
127128
}
128129

129130
// multiple statuses
130-
if (Array.isArray(a)) {
131+
if (Array.isArray(a) && a.every(val => typeof val === 'number')) {
131132
this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a)));
132133
return this;
133134
}

‎test/supertest.js

+11
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,17 @@ describe('request(app)', function () {
573573
});
574574
});
575575

576+
it('should support parsed response arrays', function (done) {
577+
const app = express();
578+
app.get('/', function (req, res) {
579+
res.status(200).json(['a', { id: 1 }]);
580+
});
581+
582+
request(app)
583+
.get('/')
584+
.expect(['a', { id: 1 }], done);
585+
});
586+
576587
it('should support regular expressions', function (done) {
577588
const app = express();
578589

0 commit comments

Comments
 (0)
Please sign in to comment.