assert: make actual and expected getters

The `actual` and `expected` properties on an instance of
`AssertionError` is now a getter to prevent inspecting these when
inspecting the error. These values will be visible in the error
message and showing them otherwise would decrease the readability
of the error.

PR-URL: https://github.com/nodejs/node/pull/25250
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater committed 2019-01-10 03:26:50 +01:00
1 parent 81b25eac21
commit dfaa61fa18
2 files changed
+19

No files matched your search

+11
View File
@@ -1139,3 +1139,14 @@ assert.throws(
'{\n a: true\n}\n'
}
);
{
let threw = false;
try {
assert.deepStrictEqual(Array(100).fill(1), 'foobar');
} catch (err) {
threw = true;
assert(/actual: \[Array],\n expected: 'foobar',/.test(inspect(err)));
}
assert(threw);
}