Created
February 18, 2018 12:36
-
-
Save juananpe/a79713f696bc0e8b9a67aed8b332f8dc to your computer and use it in GitHub Desktop.
qunit-assert-canvas.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QUnit.extend(QUnit.assert, { | |
pixelEqual: function(canvas, x, y, r, g, b, a, message) { | |
var actual = Array.prototype.slice.apply(canvas.getContext("2d").getImageData(x, y, 1, 1).data), | |
expected = [r, g, b, a]; | |
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message); | |
}, | |
pixelNotEqual: function(canvas, x, y, r, g, b, a, message) { | |
var actual = Array.prototype.slice.apply(canvas.getContext("2d").getImageData(x, y, 1, 1).data), | |
expected = [r, g, b, a]; | |
message = message || "should not be " + expected; | |
QUnit.push(!QUnit.equiv(actual, expected), actual, expected, message); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment