test: check custom inspection truncation in assert
The assert module has some truncation logic in a custom inspect function. This was not covered in tests. Add tests to cover it. PR-URL: https://github.com/nodejs/node/pull/28234 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
This commit is contained in:
parent
fc50e6bcc8
commit
e3d5257ec3
@ -413,12 +413,33 @@ assert.throws(() => { throw new Error(); }, (err) => err instanceof Error);
|
|||||||
// Long values should be truncated for display.
|
// Long values should be truncated for display.
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
assert.strictEqual('A'.repeat(1000), '');
|
assert.strictEqual('A'.repeat(1000), '');
|
||||||
}, {
|
}, (err) => {
|
||||||
code: 'ERR_ASSERTION',
|
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||||
message: `${strictEqualMessageStart}+ actual - expected\n\n` +
|
assert.strictEqual(err.message,
|
||||||
`+ '${'A'.repeat(1000)}'\n- ''`
|
`${strictEqualMessageStart}+ actual - expected\n\n` +
|
||||||
|
`+ '${'A'.repeat(1000)}'\n- ''`);
|
||||||
|
assert.strictEqual(err.actual.length, 1000);
|
||||||
|
assert.ok(inspect(err).includes(`actual: '${'A'.repeat(488)}...'`));
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Output that extends beyond 10 lines should also be truncated for display.
|
||||||
|
{
|
||||||
|
const multilineString = 'fhqwhgads\n'.repeat(15);
|
||||||
|
assert.throws(() => {
|
||||||
|
assert.strictEqual(multilineString, '');
|
||||||
|
}, (err) => {
|
||||||
|
assert.strictEqual(err.code, 'ERR_ASSERTION');
|
||||||
|
assert.strictEqual(err.message.split('\n').length, 19);
|
||||||
|
assert.strictEqual(err.actual.split('\n').length, 16);
|
||||||
|
assert.ok(inspect(err).includes(
|
||||||
|
"actual: 'fhqwhgads\\n' +\n" +
|
||||||
|
" 'fhqwhgads\\n' +\n".repeat(9) +
|
||||||
|
" '...'"));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Bad args to AssertionError constructor should throw TypeError.
|
// Bad args to AssertionError constructor should throw TypeError.
|
||||||
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
|
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user