From 8d4cb56d25e6c8789e957e4b34d0d749cfb25a42 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 2 Feb 2017 14:03:14 -0800 Subject: [PATCH] test: simplify WPT.assert_throws() --- test/common.js | 6 ++---- test/parallel/test-whatwg-url-constructor.js | 4 ++-- test/parallel/test-whatwg-url-historical.js | 2 +- test/parallel/test-whatwg-url-searchparams-constructor.js | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/common.js b/test/common.js index 31c1342dca7aeb..33d327306ba46b 100644 --- a/test/common.js +++ b/test/common.js @@ -600,10 +600,8 @@ exports.WPT = { assert_equals: assert.strictEqual, assert_true: (value, message) => assert.strictEqual(value, true, message), assert_false: (value, message) => assert.strictEqual(value, false, message), - assert_throws: (code, func, desc) => { - assert.throws(func, (err) => { - return typeof err === 'object' && 'name' in err && err.name === code.name; - }, desc); + assert_throws: (errType, func, desc) => { + assert.throws(func, (err) => err instanceof errType, desc); }, assert_array_equals: assert.deepStrictEqual, assert_unreached(desc) { diff --git a/test/parallel/test-whatwg-url-constructor.js b/test/parallel/test-whatwg-url-constructor.js index a8a8667fc47021..d70a10f7174118 100644 --- a/test/parallel/test-whatwg-url-constructor.js +++ b/test/parallel/test-whatwg-url-constructor.js @@ -45,7 +45,7 @@ function runURLTests(urltests) { test(function() { if (expected.failure) { - assert_throws(new TypeError(), function() { + assert_throws(TypeError, function() { bURL(expected.input, expected.base) }) return @@ -97,7 +97,7 @@ function runURLSearchParamTests() { 'use strict' var urlString = 'http://example.org' var url = bURL(urlString) - assert_throws(TypeError(), function() { url.searchParams = new URLSearchParams(urlString) }) + assert_throws(TypeError, function() { url.searchParams = new URLSearchParams(urlString) }) }, 'URL.searchParams setter, invalid values') test(function() { diff --git a/test/parallel/test-whatwg-url-historical.js b/test/parallel/test-whatwg-url-historical.js index 452c14fc77a319..f6a7a094355bb0 100644 --- a/test/parallel/test-whatwg-url-historical.js +++ b/test/parallel/test-whatwg-url-historical.js @@ -31,7 +31,7 @@ if (!common.hasIntl) { test(function() { var url = new URL("./foo", "http://www.example.org"); assert_equals(url.href, "http://www.example.org/foo"); - assert_throws(new TypeError(), function() { + assert_throws(TypeError, function() { url.href = "./bar"; }); }, "Setting URL's href attribute and base URLs"); diff --git a/test/parallel/test-whatwg-url-searchparams-constructor.js b/test/parallel/test-whatwg-url-searchparams-constructor.js index d57373e727ac51..d89c979c352df8 100644 --- a/test/parallel/test-whatwg-url-searchparams-constructor.js +++ b/test/parallel/test-whatwg-url-searchparams-constructor.js @@ -149,8 +149,8 @@ test(function() { params = new URLSearchParams([['a', 'b'], ['c', 'd']]); assert_equals(params.get("a"), "b"); assert_equals(params.get("c"), "d"); - assert_throws(new TypeError(), function() { new URLSearchParams([[1]]); }); - assert_throws(new TypeError(), function() { new URLSearchParams([[1,2,3]]); }); + assert_throws(TypeError, function() { new URLSearchParams([[1]]); }); + assert_throws(TypeError, function() { new URLSearchParams([[1,2,3]]); }); }, "Constructor with sequence of sequences of strings"); [