Skip to content

Commit

Permalink
Merge pull request #728 from swantzter/fix/array-of-statuses-body
Browse files Browse the repository at this point in the history
Mitigate array-of-statuses' impact on JSON bodies
  • Loading branch information
niftylettuce authored Aug 11, 2021
2 parents cfeae1a + 5a6999a commit 3c46dae
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 3c46dae

Please sign in to comment.