fix tests: remove unnecessary assert doesNotThrow and api calls (#1170)

* tests: fix error verification

So far the error message was not tested at all. This change makes
sure the error will actually be tested for.

* tests: remove unnecessary api calls

`assert.doesNotThrow` does not provide any benefit since it will
only catch errors and then rethrow in case of an error.
master
Ruben Bridgewater 2018-04-10 04:36:52 +02:00 committed by jongleberry
parent 8c17517809
commit 13086d2fcd
2 changed files with 8 additions and 9 deletions

View File

@ -7,14 +7,15 @@ const assert = require('assert');
describe('req.URL', () => {
describe('should not throw when', () => {
it('host is void', () => {
const req = request();
assert.doesNotThrow(() => req.URL, TypeError);
// Accessing the URL should not throw.
request().URL;
});
it('header.host is invalid', () => {
const req = request();
req.header.host = 'invalid host';
assert.doesNotThrow(() => req.URL, TypeError);
// Accessing the URL should not throw.
req.URL;
});
});

View File

@ -17,9 +17,7 @@ describe('res.status=', () => {
});
it('should not throw', () => {
assert.doesNotThrow(() => {
response().status = 403;
});
response().status = 403;
});
});
@ -27,7 +25,7 @@ describe('res.status=', () => {
it('should throw', () => {
assert.throws(() => {
response().status = 999;
}, 'invalid status code: 999');
}, /invalid status code: 999/);
});
});
@ -41,7 +39,7 @@ describe('res.status=', () => {
});
it('should not throw', () => {
assert.doesNotThrow(() => response().status = 700);
response().status = 700;
});
});
@ -59,7 +57,7 @@ describe('res.status=', () => {
describe('when a status string', () => {
it('should throw', () => {
assert.throws(() => response().status = 'forbidden', 'status code must be a number');
assert.throws(() => response().status = 'forbidden', /status code must be a number/);
});
});