@@ -24,19 +24,14 @@ You can assert the error message is a given string if you provide a
24
24
string as the second parameter.
25
25
26
26
``` 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' );
34
30
```
35
31
36
32
In case of a failing expectation you get the following output:
37
33
38
- ``` js
39
- expect (function () {
34
+ expect(() => {
40
35
throw new Error('The error message!');
41
36
}, 'to throw', 'The error message');
42
37
```
@@ -57,19 +52,14 @@ By providing a regular expression as the second parameter you can
57
52
assert the error message matches the given regular expression.
58
53
59
54
``` 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/ );
67
58
```
68
59
69
60
In case of a failing expectation you get the following output:
70
61
71
- ``` js
72
- expect (function () {
62
+ expect(() => {
73
63
throw new Error('The error message!');
74
64
}, 'to throw', /catastrophic failure/);
75
65
```
@@ -86,13 +76,9 @@ to throw /catastrophic failure/
86
76
That can also just supply an error object to validate against:
87
77
88
78
``` 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' ));
96
82
```
97
83
98
84
In case of a failing expectation you get the following output:
@@ -113,7 +99,7 @@ to throw TypeError('Invalid syntax')
113
99
```
114
100
115
101
``` js
116
- expect (function () {
102
+ expect (() => {
117
103
// Do some work that should not throw
118
104
}, ' not to throw' );
119
105
```
@@ -142,11 +128,8 @@ function willThrow(input) {
142
128
if (input) throw new SyntaxError (' The error message' );
143
129
return input;
144
130
}
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' ));
152
135
```
0 commit comments