Skip to content

Commit

Permalink
test: 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lamweili committed Oct 3, 2022
1 parent 1c8930d commit 8bf4c14
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/supertest.js
Expand Up @@ -1269,7 +1269,7 @@ describe('request.get(url).query(vals) works as expected', function () {
});
});

it('handles unknown errors', function (done) {
it('handles unknown errors (err without res)', function (done) {
const app = express();

nock.disableNetConnect();
Expand All @@ -1285,6 +1285,8 @@ describe('request.get(url).query(vals) works as expected', function () {
// https://github.com/visionmedia/supertest/issues/352
.expect(200)
.end(function (err, res) {
should.exist(err);
should.not.exist(res);
err.should.be.an.instanceof(Error);
err.message.should.match(/Nock: Disallowed net connect/);
shouldIncludeStackWithThisFile(err);
Expand All @@ -1294,6 +1296,35 @@ describe('request.get(url).query(vals) works as expected', function () {
nock.restore();
});

// this scenario should never happen
// there shouldn't be any res if there is an err
// meant for test coverage for lib/test.js#169
// https://github.com/visionmedia/supertest/blob/5543d674cf9aa4547927ba6010d31d9474950dec/lib/test.js#L169
it('handles unknown errors (err with res)', function (done) {
const app = express();

app.get('/', function (req, res) {
res.status(200).send('OK');
});

const resError = new Error();
resError.status = 400;

const serverRes = { status: 200 };

request(app)
.get('/')
// private api
.assert(resError, serverRes, function (err, res) {
should.exist(err);
should.exist(res);
err.should.equal(resError);
res.should.equal(serverRes);
// close the server explicitly (as we are not using expect/end/then)
this.end(done);
});
});

it('should assert using promises', function (done) {
const app = express();

Expand Down

0 comments on commit 8bf4c14

Please sign in to comment.