# jest/no-done-callback

> Disallow the `done` callback in tests and hooks in favor of promises

A test that takes a `done` parameter waits until `done()` is called. If an `expect` throws first, `done()` is never reached, and the test fails with a timeout instead of the real error. An `async` test, or one that returns a promise, fails with the error itself.

The parameter's name doesn't matter. Any test or hook callback with exactly one parameter is reported.

## Configure

Off by default. To turn it on:

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

## Examples

Reported:

```ts
import { expect, test } from "@jest/globals";

test("reads the config", done => {
  readConfig((error, config) => {
    expect(config.port).toBe(3000);
    done();
  });
});
```

Not reported:

```ts
import { expect, test } from "@jest/globals";

test("reads the config", async () => {
  const config = await readConfig();
  expect(config.port).toBe(3000);
});
```

If the API only takes a callback, wrap it in a promise:

```ts
import { afterAll } from "@jest/globals";

afterAll(() => new Promise(resolve => server.close(resolve)));
```

The `test.each([...])` callback isn't checked, because its parameters are the row's values:

```ts
import { expect, test } from "@jest/globals";

test.each([1, 2, 3])("%i is positive", value => {
  expect(value).toBeGreaterThan(0);
});
```
