diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index c9989d1c..d7f66c2b 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -6204,8 +6204,10 @@ function isTestCall(n, parent) { return false; } return ( - (isFunctionOrArrowExpression(n.arguments[1]) && - n.arguments[1].params.length <= 1) || + (n.arguments.length === 2 + ? isFunctionOrArrowExpression(n.arguments[1]) + : isFunctionOrArrowExpressionWithBody(n.arguments[1]) && + n.arguments[1].params.length <= 1) || isAngularTestWrapper(n.arguments[1]) ); } @@ -6249,6 +6251,14 @@ function isFunctionOrArrowExpression(node) { ); } +function isFunctionOrArrowExpressionWithBody(node) { + return ( + node.type === "FunctionExpression" || + (node.type === "ArrowFunctionExpression" && + node.body.type === "BlockStatement") + ); +} + function isUnitTestSetUp(n) { const unitTestSetUpRe = /^(before|after)(Each|All)$/; return ( diff --git a/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap b/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap index ceecad11..5b9d7199 100644 --- a/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap +++ b/tests/test_declarations/__snapshots__/jsfmt.spec.js.snap @@ -167,6 +167,8 @@ it("does something really long and complicated so I have to write a very long na // code })); +it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS)); + /* * isTestCall(parent) should only be called when parent exists * and parent.type is CallExpression. This test makes sure that @@ -190,6 +192,9 @@ it("does something really long and complicated so I have to write a very long na // code })); +it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => + new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS())); + /* * isTestCall(parent) should only be called when parent exists * and parent.type is CallExpression. This test makes sure that @@ -218,6 +223,8 @@ it("does something really long and complicated so I have to write a very long na // code })); +it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS)); + /* * isTestCall(parent) should only be called when parent exists * and parent.type is CallExpression. This test makes sure that @@ -241,6 +248,9 @@ it("does something really long and complicated so I have to write a very long na // code })); +it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => + new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS())); + /* * isTestCall(parent) should only be called when parent exists * and parent.type is CallExpression. This test makes sure that @@ -692,6 +702,17 @@ it(\`handles it("does something quick", () => { console.log("hello!") }, 1000000000) + +it( + 'succeeds if the test finishes in time', + () => new Promise(resolve => setTimeout(resolve, 10)) +); + +it( + 'succeeds if the test finishes in time', + () => new Promise(resolve => setTimeout(resolve, 10)), + 250 +); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Shouldn't break @@ -826,6 +847,15 @@ it("does something quick", () => { console.log("hello!"); }, 1000000000); +it("succeeds if the test finishes in time", () => + new Promise(resolve => setTimeout(resolve, 10))); + +it( + "succeeds if the test finishes in time", + () => new Promise(resolve => setTimeout(resolve, 10)), + 250 +); + `; exports[`test_declarations.js - flow-verify 2`] = ` @@ -948,6 +978,17 @@ it(\`handles it("does something quick", () => { console.log("hello!") }, 1000000000) + +it( + 'succeeds if the test finishes in time', + () => new Promise(resolve => setTimeout(resolve, 10)) +); + +it( + 'succeeds if the test finishes in time', + () => new Promise(resolve => setTimeout(resolve, 10)), + 250 +); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Shouldn't break @@ -1082,4 +1123,13 @@ it("does something quick", () => { console.log("hello!"); }, 1000000000); +it("succeeds if the test finishes in time", () => + new Promise((resolve) => setTimeout(resolve, 10))); + +it( + "succeeds if the test finishes in time", + () => new Promise((resolve) => setTimeout(resolve, 10)), + 250 +); + `; diff --git a/tests/test_declarations/angular_fakeAsync.js b/tests/test_declarations/angular_fakeAsync.js index d4f4f01e..2deade91 100644 --- a/tests/test_declarations/angular_fakeAsync.js +++ b/tests/test_declarations/angular_fakeAsync.js @@ -14,6 +14,8 @@ it("does something really long and complicated so I have to write a very long na // code })); +it("does something really long and complicated so I have to write a very long name for the test", fakeAsync(() => new SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS)); + /* * isTestCall(parent) should only be called when parent exists * and parent.type is CallExpression. This test makes sure that diff --git a/tests/test_declarations/test_declarations.js b/tests/test_declarations/test_declarations.js index d90a4952..6f7139b6 100644 --- a/tests/test_declarations/test_declarations.js +++ b/tests/test_declarations/test_declarations.js @@ -117,3 +117,14 @@ it(`handles it("does something quick", () => { console.log("hello!") }, 1000000000) + +it( + 'succeeds if the test finishes in time', + () => new Promise(resolve => setTimeout(resolve, 10)) +); + +it( + 'succeeds if the test finishes in time', + () => new Promise(resolve => setTimeout(resolve, 10)), + 250 +);