@@ -24,19 +24,15 @@ 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
34
``` js#skipPhantom:true
39
- expect(function () {
35
+ expect(() => {
40
36
throw new Error('The error message!');
41
37
}, 'to throw', 'The error message');
42
38
```
@@ -57,19 +53,15 @@ By providing a regular expression as the second parameter you can
57
53
assert the error message matches the given regular expression.
58
54
59
55
``` js
60
- expect (
61
- function () {
62
- throw new Error (' The error message' );
63
- },
64
- ' to throw' ,
65
- / error message/
66
- );
56
+ expect (() => {
57
+ throw new Error (' The error message' );
58
+ }, ' to throw' , / error message/ );
67
59
```
68
60
69
61
In case of a failing expectation you get the following output:
70
62
71
63
``` js#skipPhantom:true
72
- expect(function () {
64
+ expect(() => {
73
65
throw new Error('The error message!');
74
66
}, 'to throw', /catastrophic failure/);
75
67
```
@@ -87,23 +79,19 @@ You can also provide a function as the second parameter to do
87
79
arbitrary assertions on the error.
88
80
89
81
``` js
90
- expect (
91
- function () {
92
- this .foo .bar ();
93
- },
94
- ' to throw' ,
95
- function (e ) {
96
- expect (e, ' to be a' , TypeError );
97
- }
98
- );
82
+ expect (() => {
83
+ this .foo .bar ();
84
+ }, ' to throw' , (e ) => {
85
+ expect (e, ' to be a' , TypeError );
86
+ });
99
87
```
100
88
101
89
In case of a failing expectation you get the following output:
102
90
103
91
``` js#skipPhantom:true
104
- expect(function () {
92
+ expect(() => {
105
93
throw new Error('Another error');
106
- }, 'to throw', function (e) {
94
+ }, 'to throw', (e) => {
107
95
expect(e, 'to be a', TypeError);
108
96
});
109
97
```
@@ -126,19 +114,15 @@ parameter. That means you could also just supply an error object to
126
114
validate against:
127
115
128
116
``` js
129
- expect (
130
- function () {
131
- throw new TypeError (' Invalid syntax' );
132
- },
133
- ' to throw' ,
134
- new TypeError (' Invalid syntax' )
135
- );
117
+ expect (() => {
118
+ throw new TypeError (' Invalid syntax' );
119
+ }, ' to throw' , new TypeError (' Invalid syntax' ));
136
120
```
137
121
138
122
In case of a failing expectation you get the following output:
139
123
140
124
``` js#skipPhantom:true
141
- expect(function () {
125
+ expect(() => {
142
126
throw new Error('Another error');
143
127
}, 'to throw', new TypeError('Invalid syntax'));
144
128
```
@@ -153,15 +137,15 @@ to throw TypeError('Invalid syntax')
153
137
```
154
138
155
139
``` js
156
- expect (function () {
140
+ expect (() => {
157
141
// Do some work that should not throw
158
142
}, ' not to throw' );
159
143
```
160
144
161
145
In case of a failing expectation you get the following output:
162
146
163
147
``` js#skipPhantom:true
164
- expect(function () {
148
+ expect(() => {
165
149
throw new Error('threw anyway');
166
150
}, 'not to throw');
167
151
```
@@ -182,11 +166,8 @@ function willThrow(input) {
182
166
if (input) throw new SyntaxError (' The error message' );
183
167
return input;
184
168
}
185
- expect (
186
- function () {
187
- willThrow (' input.here' );
188
- },
189
- ' to throw' ,
190
- new SyntaxError (' The error message' )
191
- );
169
+
170
+ expect (() => {
171
+ willThrow (' input.here' );
172
+ }, ' to throw' , new SyntaxError (' The error message' ));
192
173
```
0 commit comments