title: How to test headers request on a nest.js application with Jest
body: <p>I'm trying to test a nest application with jest. I have a guard that calls a service, on this service I have to check if a determinate header exists, but I can't find any documentation on how I can accomplish this. Basically I'm trying to test the canActivate method from nest.js</p>
  <p>This is my auth guard from nest.js</p>
  <pre><code>export class AuthGuard implements CanActivate {
    constructor(private authService: AuthService) { }
  
    canActivate(context: ExecutionContext): boolean | Promise&lt;boolean&gt; | Observable&lt;boolean&gt; {
      const request = context.switchToHttp().getRequest();
      return this.authService.isValidRequest(request);
    }
  }
  </code></pre>
  <p>I want to test the method below with jest, don't know if I need to mock a Request. If the header was declared then the method will return true otherwise false.</p>
  <p>I don't know how can test the headers in a unit test.</p>
  <pre><code>export class AuthService {
    constructor() { }
  
    async isValidRequest(req: Request): Promise&lt;boolean&gt; {
   
      const userId = req.headers['user-id'];
  
  
      if (userId != 'undefined') {
       
         // I'm going to call another service here
         return true;
        
      }
  
      return false;
    }
  </code></pre>