Close #38851, support `jest` fakeTimers APIs' integration with `fakeAsync()`. After enable this feature, calling `jest.useFakeTimers()` will make all test run into `fakeAsync()` automatically. ``` beforeEach(() => { jest.useFakeTimers('modern'); }); afterEach(() => { jest.useRealTimers(); }); test('should run into fakeAsync() automatically', () => { const fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec'); expect(fakeAsyncZoneSpec).toBeTruthy(); }); ``` Also there are mappings between `jest` and `zone` APIs. - `jest.runAllTicks()` will call `flushMicrotasks()`. - `jest.runAllTimers()` will call `flush()`. - `jest.advanceTimersByTime()` will call `tick()` - `jest.runOnlyPendingTimers()` will call `flushOnlyPendingTimers()` - `jest.advanceTimersToNextTimer()` will call `tickToNext()` - `jest.clearAllTimers()` will call `removeAllTimers()` - `jest.getTimerCount()` will call `getTimerCount()` PR Close #39016
		
			
				
	
	
		
			24 lines
		
	
	
		
			488 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			488 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| const NodeEnvironment = require('jest-environment-node');
 | |
| const exportFakeTimersToSandboxGlobal = require('./jest-zone-patch-fake-timer');
 | |
| 
 | |
| class ZoneNodeEnvironment extends NodeEnvironment {
 | |
|   constructor(config) {
 | |
|     super(config);
 | |
|     exportFakeTimersToSandboxGlobal(this);
 | |
|   }
 | |
| 
 | |
|   async setup() {
 | |
|     await super.setup();
 | |
|   }
 | |
| 
 | |
|   async teardown() {
 | |
|     await super.teardown();
 | |
|   }
 | |
| 
 | |
|   runScript(script) {
 | |
|     return super.runScript(script);
 | |
|   }
 | |
| }
 | |
| 
 | |
| module.exports = ZoneNodeEnvironment;
 |