Skip to content

Commit 2c70f2d

Browse files
Marsupcjihrig
authored andcommitted
Add documentation to error() (fixes #63)
1 parent 35c0ac7 commit 2c70f2d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

API.md

+18
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ const expect = Code.expect;
179179
expect(new Date()).to.be.a.date();
180180
```
181181

182+
##### `error([type], [message])`
183+
184+
Asserts that the reference value is an error. You can provide optional requirements where:
185+
- `type` - the `instanceof` value of the error.
186+
- `message` a string or regular expression matching the error `message` property. Note that a string
187+
must provide a full match.
188+
189+
```js
190+
const Code = require('code');
191+
const expect = Code.expect;
192+
193+
const err = new Error('Oops an error occured.');
194+
expect(err).to.be.an.error();
195+
expect(err).to.be.an.error(Error);
196+
expect(err).to.be.an.error('Oops an error occured.');
197+
expect(err).to.be.an.error(Error, /occured/);
198+
```
199+
182200
##### `function()`
183201

184202
Asserts that the reference value is a `function`.

0 commit comments

Comments
 (0)