Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: change common.expectsError() signature #11512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,18 @@ Platform normalizes the `dd` command

Check if there is more than 1gb of total memory.

### expectsError(code[, type[, message]])
* `code` [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
expected error must have this value for its `code` property
* `type` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
expected error must be an instance of `type`
* `message` [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
or [<RegExp>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
if a string is provided for `message`, expected error must have it for its
`message` property; if a regular expression is provided for `message`, the
regular expression must match the `message` property of the expected error
### expectsError(settings)
* `settings` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
with the following optional properties:
* `code` [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
expected error must have this value for its `code` property
* `type` [<Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
expected error must be an instance of `type`
* `message` [<String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
or [<RegExp>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
if a string is provided for `message`, expected error must have it for its
`message` property; if a regular expression is provided for `message`, the
regular expression must match the `message` property of the expected error

* return function suitable for use as a validation function passed as the second
argument to `assert.throws()`
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ exports.WPT = {
};

// Useful for testing expected internal/error objects
exports.expectsError = function expectsError(code, type, message) {
exports.expectsError = function expectsError({code, type, message}) {
return function(error) {
assert.strictEqual(error.code, code);
if (type !== undefined)
Expand Down
7 changes: 2 additions & 5 deletions test/parallel/test-debug-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const debug = require('_debug_agent');

assert.throws(
() => { debug.start(); },
common.expectsError(
undefined,
assert.AssertionError,
'Debugger agent running without bindings!'
)
common.expectsError({ type: assert.AssertionError,
message: 'Debugger agent running without bindings!' })
);
3 changes: 2 additions & 1 deletion test/parallel/test-http-request-invalid-method-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const http = require('http');

assert.throws(
() => { http.request({method: '\0'}); },
common.expectsError(undefined, TypeError, 'Method must be a valid HTTP token')
common.expectsError({ type: TypeError,
message: 'Method must be a valid HTTP token' })
);
16 changes: 10 additions & 6 deletions test/parallel/test-internal-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,39 @@ assert.throws(
assert.doesNotThrow(() => {
assert.throws(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, common.expectsError('TEST_ERROR_1'));
}, common.expectsError({ code: 'TEST_ERROR_1' }));
});

assert.doesNotThrow(() => {
assert.throws(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, common.expectsError('TEST_ERROR_1', TypeError, /^Error for testing/));
}, common.expectsError({ code: 'TEST_ERROR_1',
type: TypeError,
message: /^Error for testing/ }));
});

assert.doesNotThrow(() => {
assert.throws(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, common.expectsError('TEST_ERROR_1', TypeError));
}, common.expectsError({ code: 'TEST_ERROR_1', type: TypeError }));
});

assert.doesNotThrow(() => {
assert.throws(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, common.expectsError('TEST_ERROR_1', Error));
}, common.expectsError({ code: 'TEST_ERROR_1', type: Error }));
});

assert.throws(() => {
assert.throws(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, common.expectsError('TEST_ERROR_1', RangeError));
}, common.expectsError({ code: 'TEST_ERROR_1', type: RangeError }));
}, /^AssertionError: .+ is not the expected type \S/);

assert.throws(() => {
assert.throws(() => {
throw new errors.TypeError('TEST_ERROR_1', 'a');
}, common.expectsError('TEST_ERROR_1', TypeError, /^Error for testing 2/));
}, common.expectsError({ code: 'TEST_ERROR_1',
type: TypeError,
message: /^Error for testing 2/ }));
}, /AssertionError: .+ does not match \S/);
2 changes: 1 addition & 1 deletion test/parallel/test-require-invalid-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ const assert = require('assert');

// Should be an invalid package path.
assert.throws(() => require('package.json'),
common.expectsError('MODULE_NOT_FOUND')
common.expectsError({ code: 'MODULE_NOT_FOUND' })
);