Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
CatService,
{
provide: getModelToken('Cat'),
// notice that only the functions we call from the model are mocked
useValue: {
new: jest.fn().mockResolvedValue(mockCat()),
constructor: jest.fn().mockResolvedValue(mockCat()),
find: jest.fn(),
findOne: jest.fn(),
update: jest.fn(),
create: jest.fn(),
remove: jest.fn(),
exec: jest.fn(),
},
},
],
}).compile();
service = module.get(CatService);
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
providers: [
UsersService,
{
provide: getModelToken('User'),
useValue: UserModel,
},
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [LinksModule]
})
.overrideProvider(getModelToken('Links'))
.useValue(mockRepository)
.compile();
linksService = module.get(LinksService);
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [TagsModule]
})
.overrideProvider(getModelToken('Tags'))
.useValue(mockRepository)
.overrideProvider(getModelToken('Articles'))
.useValue({})
.overrideProvider(ArticlesSercice)
.useValue({
aggregate() {
return [
{
_id: '123'
}
];
}
})
.compile();
tagsService = module.get(TagsService);
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [OptionsModule]
})
.overrideProvider(getModelToken('Options'))
.useValue(mockRepository)
.compile();
optionsService = module.get(OptionsService);
});
useValue: {
new: jest.fn().mockResolvedValue(mockCat()),
constructor: jest.fn().mockResolvedValue(mockCat()),
find: jest.fn(),
findOne: jest.fn(),
update: jest.fn(),
create: jest.fn(),
remove: jest.fn(),
exec: jest.fn(),
},
},
],
}).compile();
service = module.get(CatService);
model = module.get>(getModelToken('Cat'));
});
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [CommentsModule]
})
.overrideProvider(getModelToken('Comments'))
.useValue(mockRepository)
.overrideProvider(getModelToken('Articles'))
.useValue({})
.overrideProvider(ArticlesSercice)
.useValue(articlesService)
.overrideProvider(EmailService)
.useValue(emailService)
.compile();
commentsService = module.get(CommentsService);
});
beforeAll(async () => {
const mockUserModel: Partial> = {};
const mockAuthService: Partial = {};
const mockTokenService: Partial = {};
const module: TestingModule = await Test.createTestingModule({
providers: [
UserService,
{
provide: getModelToken(User.modelName),
useValue: mockUserModel,
},
{
provide: AuthService,
useValue: mockAuthService,
},
{
provide: TokenService,
useValue: mockTokenService,
},
MapperService,
],
}).compile();
service = module.get(UserService);
});
it('should be defined', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
UsersService,
{
provide: getModelToken('User'),
useValue: {}
}
]
}).compile();
service = module.get(UsersService);
});
beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
TokenService,
{
provide: getModelToken(RefreshToken.modelName),
useFactory: () => ({
findOneAndDelete: jest.fn(),
findOne: jest.fn(),
findByIdAndUpdate: jest.fn(),
create: jest.fn(),
deleteMany: jest.fn(),
}),
},
{
provide: AuthService,
useFactory: () => ({}),
},
MapperService,
ConfigurationService,
],
}).compile();