Skip to content

Commit 46c9c13

Browse files
authored
fix: correct instanceof for ModernFakeTimers and LegacyFakeTimers methods (#11946)
1 parent 3674bbf commit 46c9c13

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- `[jest-runtime]` Ensure absolute paths can be resolved within test modules ([11943](https://github.com/facebook/jest/pull/11943))
8+
- `[jest-runtime]` Fix `instanceof` for `ModernFakeTimers` and `LegacyFakeTimers` methods ([#11946](https://github.com/facebook/jest/pull/11946))
89

910
### Chore & Maintenance
1011

packages/jest-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"dependencies": {
1717
"@jest/console": "^27.2.5",
1818
"@jest/environment": "^27.2.5",
19-
"@jest/fake-timers": "^27.2.5",
2019
"@jest/globals": "^27.2.5",
2120
"@jest/source-map": "^27.0.6",
2221
"@jest/test-result": "^27.2.5",
@@ -43,6 +42,7 @@
4342
"yargs": "^16.2.0"
4443
},
4544
"devDependencies": {
45+
"@jest/fake-timers": "^27.2.5",
4646
"@jest/test-utils": "^27.2.5",
4747
"@types/exit": "^0.1.30",
4848
"@types/glob": "^7.1.1",

packages/jest-runtime/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import type {
3030
Module,
3131
ModuleWrapper,
3232
} from '@jest/environment';
33-
import {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
33+
import type {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
3434
import type * as JestGlobals from '@jest/globals';
3535
import type {SourceMapRegistry} from '@jest/source-map';
3636
import type {RuntimeTransformResult, V8CoverageResult} from '@jest/test-result';
@@ -1963,7 +1963,7 @@ export default class Runtime {
19631963
getRealSystemTime: () => {
19641964
const fakeTimers = _getFakeTimers();
19651965

1966-
if (fakeTimers instanceof ModernFakeTimers) {
1966+
if (fakeTimers === this._environment.fakeTimersModern) {
19671967
return fakeTimers.getRealSystemTime();
19681968
} else {
19691969
throw new TypeError(
@@ -1984,7 +1984,7 @@ export default class Runtime {
19841984
runAllImmediates: () => {
19851985
const fakeTimers = _getFakeTimers();
19861986

1987-
if (fakeTimers instanceof LegacyFakeTimers) {
1987+
if (fakeTimers === this._environment.fakeTimers) {
19881988
fakeTimers.runAllImmediates();
19891989
} else {
19901990
throw new TypeError(
@@ -2000,7 +2000,7 @@ export default class Runtime {
20002000
setSystemTime: (now?: number | Date) => {
20012001
const fakeTimers = _getFakeTimers();
20022002

2003-
if (fakeTimers instanceof ModernFakeTimers) {
2003+
if (fakeTimers === this._environment.fakeTimersModern) {
20042004
fakeTimers.setSystemTime(now);
20052005
} else {
20062006
throw new TypeError(

0 commit comments

Comments
 (0)