diff --git a/packages/jest-util/src/__tests__/__snapshots__/fake_timers.test.js.snap b/packages/jest-util/src/__tests__/__snapshots__/fake_timers.test.js.snap index 235d2ba741f5..39cc8dd4ad64 100644 --- a/packages/jest-util/src/__tests__/__snapshots__/fake_timers.test.js.snap +++ b/packages/jest-util/src/__tests__/__snapshots__/fake_timers.test.js.snap @@ -1,7 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FakeTimers runAllTimers warns when trying to advance timers while real timers are used 1`] = ` -"A function to advance timers was called but the timers API is not mocked with fake timers. Call \`jest.useFakeTimers()\` in this test or enable fake timers globally by setting \`\\"timers\\": \\"fake\\"\` in the configuration file. This warning is likely a result of a default configuration change in Jest 15. - -Release Blog Post: https://facebook.github.io/jest/blog/2016/09/01/jest-15.html" -`; +exports[`FakeTimers runAllTimers warns when trying to advance timers while real timers are used 1`] = `"A function to advance timers was called but the timers API is not mocked with fake timers. Call \`jest.useFakeTimers()\` in this test or enable fake timers globally by setting \`\\"timers\\": \\"fake\\"\` in the configuration file"`; diff --git a/packages/jest-util/src/__tests__/fake_timers.test.js b/packages/jest-util/src/__tests__/fake_timers.test.js index b59e0e00be3f..c5c0060f6ac3 100644 --- a/packages/jest-util/src/__tests__/fake_timers.test.js +++ b/packages/jest-util/src/__tests__/fake_timers.test.js @@ -28,28 +28,28 @@ describe('FakeTimers', () => { describe('construction', () => { /* eslint-disable no-new */ it('installs setTimeout mock', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); expect(global.setTimeout).not.toBe(undefined); }); it('installs clearTimeout mock', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); expect(global.clearTimeout).not.toBe(undefined); }); it('installs setInterval mock', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); expect(global.setInterval).not.toBe(undefined); }); it('installs clearInterval mock', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); expect(global.clearInterval).not.toBe(undefined); @@ -58,6 +58,7 @@ describe('FakeTimers', () => { it('mocks process.nextTick if it exists on global', () => { const origNextTick = () => {}; const global = { + Date, process: { nextTick: origNextTick, }, @@ -70,6 +71,7 @@ describe('FakeTimers', () => { it('mocks setImmediate if it exists on global', () => { const origSetImmediate = () => {}; const global = { + Date, process, setImmediate: origSetImmediate, }; @@ -82,6 +84,7 @@ describe('FakeTimers', () => { const origSetImmediate = () => {}; const origClearImmediate = () => {}; const global = { + Date, clearImmediate: origClearImmediate, process, setImmediate: origSetImmediate, @@ -95,6 +98,7 @@ describe('FakeTimers', () => { describe('runAllTicks', () => { it('runs all ticks, in order', () => { const global = { + Date, process: { nextTick: () => {}, }, @@ -123,6 +127,7 @@ describe('FakeTimers', () => { it('does nothing when no ticks have been scheduled', () => { const nextTick = jest.genMockFn(); const global = { + Date, process: { nextTick, }, @@ -137,6 +142,7 @@ describe('FakeTimers', () => { it('only runs a scheduled callback once', () => { const global = { + Date, process: { nextTick: () => {}, }, @@ -160,6 +166,7 @@ describe('FakeTimers', () => { const nativeNextTick = jest.genMockFn(); const global = { + Date, process: { nextTick: nativeNextTick, }, @@ -184,6 +191,7 @@ describe('FakeTimers', () => { const nativeSetImmediate = jest.genMockFn(); const global = { + Date, process, setImmediate: nativeSetImmediate, }; @@ -206,6 +214,7 @@ describe('FakeTimers', () => { const nativeNextTick = jest.genMockFn(); const global = { + Date, process: { nextTick: nativeNextTick, }, @@ -230,6 +239,7 @@ describe('FakeTimers', () => { const nativeSetImmediate = jest.genMockFn(); const global = { + Date, process, setImmediate: nativeSetImmediate, }; @@ -253,6 +263,7 @@ describe('FakeTimers', () => { const nativeSetImmediate = jest.genMockFn(); const global = { + Date, process, setImmediate: nativeSetImmediate, }; @@ -275,6 +286,7 @@ describe('FakeTimers', () => { it('throws before allowing infinite recursion', () => { const global = { + Date, process: { nextTick: () => {}, }, @@ -306,7 +318,7 @@ describe('FakeTimers', () => { describe('runAllTimers', () => { it('runs all timers in order', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -349,6 +361,7 @@ describe('FakeTimers', () => { it('does nothing when no timers have been scheduled', () => { const nativeSetTimeout = jest.genMockFn(); const global = { + Date, process, setTimeout: nativeSetTimeout, }; @@ -359,7 +372,7 @@ describe('FakeTimers', () => { }); it('only runs a setTimeout callback once (ever)', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -375,7 +388,7 @@ describe('FakeTimers', () => { }); it('runs callbacks with arguments after the interval', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -390,6 +403,7 @@ describe('FakeTimers', () => { const nativeSetTimeout = jest.genMockFn(); const global = { + Date, process, setTimeout: nativeSetTimeout, }; @@ -406,7 +420,7 @@ describe('FakeTimers', () => { }); it('throws before allowing infinite recursion', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({ global, maxLoops: 100, @@ -423,14 +437,13 @@ describe('FakeTimers', () => { timers.runAllTimers(); }).toThrow( new Error( - "Ran 100 timers, and there are still more! Assuming we've hit an " + - 'infinite recursion and bailing out...', + 'Aborting after running 100 timers, assuming an infinite loop!', ), ); }); it('also clears ticks', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -447,7 +460,7 @@ describe('FakeTimers', () => { describe('advanceTimersByTime', () => { it('runs timers in order', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -486,7 +499,7 @@ describe('FakeTimers', () => { }); it('does nothing when no timers have been scheduled', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -494,7 +507,7 @@ describe('FakeTimers', () => { }); it('throws before allowing infinite recursion', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({ global, maxLoops: 100, @@ -520,7 +533,7 @@ describe('FakeTimers', () => { describe('reset', () => { it('resets all pending setTimeouts', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -533,7 +546,7 @@ describe('FakeTimers', () => { }); it('resets all pending setIntervals', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -547,6 +560,7 @@ describe('FakeTimers', () => { it('resets all pending ticks callbacks & immediates', () => { const global = { + Date, process: { nextTick: () => {}, }, @@ -566,7 +580,7 @@ describe('FakeTimers', () => { }); it('resets current advanceTimersByTime time cursor', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -587,6 +601,7 @@ describe('FakeTimers', () => { const nativeSetImmediate = jest.genMockFn(); const global = { + Date, process, setImmediate: nativeSetImmediate, }; @@ -638,7 +653,7 @@ describe('FakeTimers', () => { }); it('does not run timers that were cleared in another timer', () => { - const global = {process}; + const global = {Date, process}; const timers = new FakeTimers({global, moduleMocker, timerConfig}); timers.useFakeTimers(); @@ -661,6 +676,7 @@ describe('FakeTimers', () => { const nativeSetTimeout = jest.genMockFn(); const global = { + Date, clearInterval: nativeClearInterval, clearTimeout: nativeClearTimeout, process, @@ -706,6 +722,7 @@ describe('FakeTimers', () => { const nativeSetTimeout = jest.genMockFn(); const global = { + Date, clearInterval: nativeClearInterval, clearTimeout: nativeClearTimeout, process, @@ -763,6 +780,7 @@ describe('FakeTimers', () => { it('resets mock timer functions even if callback throws', () => { const nativeSetTimeout = jest.genMockFn(); const global = { + Date, process, setTimeout: nativeSetTimeout, }; @@ -792,6 +810,7 @@ describe('FakeTimers', () => { const nativeClearInterval = jest.genMockFn(); const global = { + Date, clearInterval: nativeClearInterval, clearTimeout: nativeClearTimeout, process, @@ -820,6 +839,7 @@ describe('FakeTimers', () => { const nativeProcessNextTick = jest.genMockFn(); const global = { + Date, process: {nextTick: nativeProcessNextTick}, }; const timers = new FakeTimers({global, moduleMocker, timerConfig}); @@ -839,6 +859,7 @@ describe('FakeTimers', () => { const nativeClearImmediate = jest.genMockFn(); const global = { + Date, clearImmediate: nativeClearImmediate, process, setImmediate: nativeSetImmediate, @@ -866,6 +887,7 @@ describe('FakeTimers', () => { const nativeClearInterval = jest.genMockFn(); const global = { + Date, clearInterval: nativeClearInterval, clearTimeout: nativeClearTimeout, process, @@ -894,6 +916,7 @@ describe('FakeTimers', () => { const nativeProcessNextTick = jest.genMockFn(); const global = { + Date, process: {nextTick: nativeProcessNextTick}, }; const timers = new FakeTimers({global, moduleMocker, timerConfig}); @@ -913,6 +936,7 @@ describe('FakeTimers', () => { const nativeClearImmediate = jest.genMockFn(); const global = { + Date, clearImmediate: nativeClearImmediate, process, setImmediate: nativeSetImmediate,