jest/no-export Correctness
作用
如果文件中包含一个或多个测试,则禁止使用导出。
为什么这不好?
此规则旨在通过从测试文件中导出内容来消除测试的重复运行。 如果你从测试文件中导入,那么该文件中的所有测试都会在每个导入的实例中运行。 因此,总而言之,不要从测试中导出,而是在需要在测试之间共享时将辅助函数移到单独的文件中。
示例
以下是此规则的错误代码示例:
javascript
export function myHelper() {}
describe("a test", () => {
expect(1).toBe(1);
});如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-export": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["jest"],
rules: {
"jest/no-export": "error",
},
});bash
oxlint --deny jest/no-export --jest-plugin版本
此规则于 v0.0.13 中添加。
