23 lines
		
	
	
		
			556 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			556 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
describe('greeter function', () => {
 | 
						|
  let timeoutSpy: jest.SpyInstance;
 | 
						|
 | 
						|
  // Act before assertions
 | 
						|
  beforeAll(async () => {
 | 
						|
    timeoutSpy = jest.spyOn(global, 'setTimeout');
 | 
						|
 | 
						|
    //const p: Promise<string> = 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', () => {});
 | 
						|
});
 |