forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fakeTimersLegacy.test.ts
67 lines (56 loc) · 2.03 KB
/
fakeTimersLegacy.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import runJest from '../runJest';
describe('enableGlobally', () => {
test('enables legacy fake timers from Jest config', () => {
const result = runJest('fake-timers-legacy/enable-globally');
expect(result.exitCode).toBe(0);
});
});
describe('legacyFakeTimers', () => {
test('toggles legacy fake timers from Jest config', () => {
const result = runJest('fake-timers-legacy/enable-legacy-fake-timers');
expect(result.exitCode).toBe(0);
});
});
describe('useFakeTimers', () => {
test('enables legacy fake timers from Jest object', () => {
const result = runJest('fake-timers-legacy/use-legacy-fake-timers');
expect(result.exitCode).toBe(0);
});
});
describe('requestAnimationFrame', () => {
test('fakes requestAnimationFrame', () => {
const result = runJest('fake-timers-legacy/request-animation-frame');
expect(result.stderr).toMatch('requestAnimationFrame test');
expect(result.exitCode).toBe(0);
});
});
describe('setImmediate', () => {
test('fakes setImmediate', () => {
const result = runJest('fake-timers-legacy/set-immediate');
expect(result.stderr).toMatch('setImmediate test');
expect(result.exitCode).toBe(0);
});
});
describe('useRealTimers', () => {
test('restores timers to the native implementation', () => {
const result = runJest('fake-timers-legacy/use-real-timers');
expect(result.stdout).toMatch('APIs are not mocked with fake timers.');
expect(result.exitCode).toBe(0);
});
});
describe('when mocks are reset', () => {
test('calling resetAllMocks does not break tests', () => {
const result = runJest('fake-timers-legacy/reset-all-mocks');
expect(result.exitCode).toBe(0);
});
test('setting resetMocks in Jest config does not break tests', () => {
const result = runJest('fake-timers-legacy/reset-mocks');
expect(result.exitCode).toBe(0);
});
});