|
10 | 10 |
|
11 | 11 | import * as util from 'util';
|
12 | 12 | import {type Context, createContext, runInContext, runInNewContext} from 'vm';
|
| 13 | +import {onNodeVersions} from '@jest/test-utils'; |
13 | 14 | import {ModuleMocker, fn, mocked, spyOn} from '../';
|
14 | 15 |
|
15 | 16 | if (!Symbol.dispose) {
|
@@ -2441,25 +2442,27 @@ test('`fn` and `spyOn` do not throw', () => {
|
2441 | 2442 | }).not.toThrow();
|
2442 | 2443 | });
|
2443 | 2444 |
|
2444 |
| -describe('Explicit Resource Management', () => { |
2445 |
| - it('jest.fn state should be restored with the `using` keyword', () => { |
2446 |
| - const mock = jest.fn(); |
2447 |
| - { |
2448 |
| - using inScope = mock.mockReturnValue(2); |
2449 |
| - expect(inScope()).toBe(2); |
2450 |
| - expect(mock()).toBe(2); |
2451 |
| - } |
2452 |
| - expect(mock()).not.toBe(2); |
2453 |
| - }); |
| 2445 | +onNodeVersions('>=18.0.0', () => { |
| 2446 | + describe('Explicit Resource Management', () => { |
| 2447 | + it('jest.fn state should be restored with the `using` keyword', () => { |
| 2448 | + const mock = jest.fn(); |
| 2449 | + { |
| 2450 | + using inScope = mock.mockReturnValue(2); |
| 2451 | + expect(inScope()).toBe(2); |
| 2452 | + expect(mock()).toBe(2); |
| 2453 | + } |
| 2454 | + expect(mock()).not.toBe(2); |
| 2455 | + }); |
2454 | 2456 |
|
2455 |
| - it('should be restored with the `using` keyword', () => { |
2456 |
| - { |
2457 |
| - using mockedLog = jest.spyOn(console, 'log'); |
2458 |
| - expect(jest.isMockFunction(console.log)).toBeTruthy(); |
| 2457 | + it('should be restored with the `using` keyword', () => { |
| 2458 | + { |
| 2459 | + using mockedLog = jest.spyOn(console, 'log'); |
| 2460 | + expect(jest.isMockFunction(console.log)).toBeTruthy(); |
2459 | 2461 |
|
2460 |
| - console.log('test'); |
2461 |
| - expect(mockedLog).toHaveBeenCalled(); |
2462 |
| - } |
2463 |
| - expect(jest.isMockFunction(console.log)).toBeFalsy(); |
| 2462 | + console.log('test'); |
| 2463 | + expect(mockedLog).toHaveBeenCalled(); |
| 2464 | + } |
| 2465 | + expect(jest.isMockFunction(console.log)).toBeFalsy(); |
| 2466 | + }); |
2464 | 2467 | });
|
2465 | 2468 | });
|
0 commit comments