Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of NaN/Infinity in mock timer delay, #5960 #5966

Merged
merged 6 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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))

### Chore & Maintenance

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