Skip to content

Latest commit

 

History

History
75 lines (56 loc) · 1.41 KB

no-done-callback.md

File metadata and controls

75 lines (56 loc) · 1.41 KB

Disallow using a callback in asynchronous tests and hooks (vitest/no-done-callback)

❌ This rule is deprecated.

⚠️ This rule warns in the 🌐 all config.

💡 This rule is manually fixable by editor suggestions.

Rule Details

This rule aims to prevent the use of a callback in asynchronous tests and hooks.

Examples of incorrect code for this rule:

test('foo', (done) => {
  setTimeout(done, 1000)
})

test('foo', (done) => {
  setTimeout(() => done(), 1000)
})

test('foo', (done) => {
  setTimeout(() => {
	done()
  }, 1000)
})

test('foo', (done) => {
  setTimeout(() => {
	done()
  }, 1000)
})

Examples of correct code for this rule:

test('foo', async () => {
  await new Promise((resolve) => setTimeout(resolve, 1000))
})

test('foo', async () => {
  await new Promise((resolve) => setTimeout(() => resolve(), 1000))
})

test('foo', async () => {
  await new Promise((resolve) => setTimeout(() => {
	resolve()
  }, 1000))
})

test('foo', async () => {
  await new Promise((resolve) => setTimeout(() => {
	resolve()
  }, 1000))
})

test.concurrent('foo', ({ expect }) => {
  expect(1).toMatchSnapshot();
});

test.concurrent('foo', (context) => {
  context.expect(1).toBe(1);
});

describe.concurrent('foo', () => {
  test('foo', ({ expect }) => {
    expect(1).toBe(1);
  });
});