Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('UserController', () => {
let userController: UserController;
let userService: UserService;
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [UserController],
components: [UserService],
}).compile();
userService = module.get(UserService);
userController = module.get(UserController);
});
describe('findAll', () => {
it('should return an array of users', async () => {
const result = ['test'];
jest.spyOn(userService, 'findAll').mockImplementation(() => result);
expect(await userController.findAll()).toBe(result);
});
});
});
import { Test } from '@nestjs/testing';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import {jest, describe, beforeEach, it, expect} from 'jest';
describe('UserController', () => {
let userController: UserController;
let userService: UserService;
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [UserController],
components: [UserService],
}).compile();
userService = module.get(UserService);
userController = module.get(UserController);
});
describe('findAll', () => {
it('should return an array of users', async () => {
const result = ['test'];