@@ -24,19 +24,14 @@ 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
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
5752assert 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
6960In 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/
8676That 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
9884In 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