GeezerVison is showing github.com — test: replace assert.throws with expectsError · nodejs/node@1be5e33
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-response-statuscode.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,14 +8,13 @@ const MAX_REQUESTS = 13; | 8 | 8 | let reqNum = 0; | 9 | 9 |
| 10 | 10 | function test(res, header, code) { | 11 | | - const errRegExp = common.expectsError({ | | 11 | + common.expectsError(() => { | | 12 | + res.writeHead(header); | | 13 | + }, { | 12 | 14 | code: 'ERR_HTTP_INVALID_STATUS_CODE', | 13 | 15 | type: RangeError, | 14 | 16 | message: `Invalid status code: ${code}` | 15 | 17 | }); | 16 | | - assert.throws(() => { | 17 | | - res.writeHead(header); | 18 | | - }, errRegExp); | 19 | 18 | } | 20 | 19 |
| 21 | 20 | const server = http.Server(common.mustCall(function(req, res) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-url-format-invalid-input.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,13 +14,14 @@ const throwsObjsAndReportTypes = new Map([ | 14 | 14 | ]); | 15 | 15 |
| 16 | 16 | for (const [urlObject, type] of throwsObjsAndReportTypes) { | 17 | | - const error = common.expectsError({ | | 17 | + common.expectsError(function() { | | 18 | + url.format(urlObject); | | 19 | + }, { | 18 | 20 | code: 'ERR_INVALID_ARG_TYPE', | 19 | 21 | type: TypeError, | 20 | 22 | message: 'The "urlObject" argument must be one of type Object or string. ' + | 21 | 23 | `Received type ${type}` | 22 | 24 | }); | 23 | | - assert.throws(function() { url.format(urlObject); }, error); | 24 | 25 | } | 25 | 26 | assert.strictEqual(url.format(''), ''); | 26 | 27 | assert.strictEqual(url.format({}), ''); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-url-parse-invalid-input.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,12 +16,13 @@ const url = require('url'); | 16 | 16 | [() => {}, 'function'], | 17 | 17 | [Symbol('foo'), 'symbol'] | 18 | 18 | ].forEach(([val, type]) => { | 19 | | - const error = common.expectsError({ | | 19 | + common.expectsError(() => { | | 20 | + url.parse(val); | | 21 | + }, { | 20 | 22 | code: 'ERR_INVALID_ARG_TYPE', | 21 | 23 | type: TypeError, | 22 | 24 | message: `The "url" argument must be of type string. Received type ${type}` | 23 | 25 | }); | 24 | | - assert.throws(() => { url.parse(val); }, error); | 25 | 26 | }); | 26 | 27 |
| 27 | 28 | assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-util-inherits.js +10-11Lines changed: 10 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const common = require('../common'); | 4 | 4 | const assert = require('assert'); | 5 | 5 | const inherits = require('util').inherits; | 6 | | -const errCheck = common.expectsError({ | 7 | | - code: 'ERR_INVALID_ARG_TYPE', | 8 | | - type: TypeError, | 9 | | - message: 'The "superCtor" argument must be of type Function' | 10 | | -}); | 11 | 6 |
| 12 | 7 | // super constructor | 13 | 8 | function A() { | @@ -86,16 +81,20 @@ common.expectsError(function() { | 86 | 81 | code: 'ERR_INVALID_ARG_TYPE', | 87 | 82 | type: TypeError, | 88 | 83 | message: 'The "superCtor.prototype" property must be of type Function' | 89 | | -} | 90 | | -); | 91 | | -assert.throws(function() { | | 84 | +}); | | 85 | + | | 86 | +common.expectsError(function() { | 92 | 87 | inherits(A, null); | 93 | | -}, errCheck); | | 88 | +}, { | | 89 | + code: 'ERR_INVALID_ARG_TYPE', | | 90 | + type: TypeError, | | 91 | + message: 'The "superCtor" argument must be of type Function' | | 92 | +}); | | 93 | + | 94 | 94 | common.expectsError(function() { | 95 | 95 | inherits(null, A); | 96 | 96 | }, { | 97 | 97 | code: 'ERR_INVALID_ARG_TYPE', | 98 | 98 | type: TypeError, | 99 | 99 | message: 'The "ctor" argument must be of type Function' | 100 | | -} | 101 | | -); | | 100 | +}); |
|