Skip to content

Instantly share code, notes, and snippets.

@juananpe
Created February 18, 2018 12:36
Show Gist options
  • Save juananpe/a79713f696bc0e8b9a67aed8b332f8dc to your computer and use it in GitHub Desktop.
Save juananpe/a79713f696bc0e8b9a67aed8b332f8dc to your computer and use it in GitHub Desktop.
qunit-assert-canvas.js
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