(value: unknown, expected: unknown)
| 41 | } |
| 42 | |
| 43 | async function assertErrorCase(value: unknown, expected: unknown): Promise<true> { |
| 44 | const handler = vi.fn(({ input }) => { |
| 45 | throw new ORPCError('TEST', { |
| 46 | data: input, |
| 47 | }) |
| 48 | }) |
| 49 | |
| 50 | const rpcHandler = new RPCHandler(os.handler(handler), { |
| 51 | strictGetMethodPluginEnabled: false, |
| 52 | }) |
| 53 | |
| 54 | const rpcLink = new RPCLink({ |
| 55 | url: 'http://api.example.com', |
| 56 | method, |
| 57 | fetch: async (request) => { |
| 58 | const { matched, response } = await rpcHandler.handle(request) |
| 59 | |
| 60 | if (matched) { |
| 61 | return response |
| 62 | } |
| 63 | |
| 64 | throw new Error('No procedure match') |
| 65 | }, |
| 66 | }) |
| 67 | |
| 68 | await expect(rpcLink.call([], value, { context: {} })).rejects.toSatisfy((e) => { |
| 69 | expect(e).toBeInstanceOf(ORPCError) |
| 70 | expect(e.code).toBe('TEST') |
| 71 | expect(e.data).toEqual(expected) |
| 72 | |
| 73 | return true |
| 74 | }) |
| 75 | |
| 76 | return true |
| 77 | } |
| 78 | |
| 79 | it('should work on flat', async () => { |
| 80 | expect(await assertSuccessCase(value, expected)).toBe(true) |
no test coverage detected