# vitest/no-importing-vitest-globals

> Disallow importing `test`, `expect`, `vi` and the other Vitest globals

With `globals: true` in the Vitest config, `describe`, `test`, `expect`, `vi` and the hooks are available in every test file. Importing them again adds a line to each file that does nothing, and the files end up written in two styles.

The names are `suite`, `test`, `it`, `describe`, `expect`, `expectTypeOf`, `assert`, `assertType`, `chai`, `vi`, `vitest`, `beforeAll`, `afterAll`, `beforeEach`, `afterEach`, `onTestFailed` and `onTestFinished`.

`--fix` removes these names from the import, and removes the whole statement if nothing else is left.

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

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

## Examples

Reported:

{/* bad */}
```ts
import { describe, expect, it } from "vitest";

describe("slugify", () => {
  it("lowercases the title", () => {
    expect(slugify("Hello")).toBe("hello");
  });
});
```

`require` is reported too:

{/* bad */}
```js
const { expect, test } = require("vitest");

test("adds", () => {
  expect(1 + 1).toBe(2);
});
```

Not reported:

{/* good */}
```ts
describe("slugify", () => {
  it("lowercases the title", () => {
    expect(slugify("Hello")).toBe("hello");
  });
});
```

An `import` of types, or of names that aren't globals, isn't reported:

{/* good */}
```ts
import { type Mock, inject } from "vitest";

const save: Mock = vi.fn();
const port = inject("port");
```

## When not to use it

Only use this rule with `globals: true`. Without it the names don't exist until you import them. `vitest/prefer-importing-vitest-globals` enforces the opposite style.
