Skip to content

Commit

Permalink
Mitigate array-of-statuses' impact on JSON bodies
Browse files Browse the repository at this point in the history
fixes a regression in #715 / v6.1.4
  • Loading branch information
swantzter committed Jul 26, 2021
1 parent cfeae1a commit 5a6999a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/test.js
Expand Up @@ -98,6 +98,7 @@ function wrapAssertFn(assertFn) {
* .expect(200, body)
* .expect('Some body')
* .expect('Some body', fn)
* .expect(['json array body', { key: 'val' }])
* .expect('Content-Type', 'application/json')
* .expect('Content-Type', 'application/json', fn)
* .expect(fn)
Expand Down Expand Up @@ -127,7 +128,7 @@ Test.prototype.expect = function(a, b, c) {
}

// multiple statuses
if (Array.isArray(a)) {
if (Array.isArray(a) && a.every(val => typeof val === 'number')) {
this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a)));
return this;
}
Expand Down
11 changes: 11 additions & 0 deletions test/supertest.js
Expand Up @@ -573,6 +573,17 @@ describe('request(app)', function () {
});
});

it('should support parsed response arrays', function (done) {
const app = express();
app.get('/', function (req, res) {
res.status(200).json(['a', { id: 1 }]);
});

request(app)
.get('/')
.expect(['a', { id: 1 }], done);
});

it('should support regular expressions', function (done) {
const app = express();

Expand Down

0 comments on commit 5a6999a

Please sign in to comment.