Skip to content

Latest commit

 

History

History
43 lines (26 loc) · 1.23 KB

no-exports.md

File metadata and controls

43 lines (26 loc) · 1.23 KB

Disallow exports from test files (mocha/no-exports)

💼 This rule is enabled in the ✅ recommended config.

Test files should have only one purpose, which is testing a specific unit. Using exports could mean the test file is also used to provide and expose utility or library functionalities, instead those should be moved to separate files.

Rule Details

This rule looks for CommonJS or ESM export statements and flags them as a problem when the same file also contains a use of a mocha function.

The following patterns are considered warnings:

describe(function () {/* ... */});
module.exports = 'foo';

it('works', function () {/* ... */});
exports.foo = 'bar';

beforeEach(function () {/* ... */});
export default 'foo';

afterEach(function () {/* ... */});
export const foo = 'bar';

These patterns would not be considered warnings:

describe(function () {/* ... */});

it('works', function () {/* ... */});

beforeEach(function () {/* ... */});

afterEach(function () {/* ... */});

When Not To Use It

When you use the exports interface it is not recommended to use this rule.