tRPCttRPC
Powered by
MugetsuM
tRPC•3y ago•
2 replies
Mugetsu

Vitest error test

How can I test for specific TRPCError code with vitest? I managed to get the message but can't figure out how to get the code.

  it('should throw if user roles are missing', async ({ trpcContextMock }) => {
    const ctx = await createInnerTRPCContext(
      trpcContextMock({ authorisation: { userSecurityGroups: [] } }),
    )
    const caller = appRouter.createCaller(ctx)

    await expect(caller.locations.searchLocations({})).rejects.toThrowError(
      'User roles are missing',
    )
  })
  it('should throw if user roles are missing', async ({ trpcContextMock }) => {
    const ctx = await createInnerTRPCContext(
      trpcContextMock({ authorisation: { userSecurityGroups: [] } }),
    )
    const caller = appRouter.createCaller(ctx)

    await expect(caller.locations.searchLocations({})).rejects.toThrowError(
      'User roles are missing',
    )
  })
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Vitest context router caller
MugetsuMMugetsu / ❓-help
4y ago
Weird error when running unit test
sudoSsudo / ❓-help
4y ago
Examples of Vitest with React Testing Library
Daniel SDDaniel S / ❓-help
3y ago