Skip to content

Commit 50faff7

Browse files
committedSep 16, 2017
Update docs
1 parent bb37cc5 commit 50faff7

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed
 

‎API.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- version -->
2-
# 4.0.0 API Reference
2+
# 5.0.0 API Reference
33
<!-- versionstop -->
44

55
<!-- toc -->
@@ -44,6 +44,7 @@
4444
- [`match(regex)`](#matchregex)
4545
- [`satisfy(validator)`](#satisfyvalidator)
4646
- [`throw([type], [message])`](#throwtype-message)
47+
- [`await reject([type], [message])`](#away-rejecttype-message)
4748
- [`fail(message)`](#failmessage)
4849
- [`count()`](#count)
4950
- [`incomplete()`](#incomplete)
@@ -639,6 +640,37 @@ const throws = function () {
639640
expect(throws).to.throw(CustomError, 'Oh no!');
640641
```
641642

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+
642674
### `fail(message)`
643675

644676
Make the test fail with `message`.

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014-2016, Project contributors
1+
Copyright (c) 2014-2017, Project contributors
22
Copyright (c) 2014, Walmart
33
Copyright (c) 2011-2014 Jake Luer
44
All rights reserved.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code",
33
"description": "assertion library",
4-
"version": "4.1.0",
4+
"version": "5.0.0",
55
"repository": "git://github.com/hapijs/code",
66
"main": "lib/index.js",
77
"keywords": [

0 commit comments

Comments
 (0)
Please sign in to comment.