Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d949ead

Browse filesBrowse files
Trotttargos
authored andcommitted
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: #28234 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 990feaf commit d949ead
Copy full SHA for d949ead

File tree

Expand file treeCollapse file tree

1 file changed

+25
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-4
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-assert.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert.js
+25-4Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,33 @@ assert.throws(() => { throw new Error(); }, (err) => err instanceof Error);
412412
// Long values should be truncated for display.
413413
assert.throws(() => {
414414
assert.strictEqual('A'.repeat(1000), '');
415-
}, {
416-
code: 'ERR_ASSERTION',
417-
message: `${strictEqualMessageStart}+ actual - expected\n\n` +
418-
`+ '${'A'.repeat(1000)}'\n- ''`
415+
}, (err) => {
416+
assert.strictEqual(err.code, 'ERR_ASSERTION');
417+
assert.strictEqual(err.message,
418+
`${strictEqualMessageStart}+ actual - expected\n\n` +
419+
`+ '${'A'.repeat(1000)}'\n- ''`);
420+
assert.strictEqual(err.actual.length, 1000);
421+
assert.ok(inspect(err).includes(`actual: '${'A'.repeat(488)}...'`));
422+
return true;
419423
});
420424

425+
// Output that extends beyond 10 lines should also be truncated for display.
426+
{
427+
const multilineString = 'fhqwhgads\n'.repeat(15);
428+
assert.throws(() => {
429+
assert.strictEqual(multilineString, '');
430+
}, (err) => {
431+
assert.strictEqual(err.code, 'ERR_ASSERTION');
432+
assert.strictEqual(err.message.split('\n').length, 19);
433+
assert.strictEqual(err.actual.split('\n').length, 16);
434+
assert.ok(inspect(err).includes(
435+
"actual: 'fhqwhgads\\n' +\n" +
436+
" 'fhqwhgads\\n' +\n".repeat(9) +
437+
" '...'"));
438+
return true;
439+
});
440+
}
441+
421442
{
422443
// Bad args to AssertionError constructor should throw TypeError.
423444
const args = [1, true, false, '', null, Infinity, Symbol('test'), undefined];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.