Replaced var with const and let in expectation related code

This commit is contained in:
Steve Gravrock
2022-06-01 09:22:03 -07:00
parent 8f16021887
commit bd368aceee
5 changed files with 72 additions and 77 deletions

View File

@@ -1481,7 +1481,7 @@ getJasmineRequireObj().Env = function(j$) {
} }
}; };
var expectationFactory = function(actual, spec) { const expectationFactory = function(actual, spec) {
return j$.Expectation.factory({ return j$.Expectation.factory({
matchersUtil: makeMatchersUtil(), matchersUtil: makeMatchersUtil(),
customMatchers: runnableResources[spec.id].customMatchers, customMatchers: runnableResources[spec.id].customMatchers,
@@ -1559,7 +1559,7 @@ getJasmineRequireObj().Env = function(j$) {
console.error(expectationResult); console.error(expectationResult);
} }
var asyncExpectationFactory = function(actual, spec, runableType) { const asyncExpectationFactory = function(actual, spec, runableType) {
return j$.Expectation.asyncFactory({ return j$.Expectation.asyncFactory({
matchersUtil: makeMatchersUtil(), matchersUtil: makeMatchersUtil(),
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers, customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
@@ -1574,11 +1574,11 @@ getJasmineRequireObj().Env = function(j$) {
return spec.addExpectationResult(passed, result); return spec.addExpectationResult(passed, result);
} }
}; };
var suiteAsyncExpectationFactory = function(actual, suite) { const suiteAsyncExpectationFactory = function(actual, suite) {
return asyncExpectationFactory(actual, suite, 'Suite'); return asyncExpectationFactory(actual, suite, 'Suite');
}; };
var specAsyncExpectationFactory = function(actual, suite) { const specAsyncExpectationFactory = function(actual, suite) {
return asyncExpectationFactory(actual, suite, 'Spec'); return asyncExpectationFactory(actual, suite, 'Spec');
}; };
@@ -3905,7 +3905,7 @@ getJasmineRequireObj().errors = function() {
}; };
getJasmineRequireObj().ExceptionFormatter = function(j$) { getJasmineRequireObj().ExceptionFormatter = function(j$) {
var ignoredProperties = [ const ignoredProperties = [
'name', 'name',
'message', 'message',
'stack', 'stack',
@@ -3919,9 +3919,10 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
]; ];
function ExceptionFormatter(options) { function ExceptionFormatter(options) {
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile(); const jasmineFile =
(options && options.jasmineFile) || j$.util.jasmineFile();
this.message = function(error) { this.message = function(error) {
var message = ''; let message = '';
if (error.jasmineMessage) { if (error.jasmineMessage) {
message += error.jasmineMessage; message += error.jasmineMessage;
@@ -3949,9 +3950,9 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return null; return null;
} }
var stackTrace = new j$.StackTrace(error); const stackTrace = new j$.StackTrace(error);
var lines = filterJasmine(stackTrace); const lines = filterJasmine(stackTrace);
var result = ''; let result = '';
if (stackTrace.message && !omitMessage) { if (stackTrace.message && !omitMessage) {
lines.unshift(stackTrace.message); lines.unshift(stackTrace.message);
@@ -3964,9 +3965,9 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
}; };
function filterJasmine(stackTrace) { function filterJasmine(stackTrace) {
var result = [], const result = [];
jasmineMarker = const jasmineMarker =
stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>'; stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
stackTrace.frames.forEach(function(frame) { stackTrace.frames.forEach(function(frame) {
if (frame.file !== jasmineFile) { if (frame.file !== jasmineFile) {
@@ -3984,10 +3985,10 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return; return;
} }
var result = {}; const result = {};
var empty = true; let empty = true;
for (var prop in error) { for (const prop in error) {
if (j$.util.arrayContains(ignoredProperties, prop)) { if (j$.util.arrayContains(ignoredProperties, prop)) {
continue; continue;
} }
@@ -4014,8 +4015,8 @@ getJasmineRequireObj().Expectation = function(j$) {
function Expectation(options) { function Expectation(options) {
this.expector = new j$.Expector(options); this.expector = new j$.Expector(options);
var customMatchers = options.customMatchers || {}; const customMatchers = options.customMatchers || {};
for (var matcherName in customMatchers) { for (const matcherName in customMatchers) {
this[matcherName] = wrapSyncCompare( this[matcherName] = wrapSyncCompare(
matcherName, matcherName,
customMatchers[matcherName] customMatchers[matcherName]
@@ -4085,8 +4086,8 @@ getJasmineRequireObj().Expectation = function(j$) {
function AsyncExpectation(options) { function AsyncExpectation(options) {
this.expector = new j$.Expector(options); this.expector = new j$.Expector(options);
var customAsyncMatchers = options.customAsyncMatchers || {}; const customAsyncMatchers = options.customAsyncMatchers || {};
for (var matcherName in customAsyncMatchers) { for (const matcherName in customAsyncMatchers) {
this[matcherName] = wrapAsyncCompare( this[matcherName] = wrapAsyncCompare(
matcherName, matcherName,
customAsyncMatchers[matcherName] customAsyncMatchers[matcherName]
@@ -4142,36 +4143,34 @@ getJasmineRequireObj().Expectation = function(j$) {
function wrapSyncCompare(name, matcherFactory) { function wrapSyncCompare(name, matcherFactory) {
return function() { return function() {
var result = this.expector.compare(name, matcherFactory, arguments); const result = this.expector.compare(name, matcherFactory, arguments);
this.expector.processResult(result); this.expector.processResult(result);
}; };
} }
function wrapAsyncCompare(name, matcherFactory) { function wrapAsyncCompare(name, matcherFactory) {
return function() { return function() {
var self = this;
// Capture the call stack here, before we go async, so that it will contain // Capture the call stack here, before we go async, so that it will contain
// frames that are relevant to the user instead of just parts of Jasmine. // frames that are relevant to the user instead of just parts of Jasmine.
var errorForStack = j$.util.errorWithStack(); const errorForStack = j$.util.errorWithStack();
return this.expector return this.expector
.compare(name, matcherFactory, arguments) .compare(name, matcherFactory, arguments)
.then(function(result) { .then(result => {
self.expector.processResult(result, errorForStack); this.expector.processResult(result, errorForStack);
}); });
}; };
} }
function addCoreMatchers(prototype, matchers, wrapper) { function addCoreMatchers(prototype, matchers, wrapper) {
for (var matcherName in matchers) { for (const matcherName in matchers) {
var matcher = matchers[matcherName]; const matcher = matchers[matcherName];
prototype[matcherName] = wrapper(matcherName, matcher); prototype[matcherName] = wrapper(matcherName, matcher);
} }
} }
function addFilter(source, filter) { function addFilter(source, filter) {
var result = Object.create(source); const result = Object.create(source);
result.expector = source.expector.addFilter(filter); result.expector = source.expector.addFilter(filter);
return result; return result;
} }
@@ -4196,7 +4195,7 @@ getJasmineRequireObj().Expectation = function(j$) {
return result; return result;
} }
var syncNegatingFilter = { const syncNegatingFilter = {
selectComparisonFunc: function(matcher) { selectComparisonFunc: function(matcher) {
function defaultNegativeCompare() { function defaultNegativeCompare() {
return negate(matcher.compare.apply(null, arguments)); return negate(matcher.compare.apply(null, arguments));
@@ -4207,7 +4206,7 @@ getJasmineRequireObj().Expectation = function(j$) {
buildFailureMessage: negatedFailureMessage buildFailureMessage: negatedFailureMessage
}; };
var asyncNegatingFilter = { const asyncNegatingFilter = {
selectComparisonFunc: function(matcher) { selectComparisonFunc: function(matcher) {
function defaultNegativeCompare() { function defaultNegativeCompare() {
return matcher.compare.apply(this, arguments).then(negate); return matcher.compare.apply(this, arguments).then(negate);
@@ -4218,10 +4217,10 @@ getJasmineRequireObj().Expectation = function(j$) {
buildFailureMessage: negatedFailureMessage buildFailureMessage: negatedFailureMessage
}; };
var expectSettledPromiseFilter = { const expectSettledPromiseFilter = {
selectComparisonFunc: function(matcher) { selectComparisonFunc: function(matcher) {
return function(actual) { return function(actual) {
var matcherArgs = arguments; const matcherArgs = arguments;
return j$.isPending_(actual).then(function(isPending) { return j$.isPending_(actual).then(function(isPending) {
if (isPending) { if (isPending) {
@@ -4244,9 +4243,7 @@ getJasmineRequireObj().Expectation = function(j$) {
} }
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) { ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
var nl = msg.indexOf('\n'); if (msg.indexOf('\n') === -1) {
if (nl === -1) {
return this.message + ': ' + msg; return this.message + ': ' + msg;
} else { } else {
return this.message + ':\n' + indent(msg); return this.message + ':\n' + indent(msg);
@@ -4328,8 +4325,8 @@ getJasmineRequireObj().ExpectationFilterChain = function() {
//TODO: expectation result may make more sense as a presentation of an expectation. //TODO: expectation result may make more sense as a presentation of an expectation.
getJasmineRequireObj().buildExpectationResult = function(j$) { getJasmineRequireObj().buildExpectationResult = function(j$) {
function buildExpectationResult(options) { function buildExpectationResult(options) {
var messageFormatter = options.messageFormatter || function() {}, const messageFormatter = options.messageFormatter || function() {};
stackFormatter = options.stackFormatter || function() {}; const stackFormatter = options.stackFormatter || function() {};
/** /**
* @typedef Expectation * @typedef Expectation
@@ -4343,7 +4340,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
* is reported on the top suite. Valid values are undefined, "afterAll", * is reported on the top suite. Valid values are undefined, "afterAll",
* "load", "lateExpectation", and "lateError". * "load", "lateExpectation", and "lateError".
*/ */
var result = { const result = {
matcherName: options.matcherName, matcherName: options.matcherName,
message: message(), message: message(),
stack: options.omitStackTrace ? '' : stack(), stack: options.omitStackTrace ? '' : stack(),
@@ -4389,7 +4386,8 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
return ''; return '';
} }
var error = options.error; let error = options.error;
if (!error) { if (!error) {
if (options.errorForStack) { if (options.errorForStack) {
error = options.errorForStack; error = options.errorForStack;

View File

@@ -329,7 +329,7 @@ getJasmineRequireObj().Env = function(j$) {
} }
}; };
var expectationFactory = function(actual, spec) { const expectationFactory = function(actual, spec) {
return j$.Expectation.factory({ return j$.Expectation.factory({
matchersUtil: makeMatchersUtil(), matchersUtil: makeMatchersUtil(),
customMatchers: runnableResources[spec.id].customMatchers, customMatchers: runnableResources[spec.id].customMatchers,
@@ -407,7 +407,7 @@ getJasmineRequireObj().Env = function(j$) {
console.error(expectationResult); console.error(expectationResult);
} }
var asyncExpectationFactory = function(actual, spec, runableType) { const asyncExpectationFactory = function(actual, spec, runableType) {
return j$.Expectation.asyncFactory({ return j$.Expectation.asyncFactory({
matchersUtil: makeMatchersUtil(), matchersUtil: makeMatchersUtil(),
customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers, customAsyncMatchers: runnableResources[spec.id].customAsyncMatchers,
@@ -422,11 +422,11 @@ getJasmineRequireObj().Env = function(j$) {
return spec.addExpectationResult(passed, result); return spec.addExpectationResult(passed, result);
} }
}; };
var suiteAsyncExpectationFactory = function(actual, suite) { const suiteAsyncExpectationFactory = function(actual, suite) {
return asyncExpectationFactory(actual, suite, 'Suite'); return asyncExpectationFactory(actual, suite, 'Suite');
}; };
var specAsyncExpectationFactory = function(actual, suite) { const specAsyncExpectationFactory = function(actual, suite) {
return asyncExpectationFactory(actual, suite, 'Spec'); return asyncExpectationFactory(actual, suite, 'Spec');
}; };

View File

@@ -1,5 +1,5 @@
getJasmineRequireObj().ExceptionFormatter = function(j$) { getJasmineRequireObj().ExceptionFormatter = function(j$) {
var ignoredProperties = [ const ignoredProperties = [
'name', 'name',
'message', 'message',
'stack', 'stack',
@@ -13,9 +13,10 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
]; ];
function ExceptionFormatter(options) { function ExceptionFormatter(options) {
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile(); const jasmineFile =
(options && options.jasmineFile) || j$.util.jasmineFile();
this.message = function(error) { this.message = function(error) {
var message = ''; let message = '';
if (error.jasmineMessage) { if (error.jasmineMessage) {
message += error.jasmineMessage; message += error.jasmineMessage;
@@ -43,9 +44,9 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return null; return null;
} }
var stackTrace = new j$.StackTrace(error); const stackTrace = new j$.StackTrace(error);
var lines = filterJasmine(stackTrace); const lines = filterJasmine(stackTrace);
var result = ''; let result = '';
if (stackTrace.message && !omitMessage) { if (stackTrace.message && !omitMessage) {
lines.unshift(stackTrace.message); lines.unshift(stackTrace.message);
@@ -58,9 +59,9 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
}; };
function filterJasmine(stackTrace) { function filterJasmine(stackTrace) {
var result = [], const result = [];
jasmineMarker = const jasmineMarker =
stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>'; stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
stackTrace.frames.forEach(function(frame) { stackTrace.frames.forEach(function(frame) {
if (frame.file !== jasmineFile) { if (frame.file !== jasmineFile) {
@@ -78,10 +79,10 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return; return;
} }
var result = {}; const result = {};
var empty = true; let empty = true;
for (var prop in error) { for (const prop in error) {
if (j$.util.arrayContains(ignoredProperties, prop)) { if (j$.util.arrayContains(ignoredProperties, prop)) {
continue; continue;
} }

View File

@@ -6,8 +6,8 @@ getJasmineRequireObj().Expectation = function(j$) {
function Expectation(options) { function Expectation(options) {
this.expector = new j$.Expector(options); this.expector = new j$.Expector(options);
var customMatchers = options.customMatchers || {}; const customMatchers = options.customMatchers || {};
for (var matcherName in customMatchers) { for (const matcherName in customMatchers) {
this[matcherName] = wrapSyncCompare( this[matcherName] = wrapSyncCompare(
matcherName, matcherName,
customMatchers[matcherName] customMatchers[matcherName]
@@ -77,8 +77,8 @@ getJasmineRequireObj().Expectation = function(j$) {
function AsyncExpectation(options) { function AsyncExpectation(options) {
this.expector = new j$.Expector(options); this.expector = new j$.Expector(options);
var customAsyncMatchers = options.customAsyncMatchers || {}; const customAsyncMatchers = options.customAsyncMatchers || {};
for (var matcherName in customAsyncMatchers) { for (const matcherName in customAsyncMatchers) {
this[matcherName] = wrapAsyncCompare( this[matcherName] = wrapAsyncCompare(
matcherName, matcherName,
customAsyncMatchers[matcherName] customAsyncMatchers[matcherName]
@@ -134,36 +134,34 @@ getJasmineRequireObj().Expectation = function(j$) {
function wrapSyncCompare(name, matcherFactory) { function wrapSyncCompare(name, matcherFactory) {
return function() { return function() {
var result = this.expector.compare(name, matcherFactory, arguments); const result = this.expector.compare(name, matcherFactory, arguments);
this.expector.processResult(result); this.expector.processResult(result);
}; };
} }
function wrapAsyncCompare(name, matcherFactory) { function wrapAsyncCompare(name, matcherFactory) {
return function() { return function() {
var self = this;
// Capture the call stack here, before we go async, so that it will contain // Capture the call stack here, before we go async, so that it will contain
// frames that are relevant to the user instead of just parts of Jasmine. // frames that are relevant to the user instead of just parts of Jasmine.
var errorForStack = j$.util.errorWithStack(); const errorForStack = j$.util.errorWithStack();
return this.expector return this.expector
.compare(name, matcherFactory, arguments) .compare(name, matcherFactory, arguments)
.then(function(result) { .then(result => {
self.expector.processResult(result, errorForStack); this.expector.processResult(result, errorForStack);
}); });
}; };
} }
function addCoreMatchers(prototype, matchers, wrapper) { function addCoreMatchers(prototype, matchers, wrapper) {
for (var matcherName in matchers) { for (const matcherName in matchers) {
var matcher = matchers[matcherName]; const matcher = matchers[matcherName];
prototype[matcherName] = wrapper(matcherName, matcher); prototype[matcherName] = wrapper(matcherName, matcher);
} }
} }
function addFilter(source, filter) { function addFilter(source, filter) {
var result = Object.create(source); const result = Object.create(source);
result.expector = source.expector.addFilter(filter); result.expector = source.expector.addFilter(filter);
return result; return result;
} }
@@ -188,7 +186,7 @@ getJasmineRequireObj().Expectation = function(j$) {
return result; return result;
} }
var syncNegatingFilter = { const syncNegatingFilter = {
selectComparisonFunc: function(matcher) { selectComparisonFunc: function(matcher) {
function defaultNegativeCompare() { function defaultNegativeCompare() {
return negate(matcher.compare.apply(null, arguments)); return negate(matcher.compare.apply(null, arguments));
@@ -199,7 +197,7 @@ getJasmineRequireObj().Expectation = function(j$) {
buildFailureMessage: negatedFailureMessage buildFailureMessage: negatedFailureMessage
}; };
var asyncNegatingFilter = { const asyncNegatingFilter = {
selectComparisonFunc: function(matcher) { selectComparisonFunc: function(matcher) {
function defaultNegativeCompare() { function defaultNegativeCompare() {
return matcher.compare.apply(this, arguments).then(negate); return matcher.compare.apply(this, arguments).then(negate);
@@ -210,10 +208,10 @@ getJasmineRequireObj().Expectation = function(j$) {
buildFailureMessage: negatedFailureMessage buildFailureMessage: negatedFailureMessage
}; };
var expectSettledPromiseFilter = { const expectSettledPromiseFilter = {
selectComparisonFunc: function(matcher) { selectComparisonFunc: function(matcher) {
return function(actual) { return function(actual) {
var matcherArgs = arguments; const matcherArgs = arguments;
return j$.isPending_(actual).then(function(isPending) { return j$.isPending_(actual).then(function(isPending) {
if (isPending) { if (isPending) {
@@ -236,9 +234,7 @@ getJasmineRequireObj().Expectation = function(j$) {
} }
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) { ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
var nl = msg.indexOf('\n'); if (msg.indexOf('\n') === -1) {
if (nl === -1) {
return this.message + ': ' + msg; return this.message + ': ' + msg;
} else { } else {
return this.message + ':\n' + indent(msg); return this.message + ':\n' + indent(msg);

View File

@@ -63,7 +63,7 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
} }
let error = options.error; let error = options.error;
if (!error) { if (!error) {
if (options.errorForStack) { if (options.errorForStack) {
error = options.errorForStack; error = options.errorForStack;