jest/no-confusing-set-timeout 风格
它做了什么
禁止在 jest.setTimeout 中使用容易引起混淆的用法
为什么这是不好的?
- 在全局作用域以外的位置调用
- 多次调用
- 在其他 Jest 函数(如钩子、
describe、test或it)之后调用
示例
以下所有情况都是无效的:
javascript
escribe("测试 foo", () => {
jest.setTimeout(1000);
it("测试描述", () => {
// 测试逻辑;
});
});
describe("测试 bar", () => {
it("测试描述", () => {
jest.setTimeout(1000);
// 测试逻辑;
});
});
test("foo-bar", () => {
jest.setTimeout(1000);
});
describe("单元测试", () => {
beforeEach(() => {
jest.setTimeout(1000);
});
});如何使用
要通过配置文件或 CLI 启用此规则,可以使用:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-confusing-set-timeout": "error"
}
}bash
oxlint --deny jest/no-confusing-set-timeout --jest-plugin