close

jest/no-done-callback

Configuration

PresetConfigured Value
✅ jestPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/no-done-callback': 'error',
    },
  },
]);

Rule Details

Disallow using a done-style callback in Jest tests and hooks. Returning a Promise (or using async/await) is more reliable than relying on done, which can silently pass or time out when not invoked correctly.

For non-async functions the rule reports noDoneCallback and suggests wrapping the body in new Promise(done => ...). For async functions it reports useAwaitInsteadOfCallback.

Examples of incorrect code for this rule:

beforeEach(done => {
  done();
});

test('myFunction()', done => {
  done();
});

test('myFunction()', async done => {
  await fetchData();
  done();
});

Examples of correct code for this rule:

beforeEach(() => {
  return setupUsTheBomb();
});

test('myFunction()', () => {
  expect(myFunction()).toBeTruthy();
});

test('myFunction()', async () => {
  const data = await fetchData();
  expect(data).toBe('peanut butter');
});

Original Documentation