# jest/no-export

> Disallow exports from a file that has tests

When another file imports from a test file, the whole test file runs, including its `test()` calls, so its tests run a second time as part of the importing file. Put shared helpers in a separate file.

The rule only checks files named like tests. That means the name ends in `test` or `spec` before the extension, such as `cart.test.ts`, or the file is under a `__tests__` directory. A file with no `test` or `it` call can export anything.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"jest/no-export" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"filename": "src/cart.test.ts"} */}
```ts
import { expect, test } from "@jest/globals";

export function makeCart() {
  return { items: [] };
}

test("starts empty", () => {
  expect(makeCart().items).toEqual([]);
});
```

Not reported, with the helper in a separate file:

{/* file "helpers.ts" */}
```ts
export function makeCart() {
  return { items: [] };
}
```

{/* good {"filename": "cart.test.ts"} */}
```ts
import { expect, test } from "@jest/globals";
import { makeCart } from "./helpers";

test("starts empty", () => {
  expect(makeCart().items).toEqual([]);
});
```

Exported types are reported too:

{/* bad {"filename": "cart.test.ts"} */}
```ts
import { expect, test } from "@jest/globals";
import { makeCart } from "./helpers";

export type Cart = ReturnType<typeof makeCart>;

test("starts empty", () => {
  expect(makeCart().items).toEqual([]);
});
```
