Skip to content

Commit

Permalink
simplify check
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 15, 2021
1 parent f1602d0 commit e4b2867
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ export default class Runtime {
getRealSystemTime: () => {
const fakeTimers = _getFakeTimers();

if (this._areModernFakeTimers(fakeTimers)) {
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 (!this._areModernFakeTimers(fakeTimers)) {
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 (this._areModernFakeTimers(fakeTimers)) {
if (fakeTimers === this._environment.fakeTimersModern) {
fakeTimers.setSystemTime(now);
} else {
throw new TypeError(
Expand All @@ -2018,12 +2018,6 @@ export default class Runtime {
return jestObject;
}

private _areModernFakeTimers(
fakeTimers: ModernFakeTimers | LegacyFakeTimers<unknown>,
): fakeTimers is ModernFakeTimers {
return typeof (fakeTimers as ModernFakeTimers).setSystemTime === 'function';
}

private _logFormattedReferenceError(errorMessage: string) {
const testPath = this._testPath
? ` From ${slash(path.relative(this._config.rootDir, this._testPath))}.`
Expand Down

0 comments on commit e4b2867

Please sign in to comment.