Fix the review notices

This commit is contained in:
Surgie Finesse
2021-03-22 19:11:03 +10:00
parent f7f928fdd3
commit 37073e2768
5 changed files with 49 additions and 36 deletions

View File

@@ -885,18 +885,23 @@ describe('matchersUtil', function() {
);
});
it("passes for ArrayBuffers with same length and content", function() {
var buffer1 = new ArrayBuffer(4);
var buffer2 = new ArrayBuffer(4);
it('passes for ArrayBuffers with same length and content', function() {
jasmine.getEnv().requireFunctioningArrayBuffers();
var buffer1 = new ArrayBuffer(4); // eslint-disable-line compat/compat
var buffer2 = new ArrayBuffer(4); // eslint-disable-line compat/compat
expect(jasmineUnderTest.matchersUtil.equals(buffer1, buffer2)).toBe(true);
});
it("fails for ArrayBuffers with same length but different content", function() {
var buffer1 = new ArrayBuffer(4);
var buffer2 = new ArrayBuffer(4);
var array1 = new Uint8Array(buffer1);
it('fails for ArrayBuffers with same length but different content', function() {
jasmine.getEnv().requireFunctioningTypedArrays();
jasmine.getEnv().requireFunctioningArrayBuffers();
var buffer1 = new ArrayBuffer(4); // eslint-disable-line compat/compat
var buffer2 = new ArrayBuffer(4); // eslint-disable-line compat/compat
var array1 = new Uint8Array(buffer1); // eslint-disable-line compat/compat
array1[0] = 1;
expect(jasmineUnderTest.matchersUtil.equals(buffer1, buffer2)).toBe(false);
expect(jasmineUnderTest.matchersUtil.equals(buffer1, buffer2)).toBe(
false
);
});
describe('when running in an environment with array polyfills', function() {

View File

@@ -0,0 +1,25 @@
/* eslint-disable compat/compat */
(function(env) {
function hasFunctioningArrayBuffers() {
if (typeof ArrayBuffer === 'undefined') {
return false;
}
try {
var buffer = new ArrayBuffer(2);
var view8bit = new Uint8Array(buffer);
var view16bit = new Uint16Array(buffer);
view16bit[0] = 0xabcd;
return view8bit[0] === 0xcd && view8bit[1] === 0xab;
} catch (e) {
return false;
}
}
env.requireFunctioningArrayBuffers = function() {
env.requireFunctioningTypedArrays();
if (!hasFunctioningArrayBuffers()) {
env.pending('Browser has incomplete or missing support for ArrayBuffer');
}
};
})(jasmine.getEnv());

View File

@@ -20,6 +20,7 @@ module.exports = {
'helpers/asyncAwait.js',
'helpers/generator.js',
'helpers/BrowserFlags.js',
'helpers/checkForArrayBuffer.js',
'helpers/checkForMap.js',
'helpers/checkForSet.js',
'helpers/checkForSymbol.js',

View File

@@ -7,6 +7,7 @@
"helpers": [
"helpers/asyncAwait.js",
"helpers/generator.js",
"helpers/checkForArrayBuffer.js",
"helpers/checkForMap.js",
"helpers/checkForSet.js",
"helpers/checkForSymbol.js",

View File

@@ -269,37 +269,18 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
diffBuilder.recordMismatch();
}
return result;
// RegExps are compared by their source patterns and flags.
case '[object ArrayBuffer]':
// If we have an instance of ArrayBuffer the Uint8Array ctor
// will be defined as well
var arrayA = new Uint8Array(a);
var arrayB = new Uint8Array(b);
var arrayALength = arrayA.length;
var arrayBLength = arrayB.length;
diffBuilder.withPath('length', function() {
if (arrayALength !== arrayBLength) {
diffBuilder.record(arrayALength, arrayBLength);
result = false;
}
});
for (i = 0; i < arrayALength || i < arrayBLength; i++) {
diffBuilder.withPath(i, function() {
if (i >= arrayBLength) {
diffBuilder.record(arrayA[i], void 0, actualArrayIsLongerFormatter);
result = false;
} else if (i >= arrayALength){
diffBuilder.record(void 0, arrayB[i], actualArrayIsLongerFormatter);
result = false;
} else if (arrayA[i] !== arrayB[i]) {
diffBuilder.record(arrayA[i], arrayB[i]);
result = false;
}
});
}
return result;
return self.eq_(
new Uint8Array(a), // eslint-disable-line compat/compat
new Uint8Array(b), // eslint-disable-line compat/compat
aStack,
bStack,
customTesters,
diffBuilder
);
// RegExps are compared by their source patterns and flags.
case '[object RegExp]':
return (
a.source == b.source &&