mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
util: add coverage for util.inspect.colors alias setter
Add test to confirm that the setter for aliases in `util.inspect.colors` keeps the alias reference-equal to the target value. Refs: https://coverage.nodejs.org/coverage-5b0308cd823a5110/lib/internal/util/inspect.js.html#L357 Refs: https://codecov.io/gh/nodejs/node/src/5b0308cd823a511098dadf9ddd5a35e3a9dbb424/lib/internal/util/inspect.js#L357 PR-URL: https://github.com/nodejs/node/pull/31743 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
75971009d0
commit
785417aeda
1 file changed
+25
@@ -2702,3 +2702,28 @@ assert.strictEqual(
|
||||
'\x1B[2mdef: \x1B[33m5\x1B[39m\x1B[22m }'
|
||||
);
|
||||
}
|
||||
|
||||
// Test changing util.inspect.colors colors and aliases.
|
||||
{
|
||||
const colors = util.inspect.colors;
|
||||
|
||||
const originalValue = colors.gray;
|
||||
|
||||
// "grey" is reference-equal alias of "gray".
|
||||
assert.strictEqual(colors.grey, colors.gray);
|
||||
|
||||
// Assigninging one should assign the other. This tests that the alias setter
|
||||
// function keeps things reference-equal.
|
||||
colors.gray = [0, 0];
|
||||
assert.deepStrictEqual(colors.gray, [0, 0]);
|
||||
assert.strictEqual(colors.grey, colors.gray);
|
||||
|
||||
colors.grey = [1, 1];
|
||||
assert.deepStrictEqual(colors.grey, [1, 1]);
|
||||
assert.strictEqual(colors.grey, colors.gray);
|
||||
|
||||
// Restore original value to avoid side effects in other tests.
|
||||
colors.gray = originalValue;
|
||||
assert.deepStrictEqual(colors.gray, originalValue);
|
||||
assert.strictEqual(colors.grey, colors.gray);
|
||||
}
|
||||
Reference in new issue
Block a user