I have this service in my NestJs application:
async testTEst(id: string) {
const user = await this.prismaService.user.findUnique({
where: {
id,
},
});
// create 5sec timer
let seconds = 5;
const timer = setInterval(() => {
console.log(`Hello ${user.email}, ${seconds} seconds left`);
seconds -= 1;
if (seconds < 0) {
clearInterval(timer);
}
}, 1000);
return {
message: 'User will be deleted in 15 seconds',
};
}
I created an integration test for this where i test how the service interact with all dependancies and database.
it('should notify about user deletion countdown', async () => {
jest.useFakeTimers();
const u = await prismaService.user.create({
data: { email: '[email protected]', password: '234' },
});
const response = userService.testTEst(u.id);
jest.advanceTimersByTime(5000);
const result = await response; // Ensure the async operation is completed
expect(result).toEqual({
message: 'User will be deleted in 15 seconds',
});
});
Running the test i get: thrown: "Exceeded timeout of 5000 ms for a test.
.
I tried this: testTimeout: 20000
but it does not work.
I assume that i did something incorrect in my test but i can not find what.
Question: Who faced this issue and how to fix my test?
Note: I am using MACos