Skip to content

Files

Latest commit

 

History

History
39 lines (30 loc) · 759 Bytes

no-export.md

File metadata and controls

39 lines (30 loc) · 759 Bytes

Pattern: Export in test file

Issue: -

Description

Exporting from test files causes tests to run multiple times when the export is imported elsewhere. Helper functions should be moved to separate utility files instead of being exported from test files.

Examples

Example of incorrect code:

export const helper = () => {
  return "test value";
};

describe("suite", () => {
  test("case", () => {
    expect(helper()).toBe("test value");
  });
});

Example of correct code:

// test-helpers.js
export const helper = () => {
  return "test value";
};

// test.test.js
import { helper } from "./test-helpers";

describe("suite", () => {
  test("case", () => {
    expect(helper()).toBe("test value");
  });
});