GeezerVison is showing github.com — assert: fix .throws operator · nodejs/node@84948cf
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/assert.js +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -643,15 +643,18 @@ function innerThrows(shouldThrow, block, expected, message) { | 643 | 643 | details += ` (${expected.name})`; | 644 | 644 | } | 645 | 645 | details += message ? `: ${message}` : '.'; | 646 | | - fail(actual, expected, `Missing expected exception${details}`, fail); | | 646 | + fail(actual, expected, `Missing expected exception${details}`, 'throws'); | 647 | 647 | } | 648 | 648 | if (expected && expectedException(actual, expected) === false) { | 649 | 649 | throw actual; | 650 | 650 | } | 651 | 651 | } else if (actual !== undefined) { | 652 | 652 | if (!expected || expectedException(actual, expected)) { | 653 | 653 | details = message ? `: ${message}` : '.'; | 654 | | - fail(actual, expected, `Got unwanted exception${details}`, fail); | | 654 | + fail(actual, | | 655 | + expected, | | 656 | + `Got unwanted exception${details}`, | | 657 | + 'doesNotThrow'); | 655 | 658 | } | 656 | 659 | throw actual; | 657 | 660 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert.js +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -463,10 +463,15 @@ assert.throws(() => { assert.ifError(new Error('test error')); }, | 463 | 463 | assert.doesNotThrow(() => { assert.ifError(null); }); | 464 | 464 | assert.doesNotThrow(() => { assert.ifError(); }); | 465 | 465 |
| 466 | | -assert.throws(() => { | 467 | | - assert.doesNotThrow(makeBlock(thrower, Error), 'user message'); | 468 | | -}, /Got unwanted exception: user message/, | 469 | | - 'a.doesNotThrow ignores user message'); | | 466 | +common.expectsError( | | 467 | + () => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'), | | 468 | + { | | 469 | + type: a.AssertionError, | | 470 | + code: 'ERR_ASSERTION', | | 471 | + operator: 'doesNotThrow', | | 472 | + message: 'Got unwanted exception: user message\n[object Object]' | | 473 | + } | | 474 | +); | 470 | 475 |
| 471 | 476 | // make sure that validating using constructor really works | 472 | 477 | { | @@ -525,7 +530,8 @@ a.throws(makeBlock(thrower, TypeError), (err) => { | 525 | 530 | () => { a.throws((noop)); }, | 526 | 531 | common.expectsError({ | 527 | 532 | code: 'ERR_ASSERTION', | 528 | | - message: /^Missing expected exception\.$/ | | 533 | + message: /^Missing expected exception\.$/, | | 534 | + operator: 'throws' | 529 | 535 | })); | 530 | 536 |
| 531 | 537 | assert.throws( | |
|