mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
fix(linter): detect assert function in Await Expression (#1202)
fixes: #1199
This commit is contained in:
parent
884a819cd6
commit
5a4e61132e
2 changed files with 38 additions and 0 deletions
|
|
@ -162,6 +162,9 @@ fn check_assert_function_used<'a>(
|
|||
};
|
||||
return check_statements(&body.statements, assert_function_names, ctx);
|
||||
}
|
||||
Expression::AwaitExpression(expr) => {
|
||||
return check_assert_function_used(&expr.argument, assert_function_names, ctx);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
|
|
@ -354,6 +357,17 @@ fn test() {
|
|||
",
|
||||
Some(serde_json::json!([{ "assertFunctionNames": ["tester.foo.bar.expect"] }])),
|
||||
),
|
||||
(
|
||||
r#"
|
||||
it("should not warn on await expect", async () => {
|
||||
const asyncFunction = async () => {
|
||||
throw new Error('nope')
|
||||
};
|
||||
await expect(asyncFunction()).rejects.toThrow();
|
||||
});
|
||||
"#,
|
||||
None,
|
||||
),
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
|
|
@ -422,6 +436,17 @@ fn test() {
|
|||
",
|
||||
None,
|
||||
),
|
||||
(
|
||||
r#"
|
||||
it("should warn on non-assert await expression", async () => {
|
||||
const asyncFunction = async () => {
|
||||
throw new Error('nope')
|
||||
};
|
||||
await foo(asyncFunction()).rejects.toThrow();
|
||||
});
|
||||
"#,
|
||||
None,
|
||||
),
|
||||
];
|
||||
|
||||
Tester::new(ExpectExpect::NAME, pass, fail).with_jest_plugin(true).test_and_snapshot();
|
||||
|
|
|
|||
|
|
@ -123,4 +123,17 @@ expression: expect_expect
|
|||
╰────
|
||||
help: Add assertion(s) in this Test
|
||||
|
||||
⚠ eslint-plugin-jest(expect-expect): Test has no assertions
|
||||
╭─[expect_expect.tsx:1:1]
|
||||
1 │
|
||||
2 │ ╭─▶ it("should warn on non-assert await expression", async () => {
|
||||
3 │ │ const asyncFunction = async () => {
|
||||
4 │ │ throw new Error('nope')
|
||||
5 │ │ };
|
||||
6 │ │ await foo(asyncFunction()).rejects.toThrow();
|
||||
7 │ ╰─▶ });
|
||||
8 │
|
||||
╰────
|
||||
help: Add assertion(s) in this Test
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue