diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 626338fe..f6e2d8dc 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -791,28 +791,26 @@ getJasmineRequireObj().Spec = function(j$) { }; Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) { - const self = this; - const onStart = { - fn: function(done) { - self.timer.start(); - self.onStart(self, done); + fn: done => { + this.timer.start(); + this.onStart(this, done); } }; const complete = { - fn: function(done) { - if (self.autoCleanClosures) { - self.queueableFn.fn = null; + fn: done => { + if (this.autoCleanClosures) { + this.queueableFn.fn = null; } - self.result.status = self.status(excluded, failSpecWithNoExp); - self.result.duration = self.timer.elapsed(); + this.result.status = this.status(excluded, failSpecWithNoExp); + this.result.duration = this.timer.elapsed(); - if (self.result.status !== 'failed') { - self.result.debugLogs = null; + if (this.result.status !== 'failed') { + this.result.debugLogs = null; } - self.resultCallback(self.result, done); + this.resultCallback(this.result, done); }, type: 'specCleanup' }; @@ -822,24 +820,22 @@ getJasmineRequireObj().Spec = function(j$) { const runnerConfig = { isLeaf: true, queueableFns: [...fns.befores, this.queueableFn, ...fns.afters], - onException: function() { - self.handleException.apply(self, arguments); - }, - onMultipleDone: function() { + onException: e => this.handleException(e), + onMultipleDone: () => { // Issue a deprecation. Include the context ourselves and pass // ignoreRunnable: true, since getting here always means that we've already // moved on and the current runnable isn't the one that caused the problem. - self.onLateError( + this.onLateError( new Error( 'An asynchronous spec, beforeEach, or afterEach function called its ' + "'done' callback more than once.\n(in spec: " + - self.getFullName() + + this.getFullName() + ')' ) ); }, - onComplete: function() { - if (self.result.status === 'failed') { + onComplete: () => { + if (this.result.status === 'failed') { onComplete(new j$.StopExecutionError('spec failed')); } else { onComplete(); @@ -3366,24 +3362,23 @@ getJasmineRequireObj().Clock = function() { * @hideconstructor */ function Clock(global, delayedFunctionSchedulerFactory, mockDate) { - const self = this, - realTimingFunctions = { - setTimeout: global.setTimeout, - clearTimeout: global.clearTimeout, - setInterval: global.setInterval, - clearInterval: global.clearInterval - }, - fakeTimingFunctions = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setInterval: setInterval, - clearInterval: clearInterval - }; + const realTimingFunctions = { + setTimeout: global.setTimeout, + clearTimeout: global.clearTimeout, + setInterval: global.setInterval, + clearInterval: global.clearInterval + }; + const fakeTimingFunctions = { + setTimeout: setTimeout, + clearTimeout: clearTimeout, + setInterval: setInterval, + clearInterval: clearInterval + }; let installed = false; let delayedFunctionScheduler; let timer; - self.FakeTimeout = FakeTimeout; + this.FakeTimeout = FakeTimeout; /** * Install the mock clock over the built-in methods. @@ -3392,7 +3387,7 @@ getJasmineRequireObj().Clock = function() { * @function * @return {Clock} */ - self.install = function() { + this.install = function() { if (!originalTimingFunctionsIntact()) { throw new Error( 'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?' @@ -3403,7 +3398,7 @@ getJasmineRequireObj().Clock = function() { delayedFunctionScheduler = delayedFunctionSchedulerFactory(); installed = true; - return self; + return this; }; /** @@ -3412,7 +3407,7 @@ getJasmineRequireObj().Clock = function() { * @since 2.0.0 * @function */ - self.uninstall = function() { + this.uninstall = function() { delayedFunctionScheduler = null; mockDate.uninstall(); replace(global, realTimingFunctions); @@ -3430,7 +3425,7 @@ getJasmineRequireObj().Clock = function() { * @function * @param {Function} closure The function to be called. */ - self.withMock = function(closure) { + this.withMock = function(closure) { this.install(); try { closure(); @@ -3446,29 +3441,29 @@ getJasmineRequireObj().Clock = function() { * @function * @param {Date} [initialDate=now] The `Date` to provide. */ - self.mockDate = function(initialDate) { + this.mockDate = function(initialDate) { mockDate.install(initialDate); }; - self.setTimeout = function(fn, delay, params) { + this.setTimeout = function(fn, delay, params) { return Function.prototype.apply.apply(timer.setTimeout, [ global, arguments ]); }; - self.setInterval = function(fn, delay, params) { + this.setInterval = function(fn, delay, params) { return Function.prototype.apply.apply(timer.setInterval, [ global, arguments ]); }; - self.clearTimeout = function(id) { + this.clearTimeout = function(id) { return Function.prototype.call.apply(timer.clearTimeout, [global, id]); }; - self.clearInterval = function(id) { + this.clearInterval = function(id) { return Function.prototype.call.apply(timer.clearInterval, [global, id]); }; @@ -3479,7 +3474,7 @@ getJasmineRequireObj().Clock = function() { * @function * @param {int} millis The number of milliseconds to tick. */ - self.tick = function(millis) { + this.tick = function(millis) { if (installed) { delayedFunctionScheduler.tick(millis, function(millis) { mockDate.tick(millis); @@ -3491,7 +3486,7 @@ getJasmineRequireObj().Clock = function() { } }; - return self; + return this; function originalTimingFunctionsIntact() { return ( @@ -3636,21 +3631,20 @@ getJasmineRequireObj().CompleteOnFirstErrorSkipPolicy = function(j$) { getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { function DelayedFunctionScheduler() { - const self = this; - const scheduledLookup = []; - const scheduledFunctions = {}; - let currentTime = 0; - let delayedFnCount = 0; - let deletedKeys = []; + this.scheduledLookup_ = []; + this.scheduledFunctions_ = {}; + this.currentTime_ = 0; + this.delayedFnCount_ = 0; + this.deletedKeys_ = []; - self.tick = function(millis, tickDate) { + this.tick = function(millis, tickDate) { millis = millis || 0; - const endTime = currentTime + millis; + const endTime = this.currentTime_ + millis; - runScheduledFunctions(endTime, tickDate); + this.runScheduledFunctions_(endTime, tickDate); }; - self.scheduleFunction = function( + this.scheduleFunction = function( funcToCall, millis, params, @@ -3669,8 +3663,8 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { } millis = millis || 0; - timeoutKey = timeoutKey || ++delayedFnCount; - runAtMillis = runAtMillis || currentTime + millis; + timeoutKey = timeoutKey || ++this.delayedFnCount_; + runAtMillis = runAtMillis || this.currentTime_ + millis; const funcToSchedule = { runAtMillis: runAtMillis, @@ -3681,12 +3675,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { millis: millis }; - if (runAtMillis in scheduledFunctions) { - scheduledFunctions[runAtMillis].push(funcToSchedule); + if (runAtMillis in this.scheduledFunctions_) { + this.scheduledFunctions_[runAtMillis].push(funcToSchedule); } else { - scheduledFunctions[runAtMillis] = [funcToSchedule]; - scheduledLookup.push(runAtMillis); - scheduledLookup.sort(function(a, b) { + this.scheduledFunctions_[runAtMillis] = [funcToSchedule]; + this.scheduledLookup_.push(runAtMillis); + this.scheduledLookup_.sort(function(a, b) { return a - b; }); } @@ -3694,19 +3688,19 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { return timeoutKey; }; - self.removeFunctionWithId = function(timeoutKey) { - deletedKeys.push(timeoutKey); + this.removeFunctionWithId = function(timeoutKey) { + this.deletedKeys_.push(timeoutKey); - for (const runAtMillis in scheduledFunctions) { - const funcs = scheduledFunctions[runAtMillis]; + for (const runAtMillis in this.scheduledFunctions_) { + const funcs = this.scheduledFunctions_[runAtMillis]; const i = indexOfFirstToPass(funcs, function(func) { return func.timeoutKey === timeoutKey; }); if (i > -1) { if (funcs.length === 1) { - delete scheduledFunctions[runAtMillis]; - deleteFromLookup(runAtMillis); + delete this.scheduledFunctions_[runAtMillis]; + this.deleteFromLookup_(runAtMillis); } else { funcs.splice(i, 1); } @@ -3718,93 +3712,99 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { } }; - return self; + return this; + } - function indexOfFirstToPass(array, testFn) { - let index = -1; + DelayedFunctionScheduler.prototype.runScheduledFunctions_ = function( + endTime, + tickDate + ) { + tickDate = tickDate || function() {}; + if ( + this.scheduledLookup_.length === 0 || + this.scheduledLookup_[0] > endTime + ) { + if (endTime >= this.currentTime_) { + tickDate(endTime - this.currentTime_); + this.currentTime_ = endTime; + } + return; + } - for (let i = 0; i < array.length; ++i) { - if (testFn(array[i])) { - index = i; - break; + do { + this.deletedKeys_ = []; + const newCurrentTime = this.scheduledLookup_.shift(); + if (newCurrentTime >= this.currentTime_) { + tickDate(newCurrentTime - this.currentTime_); + this.currentTime_ = newCurrentTime; + } + + const funcsToRun = this.scheduledFunctions_[this.currentTime_]; + + delete this.scheduledFunctions_[this.currentTime_]; + + for (const fn of funcsToRun) { + if (fn.recurring) { + this.reschedule_(fn); } } - return index; + for (const fn of funcsToRun) { + if (this.deletedKeys_.includes(fn.timeoutKey)) { + // skip a timeoutKey deleted whilst we were running + return; + } + fn.funcToCall.apply(null, fn.params || []); + } + this.deletedKeys_ = []; + } while ( + this.scheduledLookup_.length > 0 && + // checking first if we're out of time prevents setTimeout(0) + // scheduled in a funcToRun from forcing an extra iteration + this.currentTime_ !== endTime && + this.scheduledLookup_[0] <= endTime + ); + + // ran out of functions to call, but still time left on the clock + if (endTime >= this.currentTime_) { + tickDate(endTime - this.currentTime_); + this.currentTime_ = endTime; } + }; - function deleteFromLookup(key) { - const value = Number(key); - const i = indexOfFirstToPass(scheduledLookup, function(millis) { - return millis === value; - }); + DelayedFunctionScheduler.prototype.reschedule_ = function(scheduledFn) { + this.scheduleFunction( + scheduledFn.funcToCall, + scheduledFn.millis, + scheduledFn.params, + true, + scheduledFn.timeoutKey, + scheduledFn.runAtMillis + scheduledFn.millis + ); + }; - if (i > -1) { - scheduledLookup.splice(i, 1); + DelayedFunctionScheduler.prototype.deleteFromLookup_ = function(key) { + const value = Number(key); + const i = indexOfFirstToPass(this.scheduledLookup_, function(millis) { + return millis === value; + }); + + if (i > -1) { + this.scheduledLookup_.splice(i, 1); + } + }; + + function indexOfFirstToPass(array, testFn) { + let index = -1; + + for (let i = 0; i < array.length; ++i) { + if (testFn(array[i])) { + index = i; + break; } } - function reschedule(scheduledFn) { - self.scheduleFunction( - scheduledFn.funcToCall, - scheduledFn.millis, - scheduledFn.params, - true, - scheduledFn.timeoutKey, - scheduledFn.runAtMillis + scheduledFn.millis - ); - } - - function runScheduledFunctions(endTime, tickDate) { - tickDate = tickDate || function() {}; - if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { - if (endTime >= currentTime) { - tickDate(endTime - currentTime); - currentTime = endTime; - } - return; - } - - do { - deletedKeys = []; - const newCurrentTime = scheduledLookup.shift(); - if (newCurrentTime >= currentTime) { - tickDate(newCurrentTime - currentTime); - currentTime = newCurrentTime; - } - - const funcsToRun = scheduledFunctions[currentTime]; - - delete scheduledFunctions[currentTime]; - - for (const fn of funcsToRun) { - if (fn.recurring) { - reschedule(fn); - } - } - - for (const fn of funcsToRun) { - if (deletedKeys.includes(fn.timeoutKey)) { - // skip a timeoutKey deleted whilst we were running - return; - } - fn.funcToCall.apply(null, fn.params || []); - } - deletedKeys = []; - } while ( - scheduledLookup.length > 0 && - // checking first if we're out of time prevents setTimeout(0) - // scheduled in a funcToRun from forcing an extra iteration - currentTime !== endTime && - scheduledLookup[0] <= endTime - ); - - // ran out of functions to call, but still time left on the clock - if (endTime >= currentTime) { - tickDate(endTime - currentTime); - currentTime = endTime; - } - } + return index; } return DelayedFunctionScheduler; @@ -4356,12 +4356,26 @@ getJasmineRequireObj().Expector = function(j$) { }; Expector.prototype.buildMessage = function(result) { - const self = this; - if (result.pass) { return ''; } + const defaultMessage = () => { + if (!result.message) { + const args = this.args.slice(); + args.unshift(false); + args.unshift(this.matcherName); + return this.matchersUtil.buildFailureMessage.apply( + this.matchersUtil, + args + ); + } else if (j$.isFunction_(result.message)) { + return result.message(); + } else { + return result.message; + } + }; + const msg = this.filters.buildFailureMessage( result, this.matcherName, @@ -4370,22 +4384,6 @@ getJasmineRequireObj().Expector = function(j$) { defaultMessage ); return this.filters.modifyFailureMessage(msg || defaultMessage()); - - function defaultMessage() { - if (!result.message) { - const args = self.args.slice(); - args.unshift(false); - args.unshift(self.matcherName); - return self.matchersUtil.buildFailureMessage.apply( - self.matchersUtil, - args - ); - } else if (j$.isFunction_(result.message)) { - return result.message(); - } else { - return result.message; - } - } }; Expector.prototype.compare = function(matcherName, matcherFactory, args) { @@ -5105,7 +5103,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) { }; MatchersUtil.prototype.buildFailureMessage = function() { - const self = this; const args = Array.prototype.slice.call(arguments, 0), matcherName = args[0], isNot = args[1], @@ -5117,7 +5114,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { let message = 'Expected ' + - self.pp(actual) + + this.pp(actual) + (isNot ? ' not ' : ' ') + englishyPredicate; @@ -5126,7 +5123,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { if (i > 0) { message += ','; } - message += ' ' + self.pp(expected[i]); + message += ' ' + this.pp(expected[i]); } } @@ -5201,7 +5198,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) { // [Underscore](http://underscorejs.org) MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) { let result = true; - const self = this; const asymmetricResult = this.asymmetricMatch_( a, @@ -5286,7 +5282,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { case '[object ArrayBuffer]': // If we have an instance of ArrayBuffer the Uint8Array ctor // will be defined as well - return self.eq_( + return this.eq_( new Uint8Array(a), new Uint8Array(b), aStack, @@ -5356,15 +5352,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) { }); for (let i = 0; i < aLength || i < bLength; i++) { - diffBuilder.withPath(i, function() { + diffBuilder.withPath(i, () => { if (i >= bLength) { diffBuilder.recordMismatch( - actualArrayIsLongerFormatter.bind(null, self.pp) + actualArrayIsLongerFormatter.bind(null, this.pp) ); result = false; } else { result = - self.eq_( + this.eq_( i < aLength ? a[i] : void 0, i < bLength ? b[i] : void 0, aStack, @@ -5529,8 +5525,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) { continue; } - diffBuilder.withPath(key, function() { - if (!self.eq_(a[key], b[key], aStack, bStack, diffBuilder)) { + diffBuilder.withPath(key, () => { + if (!this.eq_(a[key], b[key], aStack, bStack, diffBuilder)) { result = false; } }); @@ -7388,19 +7384,18 @@ getJasmineRequireObj().toThrowMatching = function(j$) { getJasmineRequireObj().MockDate = function(j$) { function MockDate(global) { - const self = this; let currentTime = 0; if (!global || !global.Date) { - self.install = function() {}; - self.tick = function() {}; - self.uninstall = function() {}; - return self; + this.install = function() {}; + this.tick = function() {}; + this.uninstall = function() {}; + return this; } const GlobalDate = global.Date; - self.install = function(mockDate) { + this.install = function(mockDate) { if (mockDate instanceof GlobalDate) { currentTime = mockDate.getTime(); } else { @@ -7417,19 +7412,19 @@ getJasmineRequireObj().MockDate = function(j$) { global.Date = FakeDate; }; - self.tick = function(millis) { + this.tick = function(millis) { millis = millis || 0; currentTime = currentTime + millis; }; - self.uninstall = function() { + this.uninstall = function() { currentTime = 0; global.Date = GlobalDate; }; createDateProperties(); - return self; + return this; function FakeDate() { switch (arguments.length) { @@ -7935,12 +7930,11 @@ getJasmineRequireObj().QueueRunner = function(j$) { } QueueRunner.prototype.execute = function() { - const self = this; - this.handleFinalError = function(message, source, lineno, colno, error) { + this.handleFinalError = (message, source, lineno, colno, error) => { // Older browsers would send the error as the first parameter. HTML5 // specifies the the five parameters above. The error instance should // be preffered, otherwise the call stack would get lost. - self.onException(error || message); + this.onException(error || message); }; this.globalErrors.pushListener(this.handleFinalError); this.run(0); @@ -7963,44 +7957,49 @@ getJasmineRequireObj().QueueRunner = function(j$) { QueueRunner.prototype.attempt = function attempt(iterativeIndex) { let timeoutId; let timedOut; - const self = this; let completedSynchronously = true; + + const onException = e => { + this.onException(e); + this.recordError_(iterativeIndex); + }; + function handleError(error) { // TODO probably shouldn't next() right away here. // That makes debugging async failures much more confusing. onException(error); } - const cleanup = once(function cleanup() { + const cleanup = once(() => { if (timeoutId !== void 0) { - self.clearTimeout(timeoutId); + this.clearTimeout(timeoutId); } - self.globalErrors.popListener(handleError); + this.globalErrors.popListener(handleError); }); const next = once( - function next(err) { + err => { cleanup(); if (typeof err !== 'undefined') { if (!(err instanceof StopExecutionError) && !err.jasmineMessage) { - self.fail(err); + this.fail(err); } - self.recordError_(iterativeIndex); + this.recordError_(iterativeIndex); } - function runNext() { - self.run(self.nextFnIx_(iterativeIndex)); - } + const runNext = () => { + this.run(this.nextFnIx_(iterativeIndex)); + }; if (completedSynchronously) { - self.setTimeout(runNext); + this.setTimeout(runNext); } else { runNext(); } }, - function() { + () => { try { if (!timedOut) { - self.onMultipleDone(); + this.onMultipleDone(); } } catch (error) { // Any error we catch here is probably due to a bug in Jasmine, @@ -8011,20 +8010,20 @@ getJasmineRequireObj().QueueRunner = function(j$) { } ); timedOut = false; - const queueableFn = self.queueableFns[iterativeIndex]; + const queueableFn = this.queueableFns[iterativeIndex]; next.fail = function nextFail() { - self.fail.apply(null, arguments); - self.recordError_(iterativeIndex); + this.fail.apply(null, arguments); + this.recordError_(iterativeIndex); next(); - }; + }.bind(this); - self.globalErrors.pushListener(handleError); + this.globalErrors.pushListener(handleError); if (queueableFn.timeout !== undefined) { const timeoutInterval = queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL; - timeoutId = self.setTimeout(function() { + timeoutId = this.setTimeout(function() { timedOut = true; const error = new Error( 'Timeout - Async function did not complete within ' + @@ -8046,7 +8045,7 @@ getJasmineRequireObj().QueueRunner = function(j$) { let maybeThenable; if (queueableFn.fn.length === 0) { - maybeThenable = queueableFn.fn.call(self.userContext); + maybeThenable = queueableFn.fn.call(this.userContext); if (maybeThenable && j$.isFunction_(maybeThenable.then)) { maybeThenable.then( @@ -8057,24 +8056,19 @@ getJasmineRequireObj().QueueRunner = function(j$) { return { completedSynchronously: false }; } } else { - maybeThenable = queueableFn.fn.call(self.userContext, next); + maybeThenable = queueableFn.fn.call(this.userContext, next); this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable); completedSynchronously = false; return { completedSynchronously: false }; } } catch (e) { onException(e); - self.recordError_(iterativeIndex); + this.recordError_(iterativeIndex); } cleanup(); return { completedSynchronously: true }; - function onException(e) { - self.onException(e); - self.recordError_(iterativeIndex); - } - function onPromiseRejection(e) { onException(e); next(); @@ -8083,7 +8077,6 @@ getJasmineRequireObj().QueueRunner = function(j$) { QueueRunner.prototype.run = function(recursiveIndex) { const length = this.queueableFns.length; - const self = this; for ( let iterativeIndex = recursiveIndex; @@ -8097,13 +8090,13 @@ getJasmineRequireObj().QueueRunner = function(j$) { } } - this.clearStack(function() { - self.globalErrors.popListener(self.handleFinalError); + this.clearStack(() => { + this.globalErrors.popListener(this.handleFinalError); - if (self.errored_) { - self.onComplete(new StopExecutionError()); + if (this.errored_) { + this.onComplete(new StopExecutionError()); } else { - self.onComplete(); + this.onComplete(); } }); }; @@ -8929,8 +8922,6 @@ getJasmineRequireObj().SpyFactory = function(j$) { getDefaultStrategyFn, getMatchersUtil ) { - const self = this; - this.createSpy = function(name, originalFn) { return j$.Spy(name, getMatchersUtil(), { originalFn, @@ -8953,7 +8944,7 @@ getJasmineRequireObj().SpyFactory = function(j$) { const methods = normalizeKeyValues(methodNames); for (let i = 0; i < methods.length; i++) { - const spy = (obj[methods[i][0]] = self.createSpy( + const spy = (obj[methods[i][0]] = this.createSpy( baseName + '.' + methods[i][0] )); if (methods[i].length > 1) { @@ -8965,8 +8956,8 @@ getJasmineRequireObj().SpyFactory = function(j$) { for (let i = 0; i < properties.length; i++) { const descriptor = { enumerable: true, - get: self.createSpy(baseName + '.' + properties[i][0] + '.get'), - set: self.createSpy(baseName + '.' + properties[i][0] + '.set') + get: this.createSpy(baseName + '.' + properties[i][0] + '.get'), + set: this.createSpy(baseName + '.' + properties[i][0] + '.set') }; if (properties[i].length > 1) { descriptor.get.and.returnValue(properties[i][1]); @@ -9267,8 +9258,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) { function SpyStrategy(options) { options = options || {}; - const self = this; - /** * Get the identifying information for the spy. * @name SpyStrategy#identity @@ -9296,10 +9285,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) { * @param {*} value The value to return. */ this.resolveTo = function(value) { - self.plan = function() { + this.plan = function() { return Promise.resolve(value); }; - return self.getSpy(); + return this.getSpy(); }; /** @@ -9310,10 +9299,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) { * @param {*} value The value to return. */ this.rejectWith = function(value) { - self.plan = function() { + this.plan = function() { return Promise.reject(value); }; - return self.getSpy(); + return this.getSpy(); }; } diff --git a/src/core/Clock.js b/src/core/Clock.js index 08a476a8..8541d639 100644 --- a/src/core/Clock.js +++ b/src/core/Clock.js @@ -14,24 +14,23 @@ getJasmineRequireObj().Clock = function() { * @hideconstructor */ function Clock(global, delayedFunctionSchedulerFactory, mockDate) { - const self = this, - realTimingFunctions = { - setTimeout: global.setTimeout, - clearTimeout: global.clearTimeout, - setInterval: global.setInterval, - clearInterval: global.clearInterval - }, - fakeTimingFunctions = { - setTimeout: setTimeout, - clearTimeout: clearTimeout, - setInterval: setInterval, - clearInterval: clearInterval - }; + const realTimingFunctions = { + setTimeout: global.setTimeout, + clearTimeout: global.clearTimeout, + setInterval: global.setInterval, + clearInterval: global.clearInterval + }; + const fakeTimingFunctions = { + setTimeout: setTimeout, + clearTimeout: clearTimeout, + setInterval: setInterval, + clearInterval: clearInterval + }; let installed = false; let delayedFunctionScheduler; let timer; - self.FakeTimeout = FakeTimeout; + this.FakeTimeout = FakeTimeout; /** * Install the mock clock over the built-in methods. @@ -40,7 +39,7 @@ getJasmineRequireObj().Clock = function() { * @function * @return {Clock} */ - self.install = function() { + this.install = function() { if (!originalTimingFunctionsIntact()) { throw new Error( 'Jasmine Clock was unable to install over custom global timer functions. Is the clock already installed?' @@ -51,7 +50,7 @@ getJasmineRequireObj().Clock = function() { delayedFunctionScheduler = delayedFunctionSchedulerFactory(); installed = true; - return self; + return this; }; /** @@ -60,7 +59,7 @@ getJasmineRequireObj().Clock = function() { * @since 2.0.0 * @function */ - self.uninstall = function() { + this.uninstall = function() { delayedFunctionScheduler = null; mockDate.uninstall(); replace(global, realTimingFunctions); @@ -78,7 +77,7 @@ getJasmineRequireObj().Clock = function() { * @function * @param {Function} closure The function to be called. */ - self.withMock = function(closure) { + this.withMock = function(closure) { this.install(); try { closure(); @@ -94,29 +93,29 @@ getJasmineRequireObj().Clock = function() { * @function * @param {Date} [initialDate=now] The `Date` to provide. */ - self.mockDate = function(initialDate) { + this.mockDate = function(initialDate) { mockDate.install(initialDate); }; - self.setTimeout = function(fn, delay, params) { + this.setTimeout = function(fn, delay, params) { return Function.prototype.apply.apply(timer.setTimeout, [ global, arguments ]); }; - self.setInterval = function(fn, delay, params) { + this.setInterval = function(fn, delay, params) { return Function.prototype.apply.apply(timer.setInterval, [ global, arguments ]); }; - self.clearTimeout = function(id) { + this.clearTimeout = function(id) { return Function.prototype.call.apply(timer.clearTimeout, [global, id]); }; - self.clearInterval = function(id) { + this.clearInterval = function(id) { return Function.prototype.call.apply(timer.clearInterval, [global, id]); }; @@ -127,7 +126,7 @@ getJasmineRequireObj().Clock = function() { * @function * @param {int} millis The number of milliseconds to tick. */ - self.tick = function(millis) { + this.tick = function(millis) { if (installed) { delayedFunctionScheduler.tick(millis, function(millis) { mockDate.tick(millis); @@ -139,7 +138,7 @@ getJasmineRequireObj().Clock = function() { } }; - return self; + return this; function originalTimingFunctionsIntact() { return ( diff --git a/src/core/DelayedFunctionScheduler.js b/src/core/DelayedFunctionScheduler.js index 0ac0073c..ef2c2f4f 100644 --- a/src/core/DelayedFunctionScheduler.js +++ b/src/core/DelayedFunctionScheduler.js @@ -1,20 +1,19 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { function DelayedFunctionScheduler() { - const self = this; - const scheduledLookup = []; - const scheduledFunctions = {}; - let currentTime = 0; - let delayedFnCount = 0; - let deletedKeys = []; + this.scheduledLookup_ = []; + this.scheduledFunctions_ = {}; + this.currentTime_ = 0; + this.delayedFnCount_ = 0; + this.deletedKeys_ = []; - self.tick = function(millis, tickDate) { + this.tick = function(millis, tickDate) { millis = millis || 0; - const endTime = currentTime + millis; + const endTime = this.currentTime_ + millis; - runScheduledFunctions(endTime, tickDate); + this.runScheduledFunctions_(endTime, tickDate); }; - self.scheduleFunction = function( + this.scheduleFunction = function( funcToCall, millis, params, @@ -33,8 +32,8 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { } millis = millis || 0; - timeoutKey = timeoutKey || ++delayedFnCount; - runAtMillis = runAtMillis || currentTime + millis; + timeoutKey = timeoutKey || ++this.delayedFnCount_; + runAtMillis = runAtMillis || this.currentTime_ + millis; const funcToSchedule = { runAtMillis: runAtMillis, @@ -45,12 +44,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { millis: millis }; - if (runAtMillis in scheduledFunctions) { - scheduledFunctions[runAtMillis].push(funcToSchedule); + if (runAtMillis in this.scheduledFunctions_) { + this.scheduledFunctions_[runAtMillis].push(funcToSchedule); } else { - scheduledFunctions[runAtMillis] = [funcToSchedule]; - scheduledLookup.push(runAtMillis); - scheduledLookup.sort(function(a, b) { + this.scheduledFunctions_[runAtMillis] = [funcToSchedule]; + this.scheduledLookup_.push(runAtMillis); + this.scheduledLookup_.sort(function(a, b) { return a - b; }); } @@ -58,19 +57,19 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { return timeoutKey; }; - self.removeFunctionWithId = function(timeoutKey) { - deletedKeys.push(timeoutKey); + this.removeFunctionWithId = function(timeoutKey) { + this.deletedKeys_.push(timeoutKey); - for (const runAtMillis in scheduledFunctions) { - const funcs = scheduledFunctions[runAtMillis]; + for (const runAtMillis in this.scheduledFunctions_) { + const funcs = this.scheduledFunctions_[runAtMillis]; const i = indexOfFirstToPass(funcs, function(func) { return func.timeoutKey === timeoutKey; }); if (i > -1) { if (funcs.length === 1) { - delete scheduledFunctions[runAtMillis]; - deleteFromLookup(runAtMillis); + delete this.scheduledFunctions_[runAtMillis]; + this.deleteFromLookup_(runAtMillis); } else { funcs.splice(i, 1); } @@ -82,93 +81,99 @@ getJasmineRequireObj().DelayedFunctionScheduler = function(j$) { } }; - return self; + return this; + } - function indexOfFirstToPass(array, testFn) { - let index = -1; + DelayedFunctionScheduler.prototype.runScheduledFunctions_ = function( + endTime, + tickDate + ) { + tickDate = tickDate || function() {}; + if ( + this.scheduledLookup_.length === 0 || + this.scheduledLookup_[0] > endTime + ) { + if (endTime >= this.currentTime_) { + tickDate(endTime - this.currentTime_); + this.currentTime_ = endTime; + } + return; + } - for (let i = 0; i < array.length; ++i) { - if (testFn(array[i])) { - index = i; - break; + do { + this.deletedKeys_ = []; + const newCurrentTime = this.scheduledLookup_.shift(); + if (newCurrentTime >= this.currentTime_) { + tickDate(newCurrentTime - this.currentTime_); + this.currentTime_ = newCurrentTime; + } + + const funcsToRun = this.scheduledFunctions_[this.currentTime_]; + + delete this.scheduledFunctions_[this.currentTime_]; + + for (const fn of funcsToRun) { + if (fn.recurring) { + this.reschedule_(fn); } } - return index; + for (const fn of funcsToRun) { + if (this.deletedKeys_.includes(fn.timeoutKey)) { + // skip a timeoutKey deleted whilst we were running + return; + } + fn.funcToCall.apply(null, fn.params || []); + } + this.deletedKeys_ = []; + } while ( + this.scheduledLookup_.length > 0 && + // checking first if we're out of time prevents setTimeout(0) + // scheduled in a funcToRun from forcing an extra iteration + this.currentTime_ !== endTime && + this.scheduledLookup_[0] <= endTime + ); + + // ran out of functions to call, but still time left on the clock + if (endTime >= this.currentTime_) { + tickDate(endTime - this.currentTime_); + this.currentTime_ = endTime; } + }; - function deleteFromLookup(key) { - const value = Number(key); - const i = indexOfFirstToPass(scheduledLookup, function(millis) { - return millis === value; - }); + DelayedFunctionScheduler.prototype.reschedule_ = function(scheduledFn) { + this.scheduleFunction( + scheduledFn.funcToCall, + scheduledFn.millis, + scheduledFn.params, + true, + scheduledFn.timeoutKey, + scheduledFn.runAtMillis + scheduledFn.millis + ); + }; - if (i > -1) { - scheduledLookup.splice(i, 1); + DelayedFunctionScheduler.prototype.deleteFromLookup_ = function(key) { + const value = Number(key); + const i = indexOfFirstToPass(this.scheduledLookup_, function(millis) { + return millis === value; + }); + + if (i > -1) { + this.scheduledLookup_.splice(i, 1); + } + }; + + function indexOfFirstToPass(array, testFn) { + let index = -1; + + for (let i = 0; i < array.length; ++i) { + if (testFn(array[i])) { + index = i; + break; } } - function reschedule(scheduledFn) { - self.scheduleFunction( - scheduledFn.funcToCall, - scheduledFn.millis, - scheduledFn.params, - true, - scheduledFn.timeoutKey, - scheduledFn.runAtMillis + scheduledFn.millis - ); - } - - function runScheduledFunctions(endTime, tickDate) { - tickDate = tickDate || function() {}; - if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { - if (endTime >= currentTime) { - tickDate(endTime - currentTime); - currentTime = endTime; - } - return; - } - - do { - deletedKeys = []; - const newCurrentTime = scheduledLookup.shift(); - if (newCurrentTime >= currentTime) { - tickDate(newCurrentTime - currentTime); - currentTime = newCurrentTime; - } - - const funcsToRun = scheduledFunctions[currentTime]; - - delete scheduledFunctions[currentTime]; - - for (const fn of funcsToRun) { - if (fn.recurring) { - reschedule(fn); - } - } - - for (const fn of funcsToRun) { - if (deletedKeys.includes(fn.timeoutKey)) { - // skip a timeoutKey deleted whilst we were running - return; - } - fn.funcToCall.apply(null, fn.params || []); - } - deletedKeys = []; - } while ( - scheduledLookup.length > 0 && - // checking first if we're out of time prevents setTimeout(0) - // scheduled in a funcToRun from forcing an extra iteration - currentTime !== endTime && - scheduledLookup[0] <= endTime - ); - - // ran out of functions to call, but still time left on the clock - if (endTime >= currentTime) { - tickDate(endTime - currentTime); - currentTime = endTime; - } - } + return index; } return DelayedFunctionScheduler; diff --git a/src/core/Expector.js b/src/core/Expector.js index 41db72f3..c840841b 100644 --- a/src/core/Expector.js +++ b/src/core/Expector.js @@ -26,12 +26,26 @@ getJasmineRequireObj().Expector = function(j$) { }; Expector.prototype.buildMessage = function(result) { - const self = this; - if (result.pass) { return ''; } + const defaultMessage = () => { + if (!result.message) { + const args = this.args.slice(); + args.unshift(false); + args.unshift(this.matcherName); + return this.matchersUtil.buildFailureMessage.apply( + this.matchersUtil, + args + ); + } else if (j$.isFunction_(result.message)) { + return result.message(); + } else { + return result.message; + } + }; + const msg = this.filters.buildFailureMessage( result, this.matcherName, @@ -40,22 +54,6 @@ getJasmineRequireObj().Expector = function(j$) { defaultMessage ); return this.filters.modifyFailureMessage(msg || defaultMessage()); - - function defaultMessage() { - if (!result.message) { - const args = self.args.slice(); - args.unshift(false); - args.unshift(self.matcherName); - return self.matchersUtil.buildFailureMessage.apply( - self.matchersUtil, - args - ); - } else if (j$.isFunction_(result.message)) { - return result.message(); - } else { - return result.message; - } - } }; Expector.prototype.compare = function(matcherName, matcherFactory, args) { diff --git a/src/core/MockDate.js b/src/core/MockDate.js index 01b7ad00..3ddb68ad 100644 --- a/src/core/MockDate.js +++ b/src/core/MockDate.js @@ -1,18 +1,17 @@ getJasmineRequireObj().MockDate = function(j$) { function MockDate(global) { - const self = this; let currentTime = 0; if (!global || !global.Date) { - self.install = function() {}; - self.tick = function() {}; - self.uninstall = function() {}; - return self; + this.install = function() {}; + this.tick = function() {}; + this.uninstall = function() {}; + return this; } const GlobalDate = global.Date; - self.install = function(mockDate) { + this.install = function(mockDate) { if (mockDate instanceof GlobalDate) { currentTime = mockDate.getTime(); } else { @@ -29,19 +28,19 @@ getJasmineRequireObj().MockDate = function(j$) { global.Date = FakeDate; }; - self.tick = function(millis) { + this.tick = function(millis) { millis = millis || 0; currentTime = currentTime + millis; }; - self.uninstall = function() { + this.uninstall = function() { currentTime = 0; global.Date = GlobalDate; }; createDateProperties(); - return self; + return this; function FakeDate() { switch (arguments.length) { diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index 2e061bbc..0d7001c7 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -66,12 +66,11 @@ getJasmineRequireObj().QueueRunner = function(j$) { } QueueRunner.prototype.execute = function() { - const self = this; - this.handleFinalError = function(message, source, lineno, colno, error) { + this.handleFinalError = (message, source, lineno, colno, error) => { // Older browsers would send the error as the first parameter. HTML5 // specifies the the five parameters above. The error instance should // be preffered, otherwise the call stack would get lost. - self.onException(error || message); + this.onException(error || message); }; this.globalErrors.pushListener(this.handleFinalError); this.run(0); @@ -94,44 +93,49 @@ getJasmineRequireObj().QueueRunner = function(j$) { QueueRunner.prototype.attempt = function attempt(iterativeIndex) { let timeoutId; let timedOut; - const self = this; let completedSynchronously = true; + + const onException = e => { + this.onException(e); + this.recordError_(iterativeIndex); + }; + function handleError(error) { // TODO probably shouldn't next() right away here. // That makes debugging async failures much more confusing. onException(error); } - const cleanup = once(function cleanup() { + const cleanup = once(() => { if (timeoutId !== void 0) { - self.clearTimeout(timeoutId); + this.clearTimeout(timeoutId); } - self.globalErrors.popListener(handleError); + this.globalErrors.popListener(handleError); }); const next = once( - function next(err) { + err => { cleanup(); if (typeof err !== 'undefined') { if (!(err instanceof StopExecutionError) && !err.jasmineMessage) { - self.fail(err); + this.fail(err); } - self.recordError_(iterativeIndex); + this.recordError_(iterativeIndex); } - function runNext() { - self.run(self.nextFnIx_(iterativeIndex)); - } + const runNext = () => { + this.run(this.nextFnIx_(iterativeIndex)); + }; if (completedSynchronously) { - self.setTimeout(runNext); + this.setTimeout(runNext); } else { runNext(); } }, - function() { + () => { try { if (!timedOut) { - self.onMultipleDone(); + this.onMultipleDone(); } } catch (error) { // Any error we catch here is probably due to a bug in Jasmine, @@ -142,20 +146,20 @@ getJasmineRequireObj().QueueRunner = function(j$) { } ); timedOut = false; - const queueableFn = self.queueableFns[iterativeIndex]; + const queueableFn = this.queueableFns[iterativeIndex]; next.fail = function nextFail() { - self.fail.apply(null, arguments); - self.recordError_(iterativeIndex); + this.fail.apply(null, arguments); + this.recordError_(iterativeIndex); next(); - }; + }.bind(this); - self.globalErrors.pushListener(handleError); + this.globalErrors.pushListener(handleError); if (queueableFn.timeout !== undefined) { const timeoutInterval = queueableFn.timeout || j$.DEFAULT_TIMEOUT_INTERVAL; - timeoutId = self.setTimeout(function() { + timeoutId = this.setTimeout(function() { timedOut = true; const error = new Error( 'Timeout - Async function did not complete within ' + @@ -177,7 +181,7 @@ getJasmineRequireObj().QueueRunner = function(j$) { let maybeThenable; if (queueableFn.fn.length === 0) { - maybeThenable = queueableFn.fn.call(self.userContext); + maybeThenable = queueableFn.fn.call(this.userContext); if (maybeThenable && j$.isFunction_(maybeThenable.then)) { maybeThenable.then( @@ -188,24 +192,19 @@ getJasmineRequireObj().QueueRunner = function(j$) { return { completedSynchronously: false }; } } else { - maybeThenable = queueableFn.fn.call(self.userContext, next); + maybeThenable = queueableFn.fn.call(this.userContext, next); this.diagnoseConflictingAsync_(queueableFn.fn, maybeThenable); completedSynchronously = false; return { completedSynchronously: false }; } } catch (e) { onException(e); - self.recordError_(iterativeIndex); + this.recordError_(iterativeIndex); } cleanup(); return { completedSynchronously: true }; - function onException(e) { - self.onException(e); - self.recordError_(iterativeIndex); - } - function onPromiseRejection(e) { onException(e); next(); @@ -214,7 +213,6 @@ getJasmineRequireObj().QueueRunner = function(j$) { QueueRunner.prototype.run = function(recursiveIndex) { const length = this.queueableFns.length; - const self = this; for ( let iterativeIndex = recursiveIndex; @@ -228,13 +226,13 @@ getJasmineRequireObj().QueueRunner = function(j$) { } } - this.clearStack(function() { - self.globalErrors.popListener(self.handleFinalError); + this.clearStack(() => { + this.globalErrors.popListener(this.handleFinalError); - if (self.errored_) { - self.onComplete(new StopExecutionError()); + if (this.errored_) { + this.onComplete(new StopExecutionError()); } else { - self.onComplete(); + this.onComplete(); } }); }; diff --git a/src/core/Spec.js b/src/core/Spec.js index 71f82258..11ec701a 100644 --- a/src/core/Spec.js +++ b/src/core/Spec.js @@ -100,28 +100,26 @@ getJasmineRequireObj().Spec = function(j$) { }; Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) { - const self = this; - const onStart = { - fn: function(done) { - self.timer.start(); - self.onStart(self, done); + fn: done => { + this.timer.start(); + this.onStart(this, done); } }; const complete = { - fn: function(done) { - if (self.autoCleanClosures) { - self.queueableFn.fn = null; + fn: done => { + if (this.autoCleanClosures) { + this.queueableFn.fn = null; } - self.result.status = self.status(excluded, failSpecWithNoExp); - self.result.duration = self.timer.elapsed(); + this.result.status = this.status(excluded, failSpecWithNoExp); + this.result.duration = this.timer.elapsed(); - if (self.result.status !== 'failed') { - self.result.debugLogs = null; + if (this.result.status !== 'failed') { + this.result.debugLogs = null; } - self.resultCallback(self.result, done); + this.resultCallback(this.result, done); }, type: 'specCleanup' }; @@ -131,24 +129,22 @@ getJasmineRequireObj().Spec = function(j$) { const runnerConfig = { isLeaf: true, queueableFns: [...fns.befores, this.queueableFn, ...fns.afters], - onException: function() { - self.handleException.apply(self, arguments); - }, - onMultipleDone: function() { + onException: e => this.handleException(e), + onMultipleDone: () => { // Issue a deprecation. Include the context ourselves and pass // ignoreRunnable: true, since getting here always means that we've already // moved on and the current runnable isn't the one that caused the problem. - self.onLateError( + this.onLateError( new Error( 'An asynchronous spec, beforeEach, or afterEach function called its ' + "'done' callback more than once.\n(in spec: " + - self.getFullName() + + this.getFullName() + ')' ) ); }, - onComplete: function() { - if (self.result.status === 'failed') { + onComplete: () => { + if (this.result.status === 'failed') { onComplete(new j$.StopExecutionError('spec failed')); } else { onComplete(); diff --git a/src/core/SpyFactory.js b/src/core/SpyFactory.js index e44c1408..d20d6539 100644 --- a/src/core/SpyFactory.js +++ b/src/core/SpyFactory.js @@ -4,8 +4,6 @@ getJasmineRequireObj().SpyFactory = function(j$) { getDefaultStrategyFn, getMatchersUtil ) { - const self = this; - this.createSpy = function(name, originalFn) { return j$.Spy(name, getMatchersUtil(), { originalFn, @@ -28,7 +26,7 @@ getJasmineRequireObj().SpyFactory = function(j$) { const methods = normalizeKeyValues(methodNames); for (let i = 0; i < methods.length; i++) { - const spy = (obj[methods[i][0]] = self.createSpy( + const spy = (obj[methods[i][0]] = this.createSpy( baseName + '.' + methods[i][0] )); if (methods[i].length > 1) { @@ -40,8 +38,8 @@ getJasmineRequireObj().SpyFactory = function(j$) { for (let i = 0; i < properties.length; i++) { const descriptor = { enumerable: true, - get: self.createSpy(baseName + '.' + properties[i][0] + '.get'), - set: self.createSpy(baseName + '.' + properties[i][0] + '.set') + get: this.createSpy(baseName + '.' + properties[i][0] + '.get'), + set: this.createSpy(baseName + '.' + properties[i][0] + '.set') }; if (properties[i].length > 1) { descriptor.get.and.returnValue(properties[i][1]); diff --git a/src/core/SpyStrategy.js b/src/core/SpyStrategy.js index f93f330c..d2e50388 100644 --- a/src/core/SpyStrategy.js +++ b/src/core/SpyStrategy.js @@ -5,8 +5,6 @@ getJasmineRequireObj().SpyStrategy = function(j$) { function SpyStrategy(options) { options = options || {}; - const self = this; - /** * Get the identifying information for the spy. * @name SpyStrategy#identity @@ -34,10 +32,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) { * @param {*} value The value to return. */ this.resolveTo = function(value) { - self.plan = function() { + this.plan = function() { return Promise.resolve(value); }; - return self.getSpy(); + return this.getSpy(); }; /** @@ -48,10 +46,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) { * @param {*} value The value to return. */ this.rejectWith = function(value) { - self.plan = function() { + this.plan = function() { return Promise.reject(value); }; - return self.getSpy(); + return this.getSpy(); }; } diff --git a/src/core/matchers/matchersUtil.js b/src/core/matchers/matchersUtil.js index 5d552170..b7294d16 100644 --- a/src/core/matchers/matchersUtil.js +++ b/src/core/matchers/matchersUtil.js @@ -74,7 +74,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) { }; MatchersUtil.prototype.buildFailureMessage = function() { - const self = this; const args = Array.prototype.slice.call(arguments, 0), matcherName = args[0], isNot = args[1], @@ -86,7 +85,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { let message = 'Expected ' + - self.pp(actual) + + this.pp(actual) + (isNot ? ' not ' : ' ') + englishyPredicate; @@ -95,7 +94,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { if (i > 0) { message += ','; } - message += ' ' + self.pp(expected[i]); + message += ' ' + this.pp(expected[i]); } } @@ -170,7 +169,6 @@ getJasmineRequireObj().MatchersUtil = function(j$) { // [Underscore](http://underscorejs.org) MatchersUtil.prototype.eq_ = function(a, b, aStack, bStack, diffBuilder) { let result = true; - const self = this; const asymmetricResult = this.asymmetricMatch_( a, @@ -255,7 +253,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) { case '[object ArrayBuffer]': // If we have an instance of ArrayBuffer the Uint8Array ctor // will be defined as well - return self.eq_( + return this.eq_( new Uint8Array(a), new Uint8Array(b), aStack, @@ -325,15 +323,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) { }); for (let i = 0; i < aLength || i < bLength; i++) { - diffBuilder.withPath(i, function() { + diffBuilder.withPath(i, () => { if (i >= bLength) { diffBuilder.recordMismatch( - actualArrayIsLongerFormatter.bind(null, self.pp) + actualArrayIsLongerFormatter.bind(null, this.pp) ); result = false; } else { result = - self.eq_( + this.eq_( i < aLength ? a[i] : void 0, i < bLength ? b[i] : void 0, aStack, @@ -498,8 +496,8 @@ getJasmineRequireObj().MatchersUtil = function(j$) { continue; } - diffBuilder.withPath(key, function() { - if (!self.eq_(a[key], b[key], aStack, bStack, diffBuilder)) { + diffBuilder.withPath(key, () => { + if (!this.eq_(a[key], b[key], aStack, bStack, diffBuilder)) { result = false; } });