# bun:test/consistent-test-it

> Enforce one of `test` or `it` for defining tests

`test` and `it` are two names for the same function. When a project mixes them at random, readers wonder whether the difference means something. It doesn't.

By default, a test at the top level of a file uses `test`, and a test inside a `describe` uses `it`.

`--fix` renames the call if the file already imports the other name.

{/* 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]
"bun:test/consistent-test-it" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"bun:test/consistent-test-it" = ["error", {
  fn = "test", # "it" or "test"
  withinDescribe = "it", # "it" or "test"
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```ts
import { describe, expect, it, test } from "bun:test";

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

describe("subtract", () => {
  test("goes below zero", () => {
    expect(1 - 2).toBe(-1);
  });
});
```

Not reported:

{/* good */}
```ts
import { describe, expect, it, test } from "bun:test";

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

describe("subtract", () => {
  it("goes below zero", () => {
    expect(1 - 2).toBe(-1);
  });
});
```

Variants like `it.skip`, `it.only` and `it.each` are checked too:

{/* bad */}
```ts
import { expect, it } from "bun:test";

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

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `fn` | `"test"` | The name for tests at the top level of a file: `"test"` or `"it"`. |
| `withinDescribe` | the value of `fn` if you set it, otherwise `"it"` | The name for tests inside a `describe`. |

To use `test` everywhere, set only `fn`:

```toml bunfig.toml
[lint.rules]
"bun:test/consistent-test-it" = ["error", { fn = "test" }]
```

Then `it` inside a `describe` is reported too:

{/* bad {"options": [{"fn": "test"}]} */}
```ts
import { describe, expect, it } from "bun:test";

describe("subtract", () => {
  it("goes below zero", () => {
    expect(1 - 2).toBe(-1);
  });
});
```
