Skip to content

Commit

Permalink
Add on to the mitigation in https://github.com/visionmedia/supertest/…
Browse files Browse the repository at this point in the history
…pull/728/commits to support empty array response body
  • Loading branch information
benjosantony committed Aug 12, 2021
1 parent b735b90 commit ed0f68d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/test.js
Expand Up @@ -128,7 +128,7 @@ Test.prototype.expect = function(a, b, c) {
}

// multiple statuses
if (Array.isArray(a) && a.every(val => typeof val === 'number')) {
if (Array.isArray(a) && a.length > 0 && 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 @@ -584,6 +584,17 @@ describe('request(app)', function () {
.expect(['a', { id: 1 }], done);
});

it('should support empty array responses', function (done) {
const app = express();
app.get('/', function (req, res) {
res.status(200).json([]);
});

request(app)
.get('/')
.expect([], done);
});

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

Expand Down

0 comments on commit ed0f68d

Please sign in to comment.