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

View File

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

View File

@@ -6,8 +6,8 @@ getJasmineRequireObj().Expectation = function(j$) {
function Expectation(options) {
this.expector = new j$.Expector(options);
var customMatchers = options.customMatchers || {};
for (var matcherName in customMatchers) {
const customMatchers = options.customMatchers || {};
for (const matcherName in customMatchers) {
this[matcherName] = wrapSyncCompare(
matcherName,
customMatchers[matcherName]
@@ -77,8 +77,8 @@ getJasmineRequireObj().Expectation = function(j$) {
function AsyncExpectation(options) {
this.expector = new j$.Expector(options);
var customAsyncMatchers = options.customAsyncMatchers || {};
for (var matcherName in customAsyncMatchers) {
const customAsyncMatchers = options.customAsyncMatchers || {};
for (const matcherName in customAsyncMatchers) {
this[matcherName] = wrapAsyncCompare(
matcherName,
customAsyncMatchers[matcherName]
@@ -134,36 +134,34 @@ getJasmineRequireObj().Expectation = function(j$) {
function wrapSyncCompare(name, matcherFactory) {
return function() {
var result = this.expector.compare(name, matcherFactory, arguments);
const result = this.expector.compare(name, matcherFactory, arguments);
this.expector.processResult(result);
};
}
function wrapAsyncCompare(name, matcherFactory) {
return function() {
var self = this;
// 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.
var errorForStack = j$.util.errorWithStack();
const errorForStack = j$.util.errorWithStack();
return this.expector
.compare(name, matcherFactory, arguments)
.then(function(result) {
self.expector.processResult(result, errorForStack);
.then(result => {
this.expector.processResult(result, errorForStack);
});
};
}
function addCoreMatchers(prototype, matchers, wrapper) {
for (var matcherName in matchers) {
var matcher = matchers[matcherName];
for (const matcherName in matchers) {
const matcher = matchers[matcherName];
prototype[matcherName] = wrapper(matcherName, matcher);
}
}
function addFilter(source, filter) {
var result = Object.create(source);
const result = Object.create(source);
result.expector = source.expector.addFilter(filter);
return result;
}
@@ -188,7 +186,7 @@ getJasmineRequireObj().Expectation = function(j$) {
return result;
}
var syncNegatingFilter = {
const syncNegatingFilter = {
selectComparisonFunc: function(matcher) {
function defaultNegativeCompare() {
return negate(matcher.compare.apply(null, arguments));
@@ -199,7 +197,7 @@ getJasmineRequireObj().Expectation = function(j$) {
buildFailureMessage: negatedFailureMessage
};
var asyncNegatingFilter = {
const asyncNegatingFilter = {
selectComparisonFunc: function(matcher) {
function defaultNegativeCompare() {
return matcher.compare.apply(this, arguments).then(negate);
@@ -210,10 +208,10 @@ getJasmineRequireObj().Expectation = function(j$) {
buildFailureMessage: negatedFailureMessage
};
var expectSettledPromiseFilter = {
const expectSettledPromiseFilter = {
selectComparisonFunc: function(matcher) {
return function(actual) {
var matcherArgs = arguments;
const matcherArgs = arguments;
return j$.isPending_(actual).then(function(isPending) {
if (isPending) {
@@ -236,9 +234,7 @@ getJasmineRequireObj().Expectation = function(j$) {
}
ContextAddingFilter.prototype.modifyFailureMessage = function(msg) {
var nl = msg.indexOf('\n');
if (nl === -1) {
if (msg.indexOf('\n') === -1) {
return this.message + ': ' + msg;
} else {
return this.message + ':\n' + indent(msg);

View File

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