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: simplify date inspection tests #26922

Closed
wants to merge 1 commit into from
Closed
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
48 changes: 3 additions & 45 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,9 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
[RegExp, ['foobar', 'g'], '/foobar/g'],
[WeakSet, [[{}]], '{ <items unknown> }'],
[WeakMap, [[[{}, {}]]], '{ <items unknown> }'],
[BigInt64Array, [10], '[ 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n ]']
[BigInt64Array, [10], '[ 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n ]'],
[Date, ['Sun, 14 Feb 2010 11:48:40 GMT'], '2010-02-14T11:48:40.000Z'],
[Date, ['invalid_date'], 'Invalid Date']
].forEach(([base, input, rawExpected]) => {
class Foo extends base {}
const value = new Foo(...input);
Expand All @@ -1774,50 +1776,6 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res);
});

// Date null prototype checks
{
class CustomDate extends Date {
}

const date = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT');
assert.strictEqual(util.inspect(date), 'CustomDate 2010-02-14T11:48:40.000Z');

// add properties
date.foo = 'bar';
assert.strictEqual(util.inspect(date),
'{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }');

// Check for null prototype
Object.setPrototypeOf(date, null);
assert.strictEqual(util.inspect(date),
'{ [Date: null prototype] 2010-02-14T11:48:40.000Z' +
' foo: \'bar\' }');

const anotherDate = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT');
Object.setPrototypeOf(anotherDate, null);
assert.strictEqual(util.inspect(anotherDate),
'[Date: null prototype] 2010-02-14T11:48:40.000Z');
}

// Check for invalid dates and null prototype
{
class CustomDate extends Date {
}

const date = new CustomDate('invalid_date');
assert.strictEqual(util.inspect(date), 'CustomDate Invalid Date');

// add properties
date.foo = 'bar';
assert.strictEqual(util.inspect(date),
'{ CustomDate Invalid Date foo: \'bar\' }');

// Check for null prototype
Object.setPrototypeOf(date, null);
assert.strictEqual(util.inspect(date),
'{ [Date: null prototype] Invalid Date foo: \'bar\' }');
}

assert.strictEqual(inspect(1n), '1n');
assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]');
assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]');
Expand Down