Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 873 Bytes

File metadata and controls

35 lines (25 loc) · 873 Bytes

vitest/prefer-called-times

📝 Enforce using toBeCalledTimes(1) or toHaveBeenCalledTimes(1).

⚠️ This rule warns in the 🌐 all config.

🔧 This rule is automatically fixable by the --fix CLI option.

Rule Details

This rule aims to enforce the use of toBeCalledTimes(1) or toHaveBeenCalledTimes(1) over toBeCalledOnce() or toHaveBeenCalledOnce().

Examples of incorrect code for this rule:

test('foo', () => {
  const mock = vi.fn()
  mock('foo')
  expect(mock).toBeCalledOnce()
  expect(mock).toHaveBeenCalledOnce()
})

Examples of correct code for this rule:

test('foo', () => {
  const mock = vi.fn()
  mock('foo')
  expect(mock).toBeCalledTimes(1)
  expect(mock).toHaveBeenCalledTimes(1)
})