Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 1017 Bytes

File metadata and controls

37 lines (27 loc) · 1017 Bytes

vitest/prefer-called-with

📝 Enforce using toBeCalledWith() or toHaveBeenCalledWith().

⚠️ 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 toBeCalledWith() or toHaveBeenCalledWith() over toBeCalled() or toHaveBeenCalled(), and toHaveBeenCalledExactlyOnceWith() over toHaveBeenCalledOnce().

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

test('foo', () => {
  const mock = vi.fn()
  mock('foo')
  expect(mock).toBeCalledWith('foo')
  expect(mock).toHaveBeenCalledWith('foo')
  expect(mock).toHaveBeenCalledExactlyOnceWith('foo')
})