@@ -24,19 +24,15 @@ You can assert the error message is a given string if you provide a
2424string 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
3632In case of a failing expectation you get the following output:
3733
3834``` js#skipPhantom:true
39- expect(function () {
35+ expect(() => {
4036 throw new Error('The error message!');
4137}, 'to throw', 'The error message');
4238```
@@ -57,19 +53,15 @@ By providing a regular expression as the second parameter you can
5753assert the error message matches the given regular expression.
5854
5955``` 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/ );
6759```
6860
6961In case of a failing expectation you get the following output:
7062
7163``` js#skipPhantom:true
72- expect(function () {
64+ expect(() => {
7365 throw new Error('The error message!');
7466}, 'to throw', /catastrophic failure/);
7567```
@@ -87,23 +79,19 @@ You can also provide a function as the second parameter to do
8779arbitrary assertions on the error.
8880
8981``` 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+ });
9987```
10088
10189In case of a failing expectation you get the following output:
10290
10391``` js#skipPhantom:true
104- expect(function () {
92+ expect(() => {
10593 throw new Error('Another error');
106- }, 'to throw', function (e) {
94+ }, 'to throw', (e) => {
10795 expect(e, 'to be a', TypeError);
10896});
10997```
@@ -126,19 +114,15 @@ parameter. That means you could also just supply an error object to
126114validate against:
127115
128116``` 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' ));
136120```
137121
138122In case of a failing expectation you get the following output:
139123
140124``` js#skipPhantom:true
141- expect(function () {
125+ expect(() => {
142126 throw new Error('Another error');
143127}, 'to throw', new TypeError('Invalid syntax'));
144128```
@@ -153,15 +137,15 @@ to throw TypeError('Invalid syntax')
153137```
154138
155139``` js
156- expect (function () {
140+ expect (() => {
157141 // Do some work that should not throw
158142}, ' not to throw' );
159143```
160144
161145In case of a failing expectation you get the following output:
162146
163147``` js#skipPhantom:true
164- expect(function () {
148+ expect(() => {
165149 throw new Error('threw anyway');
166150}, 'not to throw');
167151```
@@ -182,11 +166,8 @@ function willThrow(input) {
182166 if (input) throw new SyntaxError (' The error message' );
183167 return input;
184168}
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' ));
192173```
0 commit comments