src/content/docs/linter/rules/no-exports-in-test.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.6.0` - Diagnostic Category: [`lint/suspicious/noExportsInTest`](/reference/diagnostics#diagnostic-category) - 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**](/reference/diagnostics#error). - This rule belongs to the following domains: - [`test`](/linter/domains#test) - Sources: - Inspired from [`jest/no-export`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-export.md){
"linter": {
"rules": {
"suspicious": {
"noExportsInTest": "error"
}
}
}
}
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.
export function myHelper() {}
describe('a test', () => {
expect(1).toBe(1);
});
function myHelper() {}
describe('a test', () => {
expect(1).toBe(1);
});