Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 2, 2021
1 parent fadb55d commit 0a8f64b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions tests/pure/es.aggregate-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ QUnit.test('AggregateError', assert => {
assert.throws(() => AggregateError([1], Symbol()), 'throws on symbol as a message');
assert.same(toString(AggregateError([1])), '[object Error]', 'Object#toString');

assert.ok(AggregateError([1], 1) instanceof AggregateError, 'no cause, without new');
assert.ok(new AggregateError([1], 1) instanceof AggregateError, 'no cause, with new');
assert.true(AggregateError([1], 1) instanceof AggregateError, 'no cause, without new');
assert.true(new AggregateError([1], 1) instanceof AggregateError, 'no cause, with new');

assert.ok(AggregateError([1], 1, {}) instanceof AggregateError, 'with options, without new');
assert.ok(new AggregateError([1], 1, {}) instanceof AggregateError, 'with options, with new');
assert.true(AggregateError([1], 1, {}) instanceof AggregateError, 'with options, without new');
assert.true(new AggregateError([1], 1, {}) instanceof AggregateError, 'with options, with new');

assert.ok(AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, without new');
assert.ok(new AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, with new');
assert.true(AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, without new');
assert.true(new AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, with new');

assert.same(AggregateError([1], 1, { cause: 7 }).cause, 7, 'cause, without new');
assert.same(new AggregateError([1], 1, { cause: 7 }).cause, 7, 'cause, with new');
Expand All @@ -39,12 +39,12 @@ QUnit.test('AggregateError', assert => {
assert.same(error.message, '1', 'instance message');
assert.same(error.cause, 7, 'instance cause');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(error.hasOwnProperty('cause'), 'cause is own');
assert.true(error.hasOwnProperty('cause'), 'cause is own');

error = AggregateError([1]);
assert.deepEqual(error.errors, [1]);
assert.same(error.message, '', 'default instance message');
assert.same(error.cause, undefined, 'default instance cause undefined');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(!error.hasOwnProperty('cause'), 'default instance cause missed');
assert.false(error.hasOwnProperty('cause'), 'default instance cause missed');
});
18 changes: 9 additions & 9 deletions tests/pure/es.error.cause.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ function runErrorTestCase($Error, ERROR_NAME) {

if (PROTO && $Error !== path.Error) {
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(path.Error.isPrototypeOf($Error), 'constructor has `Error` in the prototype chain');
assert.true(path.Error.isPrototypeOf($Error), 'constructor has `Error` in the prototype chain');
}

assert.ok($Error(1) instanceof $Error, 'no cause, without new');
assert.ok(new $Error(1) instanceof $Error, 'no cause, with new');
assert.true($Error(1) instanceof $Error, 'no cause, without new');
assert.true(new $Error(1) instanceof $Error, 'no cause, with new');

assert.ok($Error(1, {}) instanceof $Error, 'with options, without new');
assert.ok(new $Error(1, {}) instanceof $Error, 'with options, with new');
assert.true($Error(1, {}) instanceof $Error, 'with options, without new');
assert.true(new $Error(1, {}) instanceof $Error, 'with options, with new');

assert.ok($Error(1, 'foo') instanceof $Error, 'non-object options, without new');
assert.ok(new $Error(1, 'foo') instanceof $Error, 'non-object options, with new');
assert.true($Error(1, 'foo') instanceof $Error, 'non-object options, without new');
assert.true(new $Error(1, 'foo') instanceof $Error, 'non-object options, with new');

assert.same($Error(1, { cause: 7 }).cause, 7, 'cause, without new');
assert.same(new $Error(1, { cause: 7 }).cause, 7, 'cause, with new');
Expand All @@ -34,13 +34,13 @@ function runErrorTestCase($Error, ERROR_NAME) {
assert.same(error.message, '1', 'instance message');
assert.same(error.cause, 7, 'instance cause');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(error.hasOwnProperty('cause'), 'cause is own');
assert.true(error.hasOwnProperty('cause'), 'cause is own');

error = $Error();
assert.same(error.message, '', 'default instance message');
assert.same(error.cause, undefined, 'default instance cause undefined');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(!error.hasOwnProperty('cause'), 'default instance cause missed');
assert.false(error.hasOwnProperty('cause'), 'default instance cause missed');
});
}

Expand Down
18 changes: 9 additions & 9 deletions tests/tests/es.aggregate-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ QUnit.test('AggregateError', assert => {

assert.same(AggregateError.prototype.constructor, AggregateError, 'prototype constructor');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(!AggregateError.prototype.hasOwnProperty('cause'), 'prototype hasn`t cause');
assert.false(AggregateError.prototype.hasOwnProperty('cause'), 'prototype hasn`t cause');

assert.ok(AggregateError([1], 1) instanceof AggregateError, 'no cause, without new');
assert.ok(new AggregateError([1], 1) instanceof AggregateError, 'no cause, with new');
assert.true(AggregateError([1], 1) instanceof AggregateError, 'no cause, without new');
assert.true(new AggregateError([1], 1) instanceof AggregateError, 'no cause, with new');

assert.ok(AggregateError([1], 1, {}) instanceof AggregateError, 'with options, without new');
assert.ok(new AggregateError([1], 1, {}) instanceof AggregateError, 'with options, with new');
assert.true(AggregateError([1], 1, {}) instanceof AggregateError, 'with options, without new');
assert.true(new AggregateError([1], 1, {}) instanceof AggregateError, 'with options, with new');

assert.ok(AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, without new');
assert.ok(new AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, with new');
assert.true(AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, without new');
assert.true(new AggregateError([1], 1, 'foo') instanceof AggregateError, 'non-object options, with new');

assert.same(AggregateError([1], 1, { cause: 7 }).cause, 7, 'cause, without new');
assert.same(new AggregateError([1], 1, { cause: 7 }).cause, 7, 'cause, with new');
Expand All @@ -41,12 +41,12 @@ QUnit.test('AggregateError', assert => {
assert.same(error.message, '1', 'instance message');
assert.same(error.cause, 7, 'instance cause');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(error.hasOwnProperty('cause'), 'cause is own');
assert.true(error.hasOwnProperty('cause'), 'cause is own');

error = AggregateError([1]);
assert.deepEqual(error.errors, [1]);
assert.same(error.message, '', 'default instance message');
assert.same(error.cause, undefined, 'default instance cause undefined');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(!error.hasOwnProperty('cause'), 'default instance cause missed');
assert.false(error.hasOwnProperty('cause'), 'default instance cause missed');
});
20 changes: 10 additions & 10 deletions tests/tests/es.error.cause.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ function runErrorTestCase($Error, ERROR_NAME) {

if (PROTO && $Error !== Error) {
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(Error.isPrototypeOf($Error), 'constructor has `Error` in the prototype chain');
assert.true(Error.isPrototypeOf($Error), 'constructor has `Error` in the prototype chain');
}

assert.same($Error.prototype.constructor, $Error, 'prototype constructor');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(!$Error.prototype.hasOwnProperty('cause'), 'prototype hasn`t cause');
assert.false($Error.prototype.hasOwnProperty('cause'), 'prototype hasn`t cause');

assert.ok($Error(1) instanceof $Error, 'no cause, without new');
assert.ok(new $Error(1) instanceof $Error, 'no cause, with new');
assert.true($Error(1) instanceof $Error, 'no cause, without new');
assert.true(new $Error(1) instanceof $Error, 'no cause, with new');

assert.ok($Error(1, {}) instanceof $Error, 'with options, without new');
assert.ok(new $Error(1, {}) instanceof $Error, 'with options, with new');
assert.true($Error(1, {}) instanceof $Error, 'with options, without new');
assert.true(new $Error(1, {}) instanceof $Error, 'with options, with new');

assert.ok($Error(1, 'foo') instanceof $Error, 'non-object options, without new');
assert.ok(new $Error(1, 'foo') instanceof $Error, 'non-object options, with new');
assert.true($Error(1, 'foo') instanceof $Error, 'non-object options, without new');
assert.true(new $Error(1, 'foo') instanceof $Error, 'non-object options, with new');

assert.same($Error(1, { cause: 7 }).cause, 7, 'cause, without new');
assert.same(new $Error(1, { cause: 7 }).cause, 7, 'cause, with new');
Expand All @@ -38,13 +38,13 @@ function runErrorTestCase($Error, ERROR_NAME) {
assert.same(error.message, '1', 'instance message');
assert.same(error.cause, 7, 'instance cause');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(error.hasOwnProperty('cause'), 'cause is own');
assert.true(error.hasOwnProperty('cause'), 'cause is own');

error = $Error();
assert.same(error.message, '', 'default instance message');
assert.same(error.cause, undefined, 'default instance cause undefined');
// eslint-disable-next-line no-prototype-builtins -- safe
assert.ok(!error.hasOwnProperty('cause'), 'default instance cause missed');
assert.false(error.hasOwnProperty('cause'), 'default instance cause missed');
});
}

Expand Down

0 comments on commit 0a8f64b

Please sign in to comment.