noExportsInTest (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v1.6.0 - Diagnostic Category:
lint/suspicious/noExportsInTest - This rule is recommended, meaning it is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Inspired from
jest/no-export
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noExportsInTest": "error" } } }}Description
Section titled “Description”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
Section titled “Examples”Invalid
Section titled “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);
ℹ Importing a test file runs all of its tests again in the importing file. This causes duplicate test runs.
ℹ Move the exported code into a separate file and import it from the tests that need it.
function myHelper() {}describe('a test', () => { expect(1).toBe(1);});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.