summaryrefslogtreecommitdiff
path: root/test/parallel/test-internal-errors.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-02-22 15:28:29 -0800
committerJames M Snell <jasnell@gmail.com>2017-02-27 12:29:49 -0800
commitc2e838ee13244dd3dbd98ed86ef1966fe7cd90f1 (patch)
treea67427f99b82c7754337c1032f8084cd6349c978 /test/parallel/test-internal-errors.js
parent84c448eafbbf968241bc72b5020081fcc0ebc522 (diff)
downloadandroid-node-v8-c2e838ee13244dd3dbd98ed86ef1966fe7cd90f1.tar.gz
android-node-v8-c2e838ee13244dd3dbd98ed86ef1966fe7cd90f1.tar.bz2
android-node-v8-c2e838ee13244dd3dbd98ed86ef1966fe7cd90f1.zip
test: change common.expectsError() signature
One downside to `common.expectsError()` is that it increases the abstractions people have to learn about in order to work with even simple tests. Whereas before, all they had to know about is `assert.throws()`, now they have to *also* know about `common.expectsError()`. This is very different (IMO) from `common.mustCall()` in that the latter has an intuitively understandable name, accepts arguments as one would expect, and (in most cases) doesn't actually require reading documentation or code to figure out what it's doing. With `common.expectsError()`, there's a fair bit of magic. Like, it's not obvious what the first argument would be. Or the second. Or the third. You just have to know. This PR changes the arguments accepted by `common.expectsError()` to a single settings object. Someone coming across this has a hope of understanding what's going on without reading source or docs: ```js const validatorFunction = common.expectsError({code: 'ELOOP', type: Error, message: 'foo'}); ``` This, by comparison, is harder to grok: ```js const validatorFunction = common.expectsError('ELOOP', Error, 'foo'); ``` And this is especially wat-inducing: ```js common.expectsError(undefined, undefined, 'looped doodad found'); ``` It's likely that only people who work with tests frequently can be expected to remember the three arguments and their order. By comparison, remembering that the error code is `code` and the message is `message` might be manageable. PR-URL: https://github.com/nodejs/node/pull/11512 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/parallel/test-internal-errors.js')
-rw-r--r--test/parallel/test-internal-errors.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/test/parallel/test-internal-errors.js b/test/parallel/test-internal-errors.js
index 526e6befaf..354209fbad 100644
--- a/test/parallel/test-internal-errors.js
+++ b/test/parallel/test-internal-errors.js
@@ -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/);