Skip to content

Commit

Permalink
fix tests: remove unnecessary assert doesNotThrow and api calls (#1170)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
BridgeAR authored and jonathanong committed Apr 10, 2018
1 parent 8c17517 commit 13086d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 4 additions & 3 deletions test/request/whatwg-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});

Expand Down
10 changes: 4 additions & 6 deletions test/response/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ describe('res.status=', () => {
});

it('should not throw', () => {
assert.doesNotThrow(() => {
response().status = 403;
});
response().status = 403;
});
});

describe('and invalid', () => {
it('should throw', () => {
assert.throws(() => {
response().status = 999;
}, 'invalid status code: 999');
}, /invalid status code: 999/);
});
});

Expand All @@ -41,7 +39,7 @@ describe('res.status=', () => {
});

it('should not throw', () => {
assert.doesNotThrow(() => response().status = 700);
response().status = 700;
});
});

Expand All @@ -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/);
});
});

Expand Down

0 comments on commit 13086d2

Please sign in to comment.