Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
([#5914](https://github.com/facebook/jest/pull/5914))
* `[jest-regex-util]` Fix handling regex symbols in tests path on Windows
([#5941](https://github.com/facebook/jest/pull/5941))
* `[jest-util]` Fix handling of NaN/Infinity in mock timer delay
([#5966](https://github.com/facebook/jest/pull/5966))
* `[jest-resolve]` Generalise test for package main entries equivalent to ".".
([#5968)](https://github.com/facebook/jest/pull/5968)

Expand Down
15 changes: 13 additions & 2 deletions packages/jest-util/src/__tests__/fake_timers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,17 +315,28 @@ describe('FakeTimers', () => {
const mock2 = jest.fn(() => runOrder.push('mock2'));
const mock3 = jest.fn(() => runOrder.push('mock3'));
const mock4 = jest.fn(() => runOrder.push('mock4'));
const mock5 = jest.fn(() => runOrder.push('mock5'));
const mock6 = jest.fn(() => runOrder.push('mock6'));

global.setTimeout(mock1, 100);
global.setTimeout(mock2, 0);
global.setTimeout(mock2, NaN);
global.setTimeout(mock3, 0);
const intervalHandler = global.setInterval(() => {
mock4();
global.clearInterval(intervalHandler);
}, 200);
global.setTimeout(mock5, Infinity);
global.setTimeout(mock6, -Infinity);

timers.runAllTimers();
expect(runOrder).toEqual(['mock2', 'mock3', 'mock1', 'mock4']);
expect(runOrder).toEqual([
'mock2',
'mock3',
'mock5',
'mock6',
'mock1',
'mock4',
]);
});

it('warns when trying to advance timers while real timers are used', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/jest-util/src/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,7 @@ export default class FakeTimers<TimerRef> {
return null;
}

if (delay == null) {
delay = 0;
}
delay = Number(delay) | 0;

const args = [];
for (let ii = 2, ll = arguments.length; ii < ll; ii++) {
Expand Down