mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-18 00:23:36 +08:00
Share workspace packages between Ray Admin and the interactive docs. BREAKING CHANGE: v6 is a new major line. v5 stays on legacy/v5.
28 lines
653 B
TypeScript
28 lines
653 B
TypeScript
import { callWithErrorHandling } from '../../apps/admin/src/utils/basic'
|
|
|
|
describe('callWithErrorHandling', () => {
|
|
it('should call the function and return the result', () => {
|
|
const fn = (x: number) => x
|
|
|
|
const callbackFn = () => {}
|
|
|
|
expect(callWithErrorHandling(fn, callbackFn, [1])).toBe(1)
|
|
})
|
|
|
|
it('should call the callback function when the function throws an error', () => {
|
|
let callbackFnExecuted = 1
|
|
|
|
const fn = () => {
|
|
throw new Error('test error')
|
|
}
|
|
|
|
const callbackFn = () => {
|
|
callbackFnExecuted = 2
|
|
}
|
|
|
|
callWithErrorHandling(fn, callbackFn)
|
|
|
|
expect(callbackFnExecuted).toBe(2)
|
|
})
|
|
})
|