|
1 | 1 | <!-- version -->
|
2 |
| -# 4.0.0 API Reference |
| 2 | +# 5.0.0 API Reference |
3 | 3 | <!-- versionstop -->
|
4 | 4 |
|
5 | 5 | <!-- toc -->
|
|
44 | 44 | - [`match(regex)`](#matchregex)
|
45 | 45 | - [`satisfy(validator)`](#satisfyvalidator)
|
46 | 46 | - [`throw([type], [message])`](#throwtype-message)
|
| 47 | + - [`await reject([type], [message])`](#away-rejecttype-message) |
47 | 48 | - [`fail(message)`](#failmessage)
|
48 | 49 | - [`count()`](#count)
|
49 | 50 | - [`incomplete()`](#incomplete)
|
@@ -639,6 +640,37 @@ const throws = function () {
|
639 | 640 | expect(throws).to.throw(CustomError, 'Oh no!');
|
640 | 641 | ```
|
641 | 642 |
|
| 643 | +#### `await reject([type], [message])` |
| 644 | + |
| 645 | +Aliases: `throws` |
| 646 | + |
| 647 | +Asserts that the `Promise` reference value rejects with an exception when called. The provided reference |
| 648 | +promise is resolved using an `await` statement within a `try`-`catch` block and any error throws is caught |
| 649 | +and compared to the provided optional requirements where: |
| 650 | +- `type` - the `instanceof` value of the rejected object. |
| 651 | +- `message` a string or regular expression matching the rejected error `message` property. Note that a string |
| 652 | + must provide a full match. |
| 653 | + |
| 654 | +```js |
| 655 | +const NodeUtil = require('util'); |
| 656 | +const Code = require('code'); |
| 657 | +const expect = Code.expect; |
| 658 | + |
| 659 | +const CustomError = function (message) { |
| 660 | + |
| 661 | + Error.call(this, message); |
| 662 | +}; |
| 663 | + |
| 664 | +NodeUtil.inherit(CustomError, Error) |
| 665 | + |
| 666 | +const rejects = function () { |
| 667 | + |
| 668 | + new Promise((resolve, reject) => reject(new CustomError('Oh no!'))); |
| 669 | +}; |
| 670 | + |
| 671 | +await expect(rejects()).to.reject(CustomError, 'Oh no!'); |
| 672 | +``` |
| 673 | + |
642 | 674 | ### `fail(message)`
|
643 | 675 |
|
644 | 676 | Make the test fail with `message`.
|
|
0 commit comments