feat: add unit tests for RPCPlugin hook execution and error handling
This commit is contained in:
43
__tests__/unit/core/RPCPlugin.test.ts
Normal file
43
__tests__/unit/core/RPCPlugin.test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { createHookRunner, RPCPlugin } from "@/core/RPCPlugin"
|
||||
import type { CallIncomingCtx } from "@/core/RPCPlugin"
|
||||
|
||||
describe('RPCPlugin.test', () => {
|
||||
const plugin3 = {
|
||||
onCallIncoming(ctx: CallIncomingCtx) { throw new Error() }
|
||||
} as RPCPlugin;
|
||||
const plugin4 = {
|
||||
async onCallIncoming(ctx: CallIncomingCtx) { throw new Error() }
|
||||
} as RPCPlugin;
|
||||
|
||||
test('should be resolved', async () => {
|
||||
const plugin1 = {
|
||||
onCallIncoming: jest.fn(),
|
||||
} as RPCPlugin;
|
||||
const plugin2 = {
|
||||
async onCallIncoming(ctx: CallIncomingCtx) { }
|
||||
} as RPCPlugin;
|
||||
|
||||
const plugins = [plugin1, plugin2];
|
||||
const hookRunner = createHookRunner(plugins, 'onCallIncoming');
|
||||
await hookRunner({} as any);
|
||||
expect(plugin1.onCallIncoming).toHaveBeenCalled()
|
||||
})
|
||||
test('should be resolved2', async () => {
|
||||
const plugins = [] as RPCPlugin[];
|
||||
const hookRunner = createHookRunner(plugins, 'onCallIncoming');
|
||||
await hookRunner({} as any);
|
||||
expect.assertions(0);
|
||||
})
|
||||
|
||||
test('should be rejected1', async () => {
|
||||
const plugins = [plugin3];
|
||||
const hookRunner = createHookRunner(plugins, 'onCallIncoming');
|
||||
await expect(hookRunner({} as any)).rejects.toThrow(Error)
|
||||
})
|
||||
|
||||
test('should be rejected2', async () => {
|
||||
const plugins = [plugin4];
|
||||
const hookRunner = createHookRunner(plugins, 'onCallIncoming');
|
||||
await expect(hookRunner({} as any)).rejects.toThrow(Error)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user