Skip to content

Commit

Permalink
Fix timers: reference can be null (#4855)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjesun authored and cpojer committed Nov 7, 2017
1 parent 8901f87 commit 00114dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/jest-environment-node/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class NodeEnvironment {
},
});

const timerRefToId = (timer: Timer) => timer.id;
const timerRefToId = (timer: Timer): ?number => {
return (timer && timer.id) || null;
};

const timerConfig = {
idToRef: timerIdToRef,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-util/src/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type TimerAPI = {

type TimerConfig<Ref> = {|
idToRef: (id: number) => Ref,
refToId: (ref: Ref) => number,
refToId: (ref: Ref) => ?number,
|};

const MS_IN_A_YEAR = 31536000000;
Expand Down Expand Up @@ -387,7 +387,7 @@ export default class FakeTimers<TimerRef> {
_fakeClearTimer(timerRef: TimerRef) {
const uuid = this._timerConfig.refToId(timerRef);

if (this._timers.hasOwnProperty(uuid)) {
if (uuid && this._timers.hasOwnProperty(uuid)) {
delete this._timers[String(uuid)];
}
}
Expand Down

0 comments on commit 00114dd

Please sign in to comment.