title: Test resolvers in NestJS
body: <p>This is a sample of <code>resolver</code> in NestJs, and I'm about to write tests for this file. But there is no documentation for testing resolvers in nestjs docs.</p>
  
  <p>I already have a test for my <code>service</code>, but resolvers also may have little logic inside them, so it's better to have tests for them as well.</p>
  
  <p>How I can test <code>resolver</code> files?</p>
  
  <pre><code>import { ObjectId } from 'mongodb';
  import { AuthGuard } from '../utils/Auth.guards';
  import { UseGuards } from '@nestjs/common';
  import { IUser } from '../users/users.service';
  import { User } from '../utils/user.decorator';
  import { Query, Resolver, Mutation, Args } from '@nestjs/graphql';
  import { AccessService } from './access.service';
  import { NeedAccess } from '../utils/needAccess.decorator';
  import { HasAccess } from '../utils/access.decorator';
  
  @Resolver('Accesss')
  @UseGuards(AuthGuard)
  export class AccessResolvers {
    constructor(private readonly accessService: AccessService) {}
  
    @Query()
    @NeedAccess()
    access(
      @Args('userId') userId: ObjectId,
      @User() user: IUser,
      @HasAccess(['access.view']) hasAccess,
    ) {
      if (userId &amp;&amp; hasAccess) { // this might be a situation to concern about in tests
        return this.accessService.getUserAccess(userId);
      } else {
        return this.accessService.getUserAccess(user._id);
      }
    }
  
  }
  </code></pre>