All quizzesEasy
Unit Testing Basics
Preview — 3 of 10 questions
Which API from @nestjs/testing do you use to assemble a module for testing a service and its dependencies?
javascript
import { Test } from '@nestjs/testing';
import { UserService } from './user.service';
const builder = Test.createTestingModule({
providers: [UserService],
});ANestFactory.create()
Bjest.createModule()
Cnew TestingModule()
DTest.createTestingModule({ providers })
After Test.createTestingModule({...}), what does await builder.compile() return?
javascript
import { TestingModule } from '@nestjs/testing';
const moduleRef: TestingModule = await Test.createTestingModule({
providers: [UserService],
}).compile();AThe raw metadata object you passed in
BA Jest mock of the module
CA running HTTP server
DA TestingModule instance with an initialized DI container you can pull providers from
How do you obtain the UserService instance from a compiled TestingModule for a standard singleton provider?
javascript
const service = moduleRef.get<UserService>(UserService);
expect(service).toBeDefined();AmoduleRef.get(UserService)
BmoduleRef.find(UserService)
CmoduleRef.inject(UserService)
DmoduleRef.provider(UserService)
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.