Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading