jest/valid-describe-callback 正確性
作用
此規則驗證 describe()
函式的第二個參數是否為回呼函式。此回呼函式
- 不應為 async
- 不應包含任何參數
- 不應包含任何
return
語句
為何這是不好的?
使用不正確的 describe()
回呼函式可能會導致意料之外的測試錯誤。
範例
javascript
// Async callback functions are not allowed
describe("myFunction()", async () => {
// ...
});
// Callback function parameters are not allowed
describe("myFunction()", (done) => {
// ...
});
// Returning a value from a describe block is not allowed
describe("myFunction", () =>
it("returns a truthy value", () => {
expect(myFunction()).toBeTruthy();
}));
此規則與 eslint-plugin-vitest 相容,若要使用它,請將以下設定新增至您的 .eslintrc.json
json
{
"rules": {
"vitest/valid-describe-callback": "error"
}
}