ray-template/__test__/vue/call.spec.ts
XiaoDaiGua-Ray 403fdd589a feat!: rebuild Ray Template as a monorepo
Share workspace packages between Ray Admin and the interactive docs.

BREAKING CHANGE: v6 is a new major line. v5 stays on legacy/v5.
2026-11-04 14:01:28 +08:00

55 lines
1.1 KiB
TypeScript

import { call } from '../../apps/admin/src/utils/vue/call'
describe('call', () => {
it('should be executed once', () => {
const fn = vi.fn()
call(() => fn())
expect(fn).toHaveBeenCalledTimes(1)
})
it('should be executed with an argument', () => {
const fn = vi.fn()
call((a: number) => fn(a), 1)
expect(fn).toHaveBeenCalledWith(1)
})
it('should be executed with multiple arguments', () => {
const fn = vi.fn()
call((a: number, b: number) => fn(a, b), 1, 2)
expect(fn).toHaveBeenCalledWith(1, 2)
})
})
it('forwards variadic arguments in order and stops when a callback throws', () => {
const first = vi.fn(
(_a: number, _b: string, _c: boolean, _d: null, _e: number) => {},
)
const error = new Error('stop')
const last = vi.fn()
expect(() =>
call(
[
first,
() => {
throw error
},
last,
],
1,
'a',
false,
null,
2,
),
).toThrow(error)
expect(first).toHaveBeenCalledExactlyOnceWith(1, 'a', false, null, 2)
expect(last).not.toHaveBeenCalled()
})