noExportsInTest
¥Summary
-
规则生效日期:
v1.6.0¥Rule available since:
v1.6.0 -
诊断类别:
lint/suspicious/noExportsInTest¥Diagnostic Category:
lint/suspicious/noExportsInTest -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
此规则属于以下域:
¥This rule belongs to the following domains:
-
来源:
¥Sources:
-
灵感来自
jest/no-export¥Inspired from
jest/no-export
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noExportsInTest": "error" } } }}¥Description
禁止在包含测试的文件中 使用 export 或 module.exports
¥Disallow using export or module.exports in files containing tests
此规则旨在通过从测试文件中导出内容来消除重复的测试运行。如果你从测试文件导入,则该文件中的所有测试都将在每个导入的实例中运行,因此最重要的是,不要从测试中导出,而是在需要在测试之间共享辅助函数时将其移动到单独的文件中。
¥This rule aims to eliminate duplicate runs of tests by exporting things from test files. If you import from a test file, then all the tests in that file will be run in each imported instance, so bottom line, don’t export from a test, but instead move helper functions into a separate file when they need to be shared across tests.
¥Examples
¥Invalid
export function myHelper() {}describe('a test', () => { expect(1).toBe(1);});code-block.js:1:1 lint/suspicious/noExportsInTest ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Do not export from a test file.
> 1 │ export function myHelper() {}
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ describe(‘a test’, () => {
3 │ expect(1).toBe(1);
¥Valid
function myHelper() {}describe('a test', () => { expect(1).toBe(1);});¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号