File tree Expand file tree Collapse file tree 7 files changed +42
-14
lines changed
Expand file tree Collapse file tree 7 files changed +42
-14
lines changed Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
Original file line number Diff line number Diff line change @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call
142142
143143``` js
144144function compileAndroidCode () {
145- throw new Error (' you are using the wrong JDK' );
145+ throw new Error (' you are using the wrong JDK! ' );
146146}
147147
148148test (' compiling android goes as expected' , () => {
149149 expect (() => compileAndroidCode ()).toThrow ();
150150 expect (() => compileAndroidCode ()).toThrow (Error );
151151
152- // You can also use the exact error message or a regexp
152+ // You can also use a string that must be contained in the error message or a regexp
153153 expect (() => compileAndroidCode ()).toThrow (' you are using the wrong JDK' );
154154 expect (() => compileAndroidCode ()).toThrow (/ JDK/ );
155+
156+ // Or you can match an exact error mesage using a regexp like below
157+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK$ / ); // Test fails
158+ expect (() => compileAndroidCode ()).toThrow (/ ^ you are using the wrong JDK!$ / ); // Test pass
155159});
156160```
157161
You can’t perform that action at this time.
0 commit comments