Skip to content

Commit

Permalink
Merge c2a0d4e into 28caa56
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Jan 6, 2019
2 parents 28caa56 + c2a0d4e commit a2301e9
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions documentation/assertions/function/to-throw.md
Expand Up @@ -24,19 +24,15 @@ You can assert the error message is a given string if you provide a
string as the second parameter.

```js
expect(
function() {
throw new Error('The error message');
},
'to throw',
'The error message'
);
expect(() => {
throw new Error('The error message');
}, 'to throw', 'The error message');
```

In case of a failing expectation you get the following output:

```js
expect(function () {
expect(() => {
throw new Error('The error message!');
}, 'to throw', 'The error message');
```
Expand All @@ -57,19 +53,14 @@ By providing a regular expression as the second parameter you can
assert the error message matches the given regular expression.

```js
expect(
function() {
throw new Error('The error message');
},
'to throw',
/error message/
);
expect(() => {
throw new Error('The error message');
}, 'to throw', /error message/);
```

In case of a failing expectation you get the following output:

```js
expect(function () {
expect(() => {
throw new Error('The error message!');
}, 'to throw', /catastrophic failure/);
```
Expand All @@ -86,13 +77,9 @@ to throw /catastrophic failure/
That can also just supply an error object to validate against:

```js
expect(
function() {
throw new TypeError('Invalid syntax');
},
'to throw',
new TypeError('Invalid syntax')
);
expect(() => {
throw new TypeError('Invalid syntax');
}, 'to throw', new TypeError('Invalid syntax'));
```

In case of a failing expectation you get the following output:
Expand All @@ -113,7 +100,7 @@ to throw TypeError('Invalid syntax')
```

```js
expect(function() {
expect(() => {
// Do some work that should not throw
}, 'not to throw');
```
Expand Down Expand Up @@ -142,11 +129,8 @@ function willThrow(input) {
if (input) throw new SyntaxError('The error message');
return input;
}
expect(
function() {
willThrow('input.here');
},
'to throw',
new SyntaxError('The error message')
);

expect(() => {
willThrow('input.here');
}, 'to throw', new SyntaxError('The error message'));
```

0 comments on commit a2301e9

Please sign in to comment.