isMockFunction
function in meocord/testing Since 4.0.0
isMockFunction(fn: unknown): fn is MockInstanceTells whether a value is a mock function: one from meocord/testing, jest.fn() or vi.fn().
Use it in a helper that takes mocks and real functions alike, such as one that sets a default on every mock method.
Parameters
| Name | Type | Description |
|---|---|---|
fn | unknown | The value to check. |
Returns
fn is MockInstanceExamples
import { expect } from 'vitest'
const interaction = createMockInteraction(ButtonInteraction, { customId: 'refresh' })
expect(isMockFunction(interaction.reply)).toBe(true)
expect(isMockFunction(() => undefined)).toBe(false)