Skip to content
GitHub

isMockFunction

function in meocord/testing Since 4.0.0

isMockFunction(fn: unknown): fn is MockInstance

Tells 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

NameTypeDescription
fnunknown

The value to check.

Returns

fn is MockInstance

Examples

TypeScript
import { expect } from 'vitest'

const interaction = createMockInteraction(ButtonInteraction, { customId: 'refresh' })
expect(isMockFunction(interaction.reply)).toBe(true)
expect(isMockFunction(() => undefined)).toBe(false)