Skip to content

Instantly share code, notes, and snippets.

@rjpkuyper
Last active February 2, 2023 06:09
Show Gist options
  • Save rjpkuyper/e3b2dc31a27f853161b216a47b96d41f to your computer and use it in GitHub Desktop.
Save rjpkuyper/e3b2dc31a27f853161b216a47b96d41f to your computer and use it in GitHub Desktop.
Test file
import { Test } from '@nestjs/testing';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';
describe('CatsController', () => {
let catsController: CatsController;
let catsService: CatsService;
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
controllers: [CatsController],
providers: [CatsService],
}).compile();
catsService = moduleRef.get<CatsService>(CatsService);
catsController = moduleRef.get<CatsController>(CatsController);
});
describe('findAll', () => {
it('should return an array of cats', async () => {
const result = ['test'];
jest.spyOn(catsService, 'findAll').mockImplementation(() => result);
expect(await catsController.findAll()).toBe(result);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment