diff --git a/crates/oxc_formatter/src/utils/call_expression.rs b/crates/oxc_formatter/src/utils/call_expression.rs index 0d587a630c251..2ea6defa04392 100644 --- a/crates/oxc_formatter/src/utils/call_expression.rs +++ b/crates/oxc_formatter/src/utils/call_expression.rs @@ -56,8 +56,11 @@ pub fn is_test_call_expression(call: &AstNode>) -> bool { } // it("description", ..) - // it(Test.name, ..) - (_, Some(second), third) if arguments.len() <= 3 && contains_a_test_pattern(callee) => { + (Some(first), Some(second), third) + if arguments.len() <= 3 + && matches!(first, Argument::StringLiteral(_) | Argument::TemplateLiteral(_)) + && contains_a_test_pattern(callee) => + { // it('name', callback, duration) if !matches!(third, None | Some(Argument::NumericLiteral(_))) { return false; diff --git a/crates/oxc_formatter/tests/fixtures/ts/arguments/issue-18929.ts b/crates/oxc_formatter/tests/fixtures/ts/arguments/issue-18929.ts new file mode 100644 index 0000000000000..c71bf0a0c2573 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/arguments/issue-18929.ts @@ -0,0 +1,8 @@ +// The first argument of test function should be a simple string literal or template literal +it( + "a" + b, + async () => { + // code + }, + 30000, +); diff --git a/crates/oxc_formatter/tests/fixtures/ts/arguments/issue-18929.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/arguments/issue-18929.ts.snap new file mode 100644 index 0000000000000..5c97ecd1375f2 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/arguments/issue-18929.ts.snap @@ -0,0 +1,39 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +// The first argument of test function should be a simple string literal or template literal +it( + "a" + b, + async () => { + // code + }, + 30000, +); + +==================== Output ==================== +------------------ +{ printWidth: 80 } +------------------ +// The first argument of test function should be a simple string literal or template literal +it( + "a" + b, + async () => { + // code + }, + 30000, +); + +------------------- +{ printWidth: 100 } +------------------- +// The first argument of test function should be a simple string literal or template literal +it( + "a" + b, + async () => { + // code + }, + 30000, +); + +===================== End =====================