diff --git a/crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs b/crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs index ff5ce6b1c5ce0..b76b75a239532 100644 --- a/crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs +++ b/crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs @@ -240,6 +240,16 @@ fn is_var_declarator_or_test_block<'a>( if additional_test_block_functions.contains(&node_name) { return true; } + + let parent = ctx.nodes().parent_node(node.id()); + if matches!(parent.kind(), AstKind::CallExpression(_)) { + return is_var_declarator_or_test_block( + parent, + additional_test_block_functions, + id_nodes_mapping, + ctx, + ); + } } AstKind::ArrayExpression(_) | AstKind::ObjectExpression(_) => { let mut current = node; diff --git a/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/jest.rs b/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/jest.rs index 6ff2e65c9da37..2211d928a3c64 100644 --- a/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/jest.rs +++ b/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/jest.rs @@ -103,6 +103,15 @@ fn test() { });", None, ), + ( + r"import {fakeAsync} from '@angular/core/testing'; + describe('App', () => { it('should create the app', fakeAsync(() => { expect(true).toBeTruthy(); })); });", + None, + ), + ( + r"describe('App', () => { it('should work with wrapper function', wrapperFn(() => { expect(true).toBeTruthy(); })); });", + None, + ), ]; let fail = vec![ @@ -180,6 +189,7 @@ fn test() { None, ), ("describe.each([1, true])('trues', value => { expect(value).toBe(true); });", None), + (r"describe('App', () => { wrapperFn(() => { expect(true).toBeTruthy(); }); });", None), ( " import { expect as pleaseExpect } from '@jest/globals'; diff --git a/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/vitest.rs b/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/vitest.rs index 27a7259ca8175..90340c137133a 100644 --- a/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/vitest.rs +++ b/crates/oxc_linter/src/rules/jest/no_standalone_expect/tests/vitest.rs @@ -36,6 +36,17 @@ fn test() { r#"it.each([1, true])("trues", value => { expect(value).toBe(true); }); it("an it", () => { expect(1).toBe(1) });"#, None, ), + ( + r"import {fakeAsync} from '@angular/core/testing'; + describe('App', () => { it('should create the app', fakeAsync(() => { expect(true).toBeTruthy(); })); });", + None, + ), + ( + r"describe('App', () => { + it('should work with wrapper function', wrapperFn(() => { expect(true).toBeTruthy(); })); + });", + None, + ), ]; let fail = vec![ diff --git a/crates/oxc_linter/src/snapshots/jest_no_standalone_expect.snap b/crates/oxc_linter/src/snapshots/jest_no_standalone_expect.snap index f3bab8119b136..625e181ff8306 100644 --- a/crates/oxc_linter/src/snapshots/jest_no_standalone_expect.snap +++ b/crates/oxc_linter/src/snapshots/jest_no_standalone_expect.snap @@ -123,6 +123,13 @@ source: crates/oxc_linter/src/tester.rs ╰──── help: Did you forget to wrap `expect` in a `test` or `it` block? + ⚠ eslint-plugin-jest(no-standalone-expect): `expect` must be inside of a test block. + ╭─[no_standalone_expect.tsx:1:43] + 1 │ describe('App', () => { wrapperFn(() => { expect(true).toBeTruthy(); }); }); + · ────── + ╰──── + help: Did you forget to wrap `expect` in a `test` or `it` block? + ⚠ eslint-plugin-jest(no-standalone-expect): `expect` must be inside of a test block. ╭─[no_standalone_expect.tsx:3:44] 2 │ import { expect as pleaseExpect } from '@jest/globals';