MCPcopy Create free account
hub / github.com/middleapi/orpc / assertErrorCase

Function assertErrorCase

packages/client/src/adapters/fetch/rpc-link.test.ts:43–77  ·  view source on GitHub ↗
(value: unknown, expected: unknown)

Source from the content-addressed store, hash-verified

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)

Callers 1

rpc-link.test.tsFile · 0.70

Calls 3

handlerMethod · 0.80
callMethod · 0.65
handleMethod · 0.45

Tested by

no test coverage detected