diff --git a/docs/UsingMatchers.md b/docs/UsingMatchers.md index 8b375525e126..c642b54f1461 100644 --- a/docs/UsingMatchers.md +++ b/docs/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ``` diff --git a/website/versioned_docs/version-25.x/UsingMatchers.md b/website/versioned_docs/version-25.x/UsingMatchers.md index 51634dfaf842..06db29575bf2 100644 --- a/website/versioned_docs/version-25.x/UsingMatchers.md +++ b/website/versioned_docs/version-25.x/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ``` diff --git a/website/versioned_docs/version-26.x/UsingMatchers.md b/website/versioned_docs/version-26.x/UsingMatchers.md index fd9347ae99ca..8ee81fa06f82 100644 --- a/website/versioned_docs/version-26.x/UsingMatchers.md +++ b/website/versioned_docs/version-26.x/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ``` diff --git a/website/versioned_docs/version-27.x/UsingMatchers.md b/website/versioned_docs/version-27.x/UsingMatchers.md index 8b375525e126..c642b54f1461 100644 --- a/website/versioned_docs/version-27.x/UsingMatchers.md +++ b/website/versioned_docs/version-27.x/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ``` diff --git a/website/versioned_docs/version-28.x/UsingMatchers.md b/website/versioned_docs/version-28.x/UsingMatchers.md index 8b375525e126..c642b54f1461 100644 --- a/website/versioned_docs/version-28.x/UsingMatchers.md +++ b/website/versioned_docs/version-28.x/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ``` diff --git a/website/versioned_docs/version-29.0/UsingMatchers.md b/website/versioned_docs/version-29.0/UsingMatchers.md index 8b375525e126..c642b54f1461 100644 --- a/website/versioned_docs/version-29.0/UsingMatchers.md +++ b/website/versioned_docs/version-29.0/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ``` diff --git a/website/versioned_docs/version-29.1/UsingMatchers.md b/website/versioned_docs/version-29.1/UsingMatchers.md index 8b375525e126..c642b54f1461 100644 --- a/website/versioned_docs/version-29.1/UsingMatchers.md +++ b/website/versioned_docs/version-29.1/UsingMatchers.md @@ -142,16 +142,20 @@ If you want to test whether a particular function throws an error when it's call ```js function compileAndroidCode() { - throw new Error('you are using the wrong JDK'); + throw new Error('you are using the wrong JDK!'); } test('compiling android goes as expected', () => { expect(() => compileAndroidCode()).toThrow(); expect(() => compileAndroidCode()).toThrow(Error); - // You can also use the exact error message or a regexp + // You can also use a string that must be contained in the error message or a regexp expect(() => compileAndroidCode()).toThrow('you are using the wrong JDK'); expect(() => compileAndroidCode()).toThrow(/JDK/); + + // Or you can match an exact error mesage using a regexp like below + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK$/); // Test fails + expect(() => compileAndroidCode()).toThrow(/^you are using the wrong JDK!$/); // Test pass }); ```