Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Nov 22, 2021
1 parent bafe97e commit 98f0c19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions tests/pure/web.dom-exception.constructor.js
Expand Up @@ -38,14 +38,14 @@ QUnit.test('DOMException', assert => {
assert.name(DOMException, 'DOMException');

let error = new DOMException({}, 'Foo');
assert.ok(error instanceof DOMException, 'new DOMException({}, "Foo") instanceof DOMException');
assert.true(error instanceof DOMException, 'new DOMException({}, "Foo") instanceof DOMException');
assert.same(error.message, '[object Object]', 'new DOMException({}, "Foo").message');
assert.same(error.name, 'Foo', 'new DOMException({}, "Foo").name');
assert.same(error.code, 0, 'new DOMException({}, "Foo").code');
assert.same(String(error), 'Foo: [object Object]', 'String(new DOMException({}, "Foo"))'); // Safari 10.1 bug
// assert.same(error.constructor, DOMException, 'new DOMException({}, "Foo").constructor');
assert.same(error[Symbol.toStringTag], 'DOMException', 'DOMException.prototype[Symbol.toStringTag]');
if (HAS_STACK) assert.ok('stack' in error, "'stack' in new DOMException()");
if (HAS_STACK) assert.true('stack' in error, "'stack' in new DOMException()");

assert.same(new DOMException().message, '', 'new DOMException().message');
assert.same(new DOMException(undefined).message, '', 'new DOMException(undefined).message');
Expand All @@ -54,14 +54,14 @@ QUnit.test('DOMException', assert => {

for (const name in errors) {
error = new DOMException(42, name);
assert.ok(error instanceof DOMException, `new DOMException({}, "${ name }") instanceof DOMException`);
assert.true(error instanceof DOMException, `new DOMException({}, "${ name }") instanceof DOMException`);
assert.same(error.message, '42', `new DOMException({}, "${ name }").message`);
assert.same(error.name, name, `new DOMException({}, "${ name }").name`);
if (errors[name].m) assert.same(error.code, errors[name].c, `new DOMException({}, "${ name }").code`);
// NodeJS and Deno set codes to deprecated errors
else if (!NODE) assert.same(error.code, 0, `new DOMException({}, "${ name }").code`);
assert.same(String(error), `${ name }: 42`, `String(new DOMException({}, "${ name }"))`); // Safari 10.1 bug
if (HAS_STACK) assert.ok('stack' in error, `'stack' in new DOMException({}, "${ name }")`);
if (HAS_STACK) assert.true('stack' in error, `'stack' in new DOMException({}, "${ name }")`);

assert.same(DOMException[errors[name].s], errors[name].c, `DOMException.${ errors[name].s }`);
assert.same(DOMException.prototype[errors[name].s], errors[name].c, `DOMException.prototype.${ errors[name].s }`);
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/web.dom-exception.constructor.js
Expand Up @@ -37,14 +37,14 @@ QUnit.test('DOMException', assert => {
// assert.looksNative(DOMException); // FF43- bug

let error = new DOMException({}, 'Foo');
assert.ok(error instanceof DOMException, 'new DOMException({}, "Foo") instanceof DOMException');
assert.true(error instanceof DOMException, 'new DOMException({}, "Foo") instanceof DOMException');
assert.same(error.message, '[object Object]', 'new DOMException({}, "Foo").message');
assert.same(error.name, 'Foo', 'new DOMException({}, "Foo").name');
assert.same(error.code, 0, 'new DOMException({}, "Foo").code');
assert.same(String(error), 'Foo: [object Object]', 'String(new DOMException({}, "Foo"))'); // Safari 10.1 bug
assert.same(error.constructor, DOMException, 'new DOMException({}, "Foo").constructor');
assert.same(error[Symbol.toStringTag], 'DOMException', 'DOMException.prototype[Symbol.toStringTag]');
if (HAS_STACK) assert.ok('stack' in error, "'stack' in new DOMException()");
if (HAS_STACK) assert.true('stack' in error, "'stack' in new DOMException()");

assert.same(new DOMException().message, '', 'new DOMException().message');
assert.same(new DOMException(undefined).message, '', 'new DOMException(undefined).message');
Expand All @@ -53,14 +53,14 @@ QUnit.test('DOMException', assert => {

for (const name in errors) {
error = new DOMException(42, name);
assert.ok(error instanceof DOMException, `new DOMException({}, "${ name }") instanceof DOMException`);
assert.true(error instanceof DOMException, `new DOMException({}, "${ name }") instanceof DOMException`);
assert.same(error.message, '42', `new DOMException({}, "${ name }").message`);
assert.same(error.name, name, `new DOMException({}, "${ name }").name`);
if (errors[name].m) assert.same(error.code, errors[name].c, `new DOMException({}, "${ name }").code`);
// NodeJS and Deno set codes to deprecated errors
else if (!NODE) assert.same(error.code, 0, `new DOMException({}, "${ name }").code`);
assert.same(String(error), `${ name }: 42`, `String(new DOMException({}, "${ name }"))`); // Safari 10.1 bug
if (HAS_STACK) assert.ok('stack' in error, `'stack' in new DOMException({}, "${ name }")`);
if (HAS_STACK) assert.true('stack' in error, `'stack' in new DOMException({}, "${ name }")`);

assert.same(DOMException[errors[name].s], errors[name].c, `DOMException.${ errors[name].s }`);
assert.same(DOMException.prototype[errors[name].s], errors[name].c, `DOMException.prototype.${ errors[name].s }`);
Expand Down

0 comments on commit 98f0c19

Please sign in to comment.