Added a pixelEquals function that checks if a given pixel of a canvas is equal to a provided rgba value #84

wants to merge 1 commit into


None yet
2 participants

The title pretty much says everything. I needed the test function for a project of mine and implemented it. I thought I might aswell share it with the qunit project.
Howto use pixelEquals:

var canvas = document.getElementById('myCanvas');
// draw something to the canvas that will set the pixel 
// at x = 50, y = 100 to fully red, 50% transparency

pixelEquals(canvas, 50, 100, 255, 0, 0, 127); // will yield a successfull test

I also added a testcase to the test suite. However, I wasn't sure where to actually put it, so I just added it to the end of test.js. Of course a canvas element is required for the test. I added it to the test's index.html.

If you like it, use it :)

Best regards,

Added pixelEquals (+ tests).
pixelEquals compares a specified pixel in a canvas to given rgba values. Tests might need rework.

jzaefferer commented Feb 21, 2011

Thanks. Leaving the ticket open to add this to the documentation eventually, but won't add it to QUnit.


jzaefferer commented Aug 5, 2011

Thanks! I've (finally) landed this, as the first official addon:
Renamed the method to pixelEqual to match the naming convention, and its namespaced within QUnit (no need to add more globals really).

@jzaefferer jzaefferer closed this Aug 5, 2011

cool, thank you!

marrocamp pushed a commit to marrocamp/testcc that referenced this pull request Mar 7, 2016

Introducing the first QUnit addon, based on qunitjs/qunit#84 - adds Q…
…Unit.pixelEqual assertion method, along with example tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment