# vitest/prefer-importing-vitest-globals

> Require `describe`, `test`, `expect` and `vi` to be imported from `vitest`

With `globals: true` in the Vitest config, `describe`, `test`, `expect`, `vi` and the hooks exist without an import. A file that relies on that fails with a `ReferenceError` as soon as the setting is off, and nothing in the file says where the names come from.

A file gets one report for all the names it uses.

`--fix` adds the import, or adds the names to the import from `vitest` that's already there.

{/* 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]
"vitest/prefer-importing-vitest-globals" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad {"count": 1} */}
```ts
describe("cart", () => {
  test("starts empty", () => {
    expect(cart.items).toHaveLength(0);
  });
});
```

Not reported:

{/* good */}
```ts
import { describe, expect, test } from "vitest";

describe("cart", () => {
  test("starts empty", () => {
    expect(cart.items).toHaveLength(0);
  });
});
```

A call to one of these names is reported too if the name is imported from another package:

{/* bad */}
```ts
import { test } from "node:test";

test("starts empty", () => {});
```

## When not to use it

Turn it off for files that use another test runner with the same names.
