describe('greeter function', () => { let timeoutSpy: jest.SpyInstance; // Act before assertions beforeAll(async () => { timeoutSpy = jest.spyOn(global, 'setTimeout'); //const p: Promise = greeter(name); jest.runOnlyPendingTimers(); }); // Teardown (cleanup) after assertions afterAll(() => { timeoutSpy.mockRestore(); }); // Assert if setTimeout was called properly it('delays the greeting by 2 seconds', () => {}); // Assert greeter result it('greets a user with `Hello, {name}` message', () => {}); });