jest-util
Advanced tools
Comparing version 11.0.0 to 11.0.1
@@ -14,13 +14,13 @@ /** | ||
describe('FakeTimers', function() { | ||
var FakeTimers; | ||
describe('FakeTimers', () => { | ||
let FakeTimers; | ||
beforeEach(function() { | ||
beforeEach(() => { | ||
FakeTimers = require('../FakeTimers'); | ||
}); | ||
describe('construction', function() { | ||
describe('construction', () => { | ||
/* eslint-disable no-new */ | ||
it('installs setTimeout mock', function() { | ||
var global = {}; | ||
it('installs setTimeout mock', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -30,4 +30,4 @@ expect(global.setTimeout).not.toBe(undefined); | ||
it('installs clearTimeout mock', function() { | ||
var global = {}; | ||
it('installs clearTimeout mock', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -37,4 +37,4 @@ expect(global.clearTimeout).not.toBe(undefined); | ||
it('installs setInterval mock', function() { | ||
var global = {}; | ||
it('installs setInterval mock', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -44,4 +44,4 @@ expect(global.setInterval).not.toBe(undefined); | ||
it('installs clearInterval mock', function() { | ||
var global = {}; | ||
it('installs clearInterval mock', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -51,5 +51,5 @@ expect(global.clearInterval).not.toBe(undefined); | ||
it('mocks process.nextTick if on exists on global', function() { | ||
var origNextTick = function() {}; | ||
var global = { | ||
it('mocks process.nextTick if on exists on global', () => { | ||
const origNextTick = () => {}; | ||
const global = { | ||
process: { | ||
@@ -63,4 +63,4 @@ nextTick: origNextTick, | ||
it('doesn\'t mock process.nextTick if real impl isnt present', function() { | ||
var global = {}; | ||
it('doesn\'t mock process.nextTick if real impl isnt present', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -70,5 +70,5 @@ expect(global.process).toBe(undefined); | ||
it('mocks setImmediate if it exists on global', function() { | ||
var origSetImmediate = function() {}; | ||
var global = { | ||
it('mocks setImmediate if it exists on global', () => { | ||
const origSetImmediate = () => {}; | ||
const global = { | ||
setImmediate: origSetImmediate, | ||
@@ -80,6 +80,6 @@ }; | ||
it('mocks clearImmediate if setImmediate is on global', function() { | ||
var origSetImmediate = function() {}; | ||
var origClearImmediate = function() {}; | ||
var global = { | ||
it('mocks clearImmediate if setImmediate is on global', () => { | ||
const origSetImmediate = () => {}; | ||
const origClearImmediate = () => {}; | ||
const global = { | ||
setImmediate: origSetImmediate, | ||
@@ -92,4 +92,4 @@ clearImmediate: origClearImmediate, | ||
it('doesn\'t mock setImmediate if real impl isnt present', function() { | ||
var global = {}; | ||
it('doesn\'t mock setImmediate if real impl isnt present', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -99,4 +99,4 @@ expect(global.setImmediate).toBe(undefined); | ||
it('doesnt mock clearImmediate if real immediate isnt present', function() { | ||
var global = {}; | ||
it('doesnt mock clearImmediate if real immediate isnt present', () => { | ||
const global = {}; | ||
new FakeTimers(global); | ||
@@ -107,17 +107,17 @@ expect(global.clearImmediate).toBe(undefined); | ||
describe('runAllTicks', function() { | ||
it('runs all ticks, in order', function() { | ||
var global = { | ||
describe('runAllTicks', () => { | ||
it('runs all ticks, in order', () => { | ||
const global = { | ||
process: { | ||
nextTick: function() {}, | ||
nextTick: () => {}, | ||
}, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var runOrder = []; | ||
var mock1 = jest.genMockFn().mockImpl(function() { | ||
const runOrder = []; | ||
const mock1 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock1'); | ||
}); | ||
var mock2 = jest.genMockFn().mockImpl(function() { | ||
const mock2 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock2'); | ||
@@ -139,11 +139,11 @@ }); | ||
it('does nothing when no ticks have been scheduled', function() { | ||
var nextTick = jest.genMockFn(); | ||
var global = { | ||
it('does nothing when no ticks have been scheduled', () => { | ||
const nextTick = jest.genMockFn(); | ||
const global = { | ||
process: { | ||
nextTick: nextTick, | ||
nextTick, | ||
}, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
fakeTimers.runAllTicks(); | ||
@@ -154,12 +154,12 @@ | ||
it('only runs a scheduled callback once', function() { | ||
var global = { | ||
it('only runs a scheduled callback once', () => { | ||
const global = { | ||
process: { | ||
nextTick: function() {}, | ||
nextTick: () => {}, | ||
}, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.process.nextTick(mock1); | ||
@@ -175,6 +175,6 @@ expect(mock1.mock.calls.length).toBe(0); | ||
it('cancels a callback even from native nextTick', function() { | ||
var nativeNextTick = jest.genMockFn(); | ||
it('cancels a callback even from native nextTick', () => { | ||
const nativeNextTick = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
process: { | ||
@@ -185,5 +185,5 @@ nextTick: nativeNextTick, | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.process.nextTick(mock1); | ||
@@ -200,12 +200,12 @@ fakeTimers.runAllTicks(); | ||
it('cancels a callback even from native setImmediate', function() { | ||
var nativeSetImmediate = jest.genMockFn(); | ||
it('cancels a callback even from native setImmediate', () => { | ||
const nativeSetImmediate = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setImmediate: nativeSetImmediate, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setImmediate(mock1); | ||
@@ -221,6 +221,6 @@ fakeTimers.runAllImmediates(); | ||
it('doesnt run a tick callback if native nextTick already did', function() { | ||
var nativeNextTick = jest.genMockFn(); | ||
it('doesnt run a tick callback if native nextTick already did', () => { | ||
const nativeNextTick = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
process: { | ||
@@ -231,5 +231,5 @@ nextTick: nativeNextTick, | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.process.nextTick(mock1); | ||
@@ -246,12 +246,12 @@ | ||
it('doesnt run immediate if native setImmediate already did', function() { | ||
var nativeSetImmediate = jest.genMockFn(); | ||
it('doesnt run immediate if native setImmediate already did', () => { | ||
const nativeSetImmediate = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setImmediate: nativeSetImmediate, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setImmediate(mock1); | ||
@@ -268,12 +268,12 @@ | ||
it('native doesnt run immediate if fake already did', function() { | ||
var nativeSetImmediate = jest.genMockFn(); | ||
it('native doesnt run immediate if fake already did', () => { | ||
const nativeSetImmediate = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setImmediate: nativeSetImmediate, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setImmediate(mock1); | ||
@@ -291,10 +291,10 @@ | ||
it('throws before allowing infinite recursion', function() { | ||
var global = { | ||
it('throws before allowing infinite recursion', () => { | ||
const global = { | ||
process: { | ||
nextTick: function() {}, | ||
nextTick: () => {}, | ||
}, | ||
}; | ||
var fakeTimers = new FakeTimers(global, 100); | ||
const fakeTimers = new FakeTimers(global, 100); | ||
@@ -305,3 +305,3 @@ global.process.nextTick(function infinitelyRecursingCallback() { | ||
expect(function() { | ||
expect(() => { | ||
fakeTimers.runAllTicks(); | ||
@@ -315,18 +315,18 @@ }).toThrow(new Error( | ||
describe('runAllTimers', function() { | ||
it('runs all timers in order', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
describe('runAllTimers', () => { | ||
it('runs all timers in order', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var runOrder = []; | ||
var mock1 = jest.genMockFn().mockImpl(function() { | ||
const runOrder = []; | ||
const mock1 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock1'); | ||
}); | ||
var mock2 = jest.genMockFn().mockImpl(function() { | ||
const mock2 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock2'); | ||
}); | ||
var mock3 = jest.genMockFn().mockImpl(function() { | ||
const mock3 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock3'); | ||
}); | ||
var mock4 = jest.genMockFn().mockImpl(function() { | ||
const mock4 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock4'); | ||
@@ -338,3 +338,3 @@ }); | ||
global.setTimeout(mock3, 0); | ||
var intervalHandler = global.setInterval(function() { | ||
const intervalHandler = global.setInterval(() => { | ||
mock4(); | ||
@@ -348,17 +348,17 @@ global.clearInterval(intervalHandler); | ||
it('does nothing when no timers have been scheduled', function() { | ||
var nativeSetTimeout = jest.genMockFn(); | ||
var global = { | ||
it('does nothing when no timers have been scheduled', () => { | ||
const nativeSetTimeout = jest.genMockFn(); | ||
const global = { | ||
setTimeout: nativeSetTimeout, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
fakeTimers.runAllTimers(); | ||
}); | ||
it('only runs a setTimeout callback once (ever)', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('only runs a setTimeout callback once (ever)', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var fn = jest.genMockFn(); | ||
const fn = jest.genMockFn(); | ||
global.setTimeout(fn, 0); | ||
@@ -374,7 +374,7 @@ expect(fn.mock.calls.length).toBe(0); | ||
it('runs callbacks with arguments after the interval', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('runs callbacks with arguments after the interval', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var fn = jest.genMockFn(); | ||
const fn = jest.genMockFn(); | ||
global.setTimeout(fn, 0, 'mockArg1', 'mockArg2'); | ||
@@ -388,12 +388,12 @@ | ||
it('doesnt pass the callback to native setTimeout', function() { | ||
var nativeSetTimeout = jest.genMockFn(); | ||
it('doesnt pass the callback to native setTimeout', () => { | ||
const nativeSetTimeout = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setTimeout: nativeSetTimeout, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setTimeout(mock1, 0); | ||
@@ -406,5 +406,5 @@ | ||
it('throws before allowing infinite recursion', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global, 100); | ||
it('throws before allowing infinite recursion', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global, 100); | ||
@@ -415,3 +415,3 @@ global.setTimeout(function infinitelyRecursingCallback() { | ||
expect(function() { | ||
expect(() => { | ||
fakeTimers.runAllTimers(); | ||
@@ -425,18 +425,18 @@ }).toThrow(new Error( | ||
describe('runTimersToTime', function() { | ||
it('runs timers in order', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
describe('runTimersToTime', () => { | ||
it('runs timers in order', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var runOrder = []; | ||
var mock1 = jest.genMockFn().mockImpl(function() { | ||
const runOrder = []; | ||
const mock1 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock1'); | ||
}); | ||
var mock2 = jest.genMockFn().mockImpl(function() { | ||
const mock2 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock2'); | ||
}); | ||
var mock3 = jest.genMockFn().mockImpl(function() { | ||
const mock3 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock3'); | ||
}); | ||
var mock4 = jest.genMockFn().mockImpl(function() { | ||
const mock4 = jest.genMockFn().mockImpl(() => { | ||
runOrder.push('mock4'); | ||
@@ -448,3 +448,3 @@ }); | ||
global.setTimeout(mock3, 0); | ||
global.setInterval(function() { | ||
global.setInterval(() => { | ||
mock4(); | ||
@@ -474,5 +474,5 @@ }, 200); | ||
it('does nothing when no timers have been scheduled', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('does nothing when no timers have been scheduled', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
@@ -482,5 +482,5 @@ fakeTimers.runTimersToTime(100); | ||
it('throws before allowing infinite recursion', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global, 100); | ||
it('throws before allowing infinite recursion', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global, 100); | ||
@@ -491,3 +491,3 @@ global.setTimeout(function infinitelyRecursingCallback() { | ||
expect(function() { | ||
expect(() => { | ||
fakeTimers.runTimersToTime(50); | ||
@@ -501,8 +501,8 @@ }).toThrow(new Error( | ||
describe('reset', function() { | ||
it('resets all pending setTimeouts', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
describe('reset', () => { | ||
it('resets all pending setTimeouts', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setTimeout(mock1, 100); | ||
@@ -515,7 +515,7 @@ | ||
it('resets all pending setIntervals', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('resets all pending setIntervals', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setInterval(mock1, 200); | ||
@@ -528,12 +528,12 @@ | ||
it('resets all pending ticks callbacks & immediates', function() { | ||
var global = { | ||
setImmediate: function() {}, | ||
it('resets all pending ticks callbacks & immediates', () => { | ||
const global = { | ||
setImmediate: () => {}, | ||
process: { | ||
nextTick: function() {}, | ||
nextTick: () => {}, | ||
}, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.process.nextTick(mock1); | ||
@@ -548,7 +548,7 @@ global.setImmediate(mock1); | ||
it('resets current runTimersToTime time cursor', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('resets current runTimersToTime time cursor', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var mock1 = jest.genMockFn(); | ||
const mock1 = jest.genMockFn(); | ||
global.setTimeout(mock1, 100); | ||
@@ -565,13 +565,13 @@ fakeTimers.runTimersToTime(50); | ||
describe('runOnlyPendingTimers', function() { | ||
it('runs all timers in order', function() { | ||
var nativeSetImmediate = jest.genMockFn(); | ||
describe('runOnlyPendingTimers', () => { | ||
it('runs all timers in order', () => { | ||
const nativeSetImmediate = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setImmediate: nativeSetImmediate, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
var runOrder = []; | ||
const runOrder = []; | ||
@@ -588,7 +588,7 @@ global.setTimeout(function cb() { | ||
global.setInterval(function() { | ||
global.setInterval(() => { | ||
runOrder.push('mock3'); | ||
}, 200); | ||
global.setImmediate(function() { | ||
global.setImmediate(() => { | ||
runOrder.push('mock4'); | ||
@@ -618,9 +618,9 @@ }); | ||
it('does not run timers that were cleared in another timer', function() { | ||
var global = {}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('does not run timers that were cleared in another timer', () => { | ||
const global = {}; | ||
const fakeTimers = new FakeTimers(global); | ||
var fn = jest.genMockFn(); | ||
var timer = global.setTimeout(fn, 10); | ||
global.setTimeout(function() { | ||
const fn = jest.genMockFn(); | ||
const timer = global.setTimeout(fn, 10); | ||
global.setTimeout(() => { | ||
global.clearTimeout(timer); | ||
@@ -634,10 +634,10 @@ }, 0); | ||
describe('runWithRealTimers', function() { | ||
it('executes callback with native timers', function() { | ||
var nativeClearInterval = jest.genMockFn(); | ||
var nativeClearTimeout = jest.genMockFn(); | ||
var nativeSetInterval = jest.genMockFn(); | ||
var nativeSetTimeout = jest.genMockFn(); | ||
describe('runWithRealTimers', () => { | ||
it('executes callback with native timers', () => { | ||
const nativeClearInterval = jest.genMockFn(); | ||
const nativeClearTimeout = jest.genMockFn(); | ||
const nativeSetInterval = jest.genMockFn(); | ||
const nativeSetTimeout = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
clearInterval: nativeClearInterval, | ||
@@ -648,6 +648,6 @@ clearTimeout: nativeClearTimeout, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
// clearInterval() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.clearInterval(); | ||
@@ -659,3 +659,3 @@ }); | ||
// clearTimeout() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.clearTimeout(); | ||
@@ -667,3 +667,3 @@ }); | ||
// setInterval() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.setInterval(); | ||
@@ -675,3 +675,3 @@ }); | ||
// setTimeout() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.setTimeout(); | ||
@@ -683,10 +683,10 @@ }); | ||
it('resets mock timers after executing callback', function() { | ||
var nativeClearInterval = jest.genMockFn(); | ||
var nativeClearTimeout = jest.genMockFn(); | ||
var nativeSetInterval = jest.genMockFn(); | ||
var nativeSetTimeout = jest.genMockFn(); | ||
it('resets mock timers after executing callback', () => { | ||
const nativeClearInterval = jest.genMockFn(); | ||
const nativeClearTimeout = jest.genMockFn(); | ||
const nativeSetInterval = jest.genMockFn(); | ||
const nativeSetTimeout = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
clearInterval: nativeClearInterval, | ||
@@ -697,6 +697,6 @@ clearTimeout: nativeClearTimeout, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
// clearInterval() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.clearInterval(); | ||
@@ -712,3 +712,3 @@ }); | ||
// clearTimeout() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.clearTimeout(); | ||
@@ -724,3 +724,3 @@ }); | ||
// setInterval() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.setInterval(); | ||
@@ -736,3 +736,3 @@ }); | ||
// setTimeout() | ||
fakeTimers.runWithRealTimers(function() { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.setTimeout(); | ||
@@ -748,9 +748,9 @@ }); | ||
it('resets mock timer functions even if callback throws', function() { | ||
var nativeSetTimeout = jest.genMockFn(); | ||
var global = {setTimeout: nativeSetTimeout}; | ||
var fakeTimers = new FakeTimers(global); | ||
it('resets mock timer functions even if callback throws', () => { | ||
const nativeSetTimeout = jest.genMockFn(); | ||
const global = {setTimeout: nativeSetTimeout}; | ||
const fakeTimers = new FakeTimers(global); | ||
expect(function() { | ||
fakeTimers.runWithRealTimers(function() { | ||
expect(() => { | ||
fakeTimers.runWithRealTimers(() => { | ||
global.setTimeout(); | ||
@@ -769,10 +769,10 @@ throw new Error('test'); | ||
describe('useRealTimers', function() { | ||
it('resets native timer APIs', function() { | ||
var nativeSetTimeout = jest.genMockFn(); | ||
var nativeSetInterval = jest.genMockFn(); | ||
var nativeClearTimeout = jest.genMockFn(); | ||
var nativeClearInterval = jest.genMockFn(); | ||
describe('useRealTimers', () => { | ||
it('resets native timer APIs', () => { | ||
const nativeSetTimeout = jest.genMockFn(); | ||
const nativeSetInterval = jest.genMockFn(); | ||
const nativeClearTimeout = jest.genMockFn(); | ||
const nativeClearInterval = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setTimeout: nativeSetTimeout, | ||
@@ -783,3 +783,3 @@ setInterval: nativeSetInterval, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
@@ -801,9 +801,9 @@ // Ensure that fakeTimers has overridden the native timer APIs | ||
it('resets native process.nextTick when present', function() { | ||
var nativeProcessNextTick = jest.genMockFn(); | ||
it('resets native process.nextTick when present', () => { | ||
const nativeProcessNextTick = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
process: {nextTick: nativeProcessNextTick}, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
@@ -819,11 +819,11 @@ // Ensure that fakeTimers has overridden the native timer APIs | ||
it('resets native setImmediate when present', function() { | ||
var nativeSetImmediate = jest.genMockFn(); | ||
var nativeClearImmediate = jest.genMockFn(); | ||
it('resets native setImmediate when present', () => { | ||
const nativeSetImmediate = jest.genMockFn(); | ||
const nativeClearImmediate = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setImmediate: nativeSetImmediate, | ||
clearImmediate: nativeClearImmediate, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
@@ -842,10 +842,10 @@ // Ensure that fakeTimers has overridden the native timer APIs | ||
describe('useFakeTimers', function() { | ||
it('resets mock timer APIs', function() { | ||
var nativeSetTimeout = jest.genMockFn(); | ||
var nativeSetInterval = jest.genMockFn(); | ||
var nativeClearTimeout = jest.genMockFn(); | ||
var nativeClearInterval = jest.genMockFn(); | ||
describe('useFakeTimers', () => { | ||
it('resets mock timer APIs', () => { | ||
const nativeSetTimeout = jest.genMockFn(); | ||
const nativeSetInterval = jest.genMockFn(); | ||
const nativeClearTimeout = jest.genMockFn(); | ||
const nativeClearInterval = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setTimeout: nativeSetTimeout, | ||
@@ -856,3 +856,3 @@ setInterval: nativeSetInterval, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
fakeTimers.useRealTimers(); | ||
@@ -875,9 +875,9 @@ | ||
it('resets mock process.nextTick when present', function() { | ||
var nativeProcessNextTick = jest.genMockFn(); | ||
it('resets mock process.nextTick when present', () => { | ||
const nativeProcessNextTick = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
process: {nextTick: nativeProcessNextTick}, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
fakeTimers.useRealTimers(); | ||
@@ -894,11 +894,11 @@ | ||
it('resets mock setImmediate when present', function() { | ||
var nativeSetImmediate = jest.genMockFn(); | ||
var nativeClearImmediate = jest.genMockFn(); | ||
it('resets mock setImmediate when present', () => { | ||
const nativeSetImmediate = jest.genMockFn(); | ||
const nativeClearImmediate = jest.genMockFn(); | ||
var global = { | ||
const global = { | ||
setImmediate: nativeSetImmediate, | ||
clearImmediate: nativeClearImmediate, | ||
}; | ||
var fakeTimers = new FakeTimers(global); | ||
const fakeTimers = new FakeTimers(global); | ||
fakeTimers.useRealTimers(); | ||
@@ -905,0 +905,0 @@ |
@@ -82,5 +82,5 @@ /** | ||
clearAllTimers() { | ||
this._immediates.forEach(function(immediate) { | ||
this._fakeClearImmediate(immediate.uuid); | ||
}, this); | ||
this._immediates.forEach( | ||
immediate => this._fakeClearImmediate(immediate.uuid) | ||
); | ||
for (const uuid in this._timers) { | ||
@@ -194,5 +194,3 @@ delete this._timers[uuid]; | ||
Object.keys(timers) | ||
.sort(function(left, right) { | ||
return timers[left].expiry - timers[right].expiry; | ||
}) | ||
.sort((left, right) => timers[left].expiry - timers[right].expiry) | ||
.forEach(this._runTimerHandle, this); | ||
@@ -347,9 +345,7 @@ } | ||
uuid, | ||
callback: function() { | ||
return callback.apply(null, args); | ||
}, | ||
callback: () => callback.apply(null, args), | ||
}); | ||
const cancelledTicks = this._cancelledTicks; | ||
this._originalTimerAPIs.nextTick(function() { | ||
this._originalTimerAPIs.nextTick(() => { | ||
if (!cancelledTicks.hasOwnProperty(uuid)) { | ||
@@ -373,9 +369,7 @@ // Callback may throw, so update the map prior calling. | ||
uuid, | ||
callback: function() { | ||
return callback.apply(null, args); | ||
}, | ||
callback: () => callback.apply(null, args), | ||
}); | ||
const cancelledImmediates = this._cancelledImmediates; | ||
this._originalTimerAPIs.setImmediate(function() { | ||
this._originalTimerAPIs.setImmediate(() => { | ||
if (!cancelledImmediates.hasOwnProperty(uuid)) { | ||
@@ -405,5 +399,3 @@ // Callback may throw, so update the map prior calling. | ||
type: 'interval', | ||
callback: function() { | ||
return callback.apply(null, args); | ||
}, | ||
callback: () => callback.apply(null, args), | ||
expiry: this._now + intervalDelay, | ||
@@ -430,5 +422,3 @@ interval: intervalDelay, | ||
type: 'timeout', | ||
callback: function() { | ||
return callback.apply(null, args); | ||
}, | ||
callback: () => callback.apply(null, args), | ||
expiry: this._now + delay, | ||
@@ -435,0 +425,0 @@ interval: null, |
@@ -47,4 +47,4 @@ /** | ||
return done => { | ||
var promise = promiseFn(); | ||
var fail = done.fail ? done.fail : err => { throw err; }; | ||
const promise = promiseFn(); | ||
const fail = done.fail ? done.fail : err => { throw err; }; | ||
@@ -51,0 +51,0 @@ try { |
{ | ||
"name": "jest-util", | ||
"version": "11.0.0", | ||
"version": "11.0.1", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
52477
1462