Better pretty printing for typed arrays

This commit is contained in:
ksvitkovsky
2017-08-01 23:58:33 +04:00
committed by Gregg Van Hove
parent acc8c23bf4
commit 4fc177d5ae
6 changed files with 61 additions and 1 deletions

View File

@@ -211,6 +211,16 @@ describe("toEqual", function() {
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches between arrays of different types", function() {
jasmine.getEnv().requireFunctioningTypedArrays();
var actual = new Uint32Array([1, 2, 3]),
expected = new Uint16Array([1, 2, 3]),
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
expect(compareEquals(actual, expected).message).toEqual(message);
});
it("reports mismatches involving NaN", function() {
var actual = {x: 0},
expected = {x: 0/0},

View File

@@ -0,0 +1,20 @@
(function(env) {
function hasFunctioningTypedArrays() {
if (typeof Uint32Array === 'undefined') { return false; }
try {
var a = new Uint32Array([1, 2, 3]);
if (a.length !== 3) { return false; }
return true;
} catch(e) {
return false;
}
}
env.requireFunctioningTypedArrays = function() {
if (!hasFunctioningTypedArrays()) {
env.pending("Browser has incomplete or missing support for typed arrays");
}
};
})(jasmine.getEnv());

View File

@@ -9,6 +9,7 @@
"helpers/asyncAwait.js",
"helpers/checkForSet.js",
"helpers/checkForMap.js",
"helpers/checkForTypedArrays.js",
"helpers/nodeDefineJasmineUnderTest.js"
],
"random": true

View File

@@ -20,6 +20,7 @@ helpers:
- 'helpers/BrowserFlags.js'
- 'helpers/checkForSet.js'
- 'helpers/checkForMap.js'
- 'helpers/checkForTypedArrays.js'
- 'helpers/defineJasmineUnderTest.js'
spec_files:
- '**/*[Ss]pec.js'