NestJS · Middle · Question 42 of 75
How do you override a guard in a test to simulate an authenticated user?
- ✓Correct answer:
.overrideGuard(JwtAuthGuard).useValue({ canActivate: () => true })on the testing module - 2Remove the guard decorator from the controller
- 3Set
NODE_ENV=test, and guards are skipped
Explanation
Similar helpers exist for pipes, interceptors and filters: overridePipe, overrideInterceptor, overrideFilter.