#How do you test your custom param decorator?

1 messages · Page 1 of 1 (latest)

lost halo
#

Hey folks, couldn't find info on testing custom param decorators.

import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { AuthenticatedRequest } from './auth.guard';

export const User = createParamDecorator(
  (data: unknown, ctx: ExecutionContext) => {
    const request = ctx.switchToHttp().getRequest<AuthenticatedRequest>();
    return request.user;
  },
);

I have a super simple param decorator I'd like to write a test for. Not sure how to do that. If you have other advices/practices along the way I'd much appreciate it, thanks

quick yew
#

if you want an unit testing, just extract the callback function you've passed to createParamDecorator
otherwise you'd have to use some hacky way to extract that