@@ -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
39- expect (function () {
35+ expect (() => {
4036 throw new Error (' The error message!' );
4137}, ' to throw' , ' The error message' );
4238```
@@ -57,19 +53,14 @@ 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
71- ``` js
72- expect (function () {
63+ expect(() => {
7364 throw new Error('The error message!');
7465}, 'to throw', /catastrophic failure/);
7566```
@@ -86,13 +77,9 @@ to throw /catastrophic failure/
8677That can also just supply an error object to validate against:
8778
8879``` js
89- expect (
90- function () {
91- throw new TypeError (' Invalid syntax' );
92- },
93- ' to throw' ,
94- new TypeError (' Invalid syntax' )
95- );
80+ expect (() => {
81+ throw new TypeError (' Invalid syntax' );
82+ }, ' to throw' , new TypeError (' Invalid syntax' ));
9683```
9784
9885In case of a failing expectation you get the following output:
@@ -113,7 +100,7 @@ to throw TypeError('Invalid syntax')
113100```
114101
115102``` js
116- expect (function () {
103+ expect (() => {
117104 // Do some work that should not throw
118105}, ' not to throw' );
119106```
@@ -142,11 +129,8 @@ function willThrow(input) {
142129 if (input) throw new SyntaxError (' The error message' );
143130 return input;
144131}
145- expect (
146- function () {
147- willThrow (' input.here' );
148- },
149- ' to throw' ,
150- new SyntaxError (' The error message' )
151- );
132+
133+ expect (() => {
134+ willThrow (' input.here' );
135+ }, ' to throw' , new SyntaxError (' The error message' ));
152136```
0 commit comments