jest/no-confusing-set-timeout Style
它的作用
禁止对 jest.setTimeout 的混淆性使用。
为什么这不好?
- 在全局作用域之外的任何地方调用
- 多次调用
- 在其他 Jest 函数之后调用,例如 hooks、
describe、test或it
示例
以下均为无效示例:
javascript
escribe("test foo", () => {
jest.setTimeout(1000);
it("test-description", () => {
// 测试逻辑;
});
});
describe("test bar", () => {
it("test-description", () => {
jest.setTimeout(1000);
// 测试逻辑;
});
});
test("foo-bar", () => {
jest.setTimeout(1000);
});
describe("unit test", () => {
beforeEach(() => {
jest.setTimeout(1000);
});
});如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-confusing-set-timeout": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jest"],
rules: {
"jest/no-confusing-set-timeout": "error",
},
});bash
oxlint --deny jest/no-confusing-set-timeout --jest-plugin版本
此规则在 v0.0.14 中添加。
