Skip to content

Commit 666c67e

Browse files
committed
test: simplify date inspection tests
The code duplicated a lot of logic that was already abstracted. Use the abstraction instead to remove code overhead. PR-URL: #26922 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
1 parent e1e9f1e commit 666c67e

File tree

1 file changed

+3
-45
lines changed

1 file changed

+3
-45
lines changed

test/parallel/test-util-inspect.js

+3-45
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,9 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
18151815
[RegExp, ['foobar', 'g'], '/foobar/g'],
18161816
[WeakSet, [[{}]], '{ <items unknown> }'],
18171817
[WeakMap, [[[{}, {}]]], '{ <items unknown> }'],
1818-
[BigInt64Array, [10], '[ 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n ]']
1818+
[BigInt64Array, [10], '[ 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n ]'],
1819+
[Date, ['Sun, 14 Feb 2010 11:48:40 GMT'], '2010-02-14T11:48:40.000Z'],
1820+
[Date, ['invalid_date'], 'Invalid Date']
18191821
].forEach(([base, input, rawExpected]) => {
18201822
class Foo extends base {}
18211823
const value = new Foo(...input);
@@ -1841,50 +1843,6 @@ assert.strictEqual(util.inspect('"\'${a}'), "'\"\\'${a}'");
18411843
assert(/\[Symbol\(foo\)]: 'yeah'/.test(res), res);
18421844
});
18431845

1844-
// Date null prototype checks
1845-
{
1846-
class CustomDate extends Date {
1847-
}
1848-
1849-
const date = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT');
1850-
assert.strictEqual(util.inspect(date), 'CustomDate 2010-02-14T11:48:40.000Z');
1851-
1852-
// add properties
1853-
date.foo = 'bar';
1854-
assert.strictEqual(util.inspect(date),
1855-
'{ CustomDate 2010-02-14T11:48:40.000Z foo: \'bar\' }');
1856-
1857-
// Check for null prototype
1858-
Object.setPrototypeOf(date, null);
1859-
assert.strictEqual(util.inspect(date),
1860-
'{ [Date: null prototype] 2010-02-14T11:48:40.000Z' +
1861-
' foo: \'bar\' }');
1862-
1863-
const anotherDate = new CustomDate('Sun, 14 Feb 2010 11:48:40 GMT');
1864-
Object.setPrototypeOf(anotherDate, null);
1865-
assert.strictEqual(util.inspect(anotherDate),
1866-
'[Date: null prototype] 2010-02-14T11:48:40.000Z');
1867-
}
1868-
1869-
// Check for invalid dates and null prototype
1870-
{
1871-
class CustomDate extends Date {
1872-
}
1873-
1874-
const date = new CustomDate('invalid_date');
1875-
assert.strictEqual(util.inspect(date), 'CustomDate Invalid Date');
1876-
1877-
// add properties
1878-
date.foo = 'bar';
1879-
assert.strictEqual(util.inspect(date),
1880-
'{ CustomDate Invalid Date foo: \'bar\' }');
1881-
1882-
// Check for null prototype
1883-
Object.setPrototypeOf(date, null);
1884-
assert.strictEqual(util.inspect(date),
1885-
'{ [Date: null prototype] Invalid Date foo: \'bar\' }');
1886-
}
1887-
18881846
assert.strictEqual(inspect(1n), '1n');
18891847
assert.strictEqual(inspect(Object(-1n)), '[BigInt: -1n]');
18901848
assert.strictEqual(inspect(Object(13n)), '[BigInt: 13n]');

0 commit comments

Comments
 (0)