Skip to content

Commit fb685af

Browse files
committed
Show that we can use modern syntax in the documentation
1 parent 28caa56 commit fb685af

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

documentation/assertions/function/to-throw.md

+16-33
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@ You can assert the error message is a given string if you provide a
2424
string as the second parameter.
2525

2626
```js
27-
expect(
28-
function() {
29-
throw new Error('The error message');
30-
},
31-
'to throw',
32-
'The error message'
33-
);
27+
expect(() => {
28+
throw new Error('The error message');
29+
}, 'to throw', 'The error message');
3430
```
3531

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

38-
```js
39-
expect(function () {
34+
expect(() => {
4035
throw new Error('The error message!');
4136
}, 'to throw', 'The error message');
4237
```
@@ -57,19 +52,14 @@ By providing a regular expression as the second parameter you can
5752
assert the error message matches the given regular expression.
5853

5954
```js
60-
expect(
61-
function() {
62-
throw new Error('The error message');
63-
},
64-
'to throw',
65-
/error message/
66-
);
55+
expect(() => {
56+
throw new Error('The error message');
57+
}, 'to throw', /error message/);
6758
```
6859

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

71-
```js
72-
expect(function () {
62+
expect(() => {
7363
throw new Error('The error message!');
7464
}, 'to throw', /catastrophic failure/);
7565
```
@@ -86,13 +76,9 @@ to throw /catastrophic failure/
8676
That can also just supply an error object to validate against:
8777

8878
```js
89-
expect(
90-
function() {
91-
throw new TypeError('Invalid syntax');
92-
},
93-
'to throw',
94-
new TypeError('Invalid syntax')
95-
);
79+
expect(() => {
80+
throw new TypeError('Invalid syntax');
81+
}, 'to throw', new TypeError('Invalid syntax'));
9682
```
9783

9884
In case of a failing expectation you get the following output:
@@ -113,7 +99,7 @@ to throw TypeError('Invalid syntax')
11399
```
114100

115101
```js
116-
expect(function() {
102+
expect(() => {
117103
// Do some work that should not throw
118104
}, 'not to throw');
119105
```
@@ -142,11 +128,8 @@ function willThrow(input) {
142128
if (input) throw new SyntaxError('The error message');
143129
return input;
144130
}
145-
expect(
146-
function() {
147-
willThrow('input.here');
148-
},
149-
'to throw',
150-
new SyntaxError('The error message')
151-
);
131+
132+
expect(() => {
133+
willThrow('input.here');
134+
}, 'to throw', new SyntaxError('The error message'));
152135
```

0 commit comments

Comments
 (0)