Replace isArray helper with native Array.isArray
This commit is contained in:
@@ -903,7 +903,7 @@ jasmineRequire.htmlReporterUtils = function(j$) {
|
||||
const el = document.createElement(type);
|
||||
let children;
|
||||
|
||||
if (j$.private.isArray(childrenArrayOrVarArgs)) {
|
||||
if (Array.isArray(childrenArrayOrVarArgs)) {
|
||||
children = childrenArrayOrVarArgs;
|
||||
} else {
|
||||
children = [];
|
||||
|
||||
@@ -275,10 +275,6 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
}
|
||||
});
|
||||
|
||||
j$.private.isArray = function(value) {
|
||||
return j$.private.isA('Array', value);
|
||||
};
|
||||
|
||||
j$.private.isObject = function(value) {
|
||||
return (
|
||||
value !== undefined && value !== null && j$.private.isA('Object', value)
|
||||
@@ -2332,7 +2328,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
||||
}
|
||||
|
||||
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
|
||||
if (!j$.private.isArray(this.sample)) {
|
||||
if (!Array.isArray(this.sample)) {
|
||||
throw new Error(
|
||||
'You must provide an array to arrayContaining, not ' +
|
||||
j$.private.basicPrettyPrinter(this.sample) +
|
||||
@@ -2343,7 +2339,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
||||
// If the actual parameter is not an array, we can fail immediately, since it couldn't
|
||||
// possibly be an "array containing" anything. However, we also want an empty sample
|
||||
// array to match anything, so we need to double-check we aren't in that case
|
||||
if (!j$.private.isArray(other) && this.sample.length > 0) {
|
||||
if (!Array.isArray(other) && this.sample.length > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2374,7 +2370,7 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
||||
other,
|
||||
matchersUtil
|
||||
) {
|
||||
if (!j$.private.isArray(this.sample)) {
|
||||
if (!Array.isArray(this.sample)) {
|
||||
throw new Error(
|
||||
'You must provide an array to arrayWithExactContents, not ' +
|
||||
j$.private.basicPrettyPrinter(this.sample) +
|
||||
@@ -2410,7 +2406,7 @@ getJasmineRequireObj().Empty = function(j$) {
|
||||
Empty.prototype.asymmetricMatch = function(other) {
|
||||
if (
|
||||
j$.private.isString(other) ||
|
||||
j$.private.isArray(other) ||
|
||||
Array.isArray(other) ||
|
||||
j$.private.isTypedArray(other)
|
||||
) {
|
||||
return other.length === 0;
|
||||
@@ -2525,7 +2521,7 @@ getJasmineRequireObj().NotEmpty = function(j$) {
|
||||
NotEmpty.prototype.asymmetricMatch = function(other) {
|
||||
if (
|
||||
j$.private.isString(other) ||
|
||||
j$.private.isArray(other) ||
|
||||
Array.isArray(other) ||
|
||||
j$.private.isTypedArray(other)
|
||||
) {
|
||||
return other.length !== 0;
|
||||
@@ -8263,7 +8259,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
} else if (
|
||||
value.toString &&
|
||||
typeof value === 'object' &&
|
||||
!j$.private.isArray(value) &&
|
||||
!Array.isArray(value) &&
|
||||
hasCustomToString(value)
|
||||
) {
|
||||
try {
|
||||
@@ -8275,15 +8271,12 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
} else if (this.seen.includes(value)) {
|
||||
this.emitScalar(
|
||||
'<circular reference: ' +
|
||||
(j$.private.isArray(value) ? 'Array' : 'Object') +
|
||||
(Array.isArray(value) ? 'Array' : 'Object') +
|
||||
'>'
|
||||
);
|
||||
} else if (
|
||||
j$.private.isArray(value) ||
|
||||
j$.private.isA('Object', value)
|
||||
) {
|
||||
} else if (Array.isArray(value) || j$.private.isA('Object', value)) {
|
||||
this.seen.push(value);
|
||||
if (j$.private.isArray(value)) {
|
||||
if (Array.isArray(value)) {
|
||||
this.emitArray(value);
|
||||
} else {
|
||||
this.emitObject(value);
|
||||
@@ -8306,10 +8299,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
}
|
||||
|
||||
iterateObject(obj, fn) {
|
||||
const objKeys = j$.private.MatchersUtil.keys(
|
||||
obj,
|
||||
j$.private.isArray(obj)
|
||||
);
|
||||
const objKeys = j$.private.MatchersUtil.keys(obj, Array.isArray(obj));
|
||||
const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
@@ -10237,7 +10227,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
|
||||
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
||||
const baseNameIsCollection =
|
||||
j$.private.isObject(baseName) || j$.private.isArray(baseName);
|
||||
j$.private.isObject(baseName) || Array.isArray(baseName);
|
||||
|
||||
if (baseNameIsCollection) {
|
||||
propertyNames = methodNames;
|
||||
@@ -10283,7 +10273,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
|
||||
function normalizeKeyValues(object) {
|
||||
const result = [];
|
||||
if (j$.private.isArray(object)) {
|
||||
if (Array.isArray(object)) {
|
||||
for (let i = 0; i < object.length; i++) {
|
||||
result.push([object[i]]);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ describe('Runner', function() {
|
||||
function arrayNotContaining(item) {
|
||||
return {
|
||||
asymmetricMatch(other, matchersUtil) {
|
||||
if (!jasmine.private.isArray(other)) {
|
||||
if (!Array.isArray(other)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
describe('util', function() {
|
||||
describe('isArray', function() {
|
||||
it('should return true if the argument is an array', function() {
|
||||
expect(privateUnderTest.isArray([])).toBe(true);
|
||||
expect(privateUnderTest.isArray(['a'])).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if the argument is not an array', function() {
|
||||
expect(privateUnderTest.isArray(undefined)).toBe(false);
|
||||
expect(privateUnderTest.isArray({})).toBe(false);
|
||||
expect(privateUnderTest.isArray(function() {})).toBe(false);
|
||||
expect(privateUnderTest.isArray('foo')).toBe(false);
|
||||
expect(privateUnderTest.isArray(5)).toBe(false);
|
||||
expect(privateUnderTest.isArray(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isObject', function() {
|
||||
it('should return true if the argument is an object', function() {
|
||||
expect(privateUnderTest.isObject({})).toBe(true);
|
||||
|
||||
@@ -59,7 +59,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
} else if (
|
||||
value.toString &&
|
||||
typeof value === 'object' &&
|
||||
!j$.private.isArray(value) &&
|
||||
!Array.isArray(value) &&
|
||||
hasCustomToString(value)
|
||||
) {
|
||||
try {
|
||||
@@ -71,15 +71,12 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
} else if (this.seen.includes(value)) {
|
||||
this.emitScalar(
|
||||
'<circular reference: ' +
|
||||
(j$.private.isArray(value) ? 'Array' : 'Object') +
|
||||
(Array.isArray(value) ? 'Array' : 'Object') +
|
||||
'>'
|
||||
);
|
||||
} else if (
|
||||
j$.private.isArray(value) ||
|
||||
j$.private.isA('Object', value)
|
||||
) {
|
||||
} else if (Array.isArray(value) || j$.private.isA('Object', value)) {
|
||||
this.seen.push(value);
|
||||
if (j$.private.isArray(value)) {
|
||||
if (Array.isArray(value)) {
|
||||
this.emitArray(value);
|
||||
} else {
|
||||
this.emitObject(value);
|
||||
@@ -102,10 +99,7 @@ getJasmineRequireObj().makePrettyPrinter = function(j$) {
|
||||
}
|
||||
|
||||
iterateObject(obj, fn) {
|
||||
const objKeys = j$.private.MatchersUtil.keys(
|
||||
obj,
|
||||
j$.private.isArray(obj)
|
||||
);
|
||||
const objKeys = j$.private.MatchersUtil.keys(obj, Array.isArray(obj));
|
||||
const length = Math.min(objKeys.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
|
||||
@@ -21,7 +21,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
|
||||
this.createSpyObj = function(baseName, methodNames, propertyNames) {
|
||||
const baseNameIsCollection =
|
||||
j$.private.isObject(baseName) || j$.private.isArray(baseName);
|
||||
j$.private.isObject(baseName) || Array.isArray(baseName);
|
||||
|
||||
if (baseNameIsCollection) {
|
||||
propertyNames = methodNames;
|
||||
@@ -67,7 +67,7 @@ getJasmineRequireObj().SpyFactory = function(j$) {
|
||||
|
||||
function normalizeKeyValues(object) {
|
||||
const result = [];
|
||||
if (j$.private.isArray(object)) {
|
||||
if (Array.isArray(object)) {
|
||||
for (let i = 0; i < object.length; i++) {
|
||||
result.push([object[i]]);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
||||
}
|
||||
|
||||
ArrayContaining.prototype.asymmetricMatch = function(other, matchersUtil) {
|
||||
if (!j$.private.isArray(this.sample)) {
|
||||
if (!Array.isArray(this.sample)) {
|
||||
throw new Error(
|
||||
'You must provide an array to arrayContaining, not ' +
|
||||
j$.private.basicPrettyPrinter(this.sample) +
|
||||
@@ -17,7 +17,7 @@ getJasmineRequireObj().ArrayContaining = function(j$) {
|
||||
// If the actual parameter is not an array, we can fail immediately, since it couldn't
|
||||
// possibly be an "array containing" anything. However, we also want an empty sample
|
||||
// array to match anything, so we need to double-check we aren't in that case
|
||||
if (!j$.private.isArray(other) && this.sample.length > 0) {
|
||||
if (!Array.isArray(other) && this.sample.length > 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ getJasmineRequireObj().ArrayWithExactContents = function(j$) {
|
||||
other,
|
||||
matchersUtil
|
||||
) {
|
||||
if (!j$.private.isArray(this.sample)) {
|
||||
if (!Array.isArray(this.sample)) {
|
||||
throw new Error(
|
||||
'You must provide an array to arrayWithExactContents, not ' +
|
||||
j$.private.basicPrettyPrinter(this.sample) +
|
||||
|
||||
@@ -6,7 +6,7 @@ getJasmineRequireObj().Empty = function(j$) {
|
||||
Empty.prototype.asymmetricMatch = function(other) {
|
||||
if (
|
||||
j$.private.isString(other) ||
|
||||
j$.private.isArray(other) ||
|
||||
Array.isArray(other) ||
|
||||
j$.private.isTypedArray(other)
|
||||
) {
|
||||
return other.length === 0;
|
||||
|
||||
@@ -6,7 +6,7 @@ getJasmineRequireObj().NotEmpty = function(j$) {
|
||||
NotEmpty.prototype.asymmetricMatch = function(other) {
|
||||
if (
|
||||
j$.private.isString(other) ||
|
||||
j$.private.isArray(other) ||
|
||||
Array.isArray(other) ||
|
||||
j$.private.isTypedArray(other)
|
||||
) {
|
||||
return other.length !== 0;
|
||||
|
||||
@@ -77,10 +77,6 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
}
|
||||
});
|
||||
|
||||
j$.private.isArray = function(value) {
|
||||
return j$.private.isA('Array', value);
|
||||
};
|
||||
|
||||
j$.private.isObject = function(value) {
|
||||
return (
|
||||
value !== undefined && value !== null && j$.private.isA('Object', value)
|
||||
|
||||
@@ -5,7 +5,7 @@ jasmineRequire.htmlReporterUtils = function(j$) {
|
||||
const el = document.createElement(type);
|
||||
let children;
|
||||
|
||||
if (j$.private.isArray(childrenArrayOrVarArgs)) {
|
||||
if (Array.isArray(childrenArrayOrVarArgs)) {
|
||||
children = childrenArrayOrVarArgs;
|
||||
} else {
|
||||
children = [];
|
||||
|
||||
Reference in New Issue
Block a user