NestJS · Senior · Question 35 of 75
How can you test a module that uses a request-scoped provider?
- 1Request-scoped providers can't be tested
- 2Use
moduleRef.get()as usual - ✓Correct answer: Use
moduleRef.resolve()with a context ID (ContextIdFactory.create()), sinceget()doesn't return scoped instances
Explanation
You can also register a request object for that context ID with moduleRef.registerRequestByContextId().