Skip to content

Commit

Permalink
fix: correct instanceof for ModernFakeTimers and `LegacyFakeTimer…
Browse files Browse the repository at this point in the history
…s` methods (#11946)
  • Loading branch information
minijus committed Oct 15, 2021
1 parent 3674bbf commit 46c9c13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Fixes

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

### Chore & Maintenance

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/package.json
Expand Up @@ -16,7 +16,6 @@
"dependencies": {
"@jest/console": "^27.2.5",
"@jest/environment": "^27.2.5",
"@jest/fake-timers": "^27.2.5",
"@jest/globals": "^27.2.5",
"@jest/source-map": "^27.0.6",
"@jest/test-result": "^27.2.5",
Expand All @@ -43,6 +42,7 @@
"yargs": "^16.2.0"
},
"devDependencies": {
"@jest/fake-timers": "^27.2.5",
"@jest/test-utils": "^27.2.5",
"@types/exit": "^0.1.30",
"@types/glob": "^7.1.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -30,7 +30,7 @@ import type {
Module,
ModuleWrapper,
} from '@jest/environment';
import {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
import type {LegacyFakeTimers, ModernFakeTimers} from '@jest/fake-timers';
import type * as JestGlobals from '@jest/globals';
import type {SourceMapRegistry} from '@jest/source-map';
import type {RuntimeTransformResult, V8CoverageResult} from '@jest/test-result';
Expand Down Expand Up @@ -1963,7 +1963,7 @@ export default class Runtime {
getRealSystemTime: () => {
const fakeTimers = _getFakeTimers();

if (fakeTimers instanceof ModernFakeTimers) {
if (fakeTimers === this._environment.fakeTimersModern) {
return fakeTimers.getRealSystemTime();
} else {
throw new TypeError(
Expand All @@ -1984,7 +1984,7 @@ export default class Runtime {
runAllImmediates: () => {
const fakeTimers = _getFakeTimers();

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

if (fakeTimers instanceof ModernFakeTimers) {
if (fakeTimers === this._environment.fakeTimersModern) {
fakeTimers.setSystemTime(now);
} else {
throw new TypeError(
Expand Down

0 comments on commit 46c9c13

Please sign in to comment.