diff --git a/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java b/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java index 4c544c3f6f..8615aa3478 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/NullishCoalescingOpTest.java @@ -9,14 +9,7 @@ public class NullishCoalescingOpTest { @Test public void testNullishCoalescingOperatorRequiresES6() { - Utils.runWithAllOptimizationLevels( - cx -> { - Scriptable scope = cx.initStandardObjects(); - assertThrows( - EvaluatorException.class, - () -> cx.evaluateString(scope, "true ?? false", "test.js", 0, null)); - return null; - }); + Utils.assertEvaluatorException_1_8("syntax error (test#1)", "true ?? false"); } @Test @@ -75,16 +68,7 @@ public void testNullishCoalescingDoesNotLeakVariables() { @Test public void testNullishAssignmentRequiresES6() { - Utils.runWithAllOptimizationLevels( - cx -> { - Scriptable scope = cx.initStandardObjects(); - assertThrows( - EvaluatorException.class, - () -> - cx.evaluateString( - scope, "a = true; a ??= false", "test.js", 0, null)); - return null; - }); + Utils.assertEvaluatorException_1_8("syntax error (test#1)", "a = true; a ??= false"); } @Test diff --git a/tests/src/test/java/org/mozilla/javascript/tests/Utils.java b/tests/src/test/java/org/mozilla/javascript/tests/Utils.java index 0e98321506..a05cb047af 100644 --- a/tests/src/test/java/org/mozilla/javascript/tests/Utils.java +++ b/tests/src/test/java/org/mozilla/javascript/tests/Utils.java @@ -227,6 +227,10 @@ private static void assertException( final Class expectedThrowable, final String expectedMessage, String js) { + + // to avoid false positives because we use startsWith() + assertTrue("expectedMessage can't be empty",expectedMessage != null && !expectedMessage.isEmpty()); + Utils.runWithAllOptimizationLevels( cx -> { if (languageVersion > -1) {