Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Sep 16, 2017
1 parent bb37cc5 commit 50faff7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
34 changes: 33 additions & 1 deletion API.md
@@ -1,5 +1,5 @@
<!-- version -->
# 4.0.0 API Reference
# 5.0.0 API Reference
<!-- versionstop -->

<!-- toc -->
Expand Down Expand Up @@ -44,6 +44,7 @@
- [`match(regex)`](#matchregex)
- [`satisfy(validator)`](#satisfyvalidator)
- [`throw([type], [message])`](#throwtype-message)
- [`await reject([type], [message])`](#away-rejecttype-message)
- [`fail(message)`](#failmessage)
- [`count()`](#count)
- [`incomplete()`](#incomplete)
Expand Down Expand Up @@ -639,6 +640,37 @@ const throws = function () {
expect(throws).to.throw(CustomError, 'Oh no!');
```

#### `await reject([type], [message])`

Aliases: `throws`

Asserts that the `Promise` reference value rejects with an exception when called. The provided reference
promise is resolved using an `await` statement within a `try`-`catch` block and any error throws is caught
and compared to the provided optional requirements where:
- `type` - the `instanceof` value of the rejected object.
- `message` a string or regular expression matching the rejected error `message` property. Note that a string
must provide a full match.

```js
const NodeUtil = require('util');
const Code = require('code');
const expect = Code.expect;

const CustomError = function (message) {

Error.call(this, message);
};

NodeUtil.inherit(CustomError, Error)

const rejects = function () {

new Promise((resolve, reject) => reject(new CustomError('Oh no!')));
};

await expect(rejects()).to.reject(CustomError, 'Oh no!');
```

### `fail(message)`

Make the test fail with `message`.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2014-2016, Project contributors
Copyright (c) 2014-2017, Project contributors
Copyright (c) 2014, Walmart
Copyright (c) 2011-2014 Jake Luer
All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "code",
"description": "assertion library",
"version": "4.1.0",
"version": "5.0.0",
"repository": "git://github.com/hapijs/code",
"main": "lib/index.js",
"keywords": [
Expand Down

0 comments on commit 50faff7

Please sign in to comment.