Last active
February 2, 2023 06:09
-
-
Save rjpkuyper/e3b2dc31a27f853161b216a47b96d41f to your computer and use it in GitHub Desktop.
Test file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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