Effect CommunityEC
Effect Communityβ€’3y agoβ€’
6 replies
mildfuzz

Unit Testing Request Has User Effect in Jest

Just getting started with unit testing my work. Starting simple, with a little effect that just checks if a
session
on a request has a user.

export const requestHasUserEffect = (
  req: NextApiRequest,
): Effect.Effect<never, UserSessionError, RequestWithUser> => {
  if (!requestHasUser(req)) {
    return Effect.fail(new UserSessionError('User unauthorised'))
  }
  return Effect.succeed(req)
}


What is the best way to unit test this in Jest to I can see both the success and failure pathways? Sucess seems easy enough, but stuggling to find a way to to failure
Was this page helpful?