jest/no-confusing-set-timeout 樣式
作用
禁止混淆地使用 jest.setTimeout
為何這樣不好?
- 在全域範圍以外的任何地方被呼叫
- 被呼叫多次
- 在其他 Jest 函式(例如 hooks、
describe
、test
或it
)之後被呼叫
範例
以下皆為無效案例
javascript
escribe("test foo", () => {
jest.setTimeout(1000);
it("test-description", () => {
// test logic;
});
});
describe("test bar", () => {
it("test-description", () => {
jest.setTimeout(1000);
// test logic;
});
});
test("foo-bar", () => {
jest.setTimeout(1000);
});
describe("unit test", () => {
beforeEach(() => {
jest.setTimeout(1000);
});
});