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: check custom inspection truncation in assert #28234

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
29 changes: 25 additions & 4 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,33 @@ assert.throws(() => { throw new Error(); }, (err) => err instanceof Error);
// Long values should be truncated for display.
assert.throws(() => {
assert.strictEqual('A'.repeat(1000), '');
}, {
code: 'ERR_ASSERTION',
message: `${strictEqualMessageStart}+ actual - expected\n\n` +
`+ '${'A'.repeat(1000)}'\n- ''`
}, (err) => {
assert.strictEqual(err.code, 'ERR_ASSERTION');
assert.strictEqual(err.message,
`${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.
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];
Expand Down