i know that this question has already been asked elswhere, but in my case, i followed the jest best practice video from mickael guay (click to view)
But unfortunately i get the jest error, Your test suite must contain at least one test But one test is passing just after that.
here's my code: [...]
const mockResponse = {
json: jest.fn(),
status: jest.fn().mockReturnThis(),
} as unknown as Response<any, Record<string, any>>;
describe('UsersController', () => {
let usersController: UsersController;
let usersService: UsersService;
beforeEach(async () => {
const moduleRef = await Test.createTestingModule({
imports: [],
controllers: [UsersController],
providers: [
UsersService,
{ provide: getModelToken(User.name), useValue: jest.fn() },
{ provide: getModelToken(Role.name), useValue: jest.fn() },
],
}).compile();
usersController = moduleRef.get<UsersController>(UsersController);
usersService = moduleRef.get<UsersService>(UsersService);
jest.clearAllMocks();
});
describe('findOneById', () => {
describe('when findOneById is called', () => {
beforeEach(async () => {
const user: Partial<User> & Response =
await usersController.findOneById(mockResponse, userStub().userId);
console.log('user', user);
});
it('then it should call usersService', () => {
expect(usersService.findOneById).toBeCalledWith(userStub().userId);
});
});
});
});
I think maybe it's because i have a describe() nested in a describe(), that makes the first describe() waiting also for a test ? Thank you very much!
EDIT: figure it out when i realized that i had another old .spec file hidden in another folder. removing it solved the issue.