Lint-free test-extensions.js
This commit is contained in:
+20
-11
@@ -1,3 +1,5 @@
|
|||||||
|
/* global resemble:false */
|
||||||
|
|
||||||
// FIXME remove afterLoadXml as it uses the wrong XML parser on IE9
|
// FIXME remove afterLoadXml as it uses the wrong XML parser on IE9
|
||||||
|
|
||||||
// helper functions for async testing and other utility functions.
|
// helper functions for async testing and other utility functions.
|
||||||
@@ -70,6 +72,7 @@
|
|||||||
* Assert value is within some tolerance of a number.
|
* Assert value is within some tolerance of a number.
|
||||||
* @param {Number} n Number.
|
* @param {Number} n Number.
|
||||||
* @param {Number} tol Tolerance.
|
* @param {Number} tol Tolerance.
|
||||||
|
* @return {expect.Assertion} The assertion.
|
||||||
*/
|
*/
|
||||||
expect.Assertion.prototype.roughlyEqual = function(n, tol) {
|
expect.Assertion.prototype.roughlyEqual = function(n, tol) {
|
||||||
this.assert(
|
this.assert(
|
||||||
@@ -88,6 +91,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that a sinon spy was called.
|
* Assert that a sinon spy was called.
|
||||||
|
* @return {expect.Assertion} The assertion.
|
||||||
*/
|
*/
|
||||||
expect.Assertion.prototype.called = function() {
|
expect.Assertion.prototype.called = function() {
|
||||||
this.assert(
|
this.assert(
|
||||||
@@ -105,7 +109,7 @@
|
|||||||
function getChildNodes(node, options) {
|
function getChildNodes(node, options) {
|
||||||
// check whitespace
|
// check whitespace
|
||||||
if (options && options.includeWhiteSpace) {
|
if (options && options.includeWhiteSpace) {
|
||||||
return node.childNodes;
|
return node.childNodes;
|
||||||
} else {
|
} else {
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
for (var i = 0, ii = node.childNodes.length; i < ii; i++) {
|
for (var i = 0, ii = node.childNodes.length; i < ii; i++) {
|
||||||
@@ -154,9 +158,8 @@
|
|||||||
errors.push('nodeValue test failed | expected ' + nv1 + ' to equal ' +
|
errors.push('nodeValue test failed | expected ' + nv1 + ' to equal ' +
|
||||||
nv2);
|
nv2);
|
||||||
}
|
}
|
||||||
}
|
} else if (node1.nodeType === 1) {
|
||||||
// for element type nodes compare namespace, attributes, and children
|
// for element type nodes compare namespace, attributes, and children
|
||||||
else if (node1.nodeType === 1) {
|
|
||||||
// test namespace alias and uri
|
// test namespace alias and uri
|
||||||
if (node1.prefix || node2.prefix) {
|
if (node1.prefix || node2.prefix) {
|
||||||
if (testPrefix) {
|
if (testPrefix) {
|
||||||
@@ -208,7 +211,6 @@
|
|||||||
errors.push('Number of attributes test failed for: ' + node1.nodeName +
|
errors.push('Number of attributes test failed for: ' + node1.nodeName +
|
||||||
' | expected ' + node1AttrLen + ' to equal ' + node2AttrLen);
|
' | expected ' + node1AttrLen + ' to equal ' + node2AttrLen);
|
||||||
}
|
}
|
||||||
var gv, ev;
|
|
||||||
for (var name in node1Attr) {
|
for (var name in node1Attr) {
|
||||||
if (node2Attr[name] === undefined) {
|
if (node2Attr[name] === undefined) {
|
||||||
errors.push('Attribute name ' + node1Attr[name].name +
|
errors.push('Attribute name ' + node1Attr[name].name +
|
||||||
@@ -272,6 +274,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the XML document sort of equals another XML document.
|
* Checks if the XML document sort of equals another XML document.
|
||||||
|
* @param {Object} obj The other object.
|
||||||
|
* @param {Object} options The options.
|
||||||
|
* @return {expect.Assertion} The assertion.
|
||||||
*/
|
*/
|
||||||
expect.Assertion.prototype.xmleql = function(obj, options) {
|
expect.Assertion.prototype.xmleql = function(obj, options) {
|
||||||
if (obj && obj.nodeType == 9) {
|
if (obj && obj.nodeType == 9) {
|
||||||
@@ -301,6 +306,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the array sort of equals another array.
|
* Checks if the array sort of equals another array.
|
||||||
|
* @param {Object} obj The other object.
|
||||||
|
* @return {expect.Assertion} The assertion.
|
||||||
*/
|
*/
|
||||||
expect.Assertion.prototype.arreql = function(obj) {
|
expect.Assertion.prototype.arreql = function(obj) {
|
||||||
this.assert(
|
this.assert(
|
||||||
@@ -319,6 +326,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the array sort of equals another array (allows NaNs to be equal).
|
* Checks if the array sort of equals another array (allows NaNs to be equal).
|
||||||
|
* @param {Object} obj The other object.
|
||||||
|
* @return {expect.Assertion} The assertion.
|
||||||
*/
|
*/
|
||||||
expect.Assertion.prototype.arreqlNaN = function(obj) {
|
expect.Assertion.prototype.arreqlNaN = function(obj) {
|
||||||
function compare(a, b) {
|
function compare(a, b) {
|
||||||
@@ -359,7 +368,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
global.assertWebGL = function(map) {
|
global.assertWebGL = function(map) {
|
||||||
if(!ol.has.WEBGL) {
|
if (!ol.has.WEBGL) {
|
||||||
expect().fail('No WebGL support!');
|
expect().fail('No WebGL support!');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -373,7 +382,7 @@
|
|||||||
.compareTo(canvas.getContext('2d').getImageData(
|
.compareTo(canvas.getContext('2d').getImageData(
|
||||||
0, 0, canvas.width, canvas.height))
|
0, 0, canvas.width, canvas.height))
|
||||||
.onComplete(function(data) {
|
.onComplete(function(data) {
|
||||||
if(!data.isSameDimensions) {
|
if (!data.isSameDimensions) {
|
||||||
expect().fail(
|
expect().fail(
|
||||||
'The dimensions of the reference image and ' +
|
'The dimensions of the reference image and ' +
|
||||||
'the test canvas are not the same.');
|
'the test canvas are not the same.');
|
||||||
@@ -388,8 +397,8 @@
|
|||||||
expect(data.misMatchPercentage).to.be.below(tolerance);
|
expect(data.misMatchPercentage).to.be.below(tolerance);
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
global.resembleCanvas = resembleCanvas;
|
global.resembleCanvas = resembleCanvas;
|
||||||
|
|
||||||
function expectResembleCanvas(map, referenceImage, tolerance, done) {
|
function expectResembleCanvas(map, referenceImage, tolerance, done) {
|
||||||
@@ -398,7 +407,7 @@
|
|||||||
var canvas = event.context.canvas;
|
var canvas = event.context.canvas;
|
||||||
resembleCanvas(canvas, referenceImage, tolerance, done);
|
resembleCanvas(canvas, referenceImage, tolerance, done);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
function expectResembleWebGL(map, referenceImage, tolerance, done) {
|
function expectResembleWebGL(map, referenceImage, tolerance, done) {
|
||||||
map.render();
|
map.render();
|
||||||
@@ -421,7 +430,7 @@
|
|||||||
|
|
||||||
resembleCanvas(canvas, referenceImage, tolerance, done);
|
resembleCanvas(canvas, referenceImage, tolerance, done);
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that the given map resembles a reference image.
|
* Assert that the given map resembles a reference image.
|
||||||
|
|||||||
Reference in New Issue
Block a user