JS-ImageDiff Jasmine Demo:

Using the Jasmine matchers, it is possible to test Canvas. Sample images from the github imagediff demo. Example by humble software development.

Example:

  // Matchers
  beforeEach(function () {
    this.addMatchers(imagediff.jasmine);
  });

  // Test
  it('should convert be the same image', function () {

    var
      a = new Image(),
      b = new Image();
    a.src = 'images/1_normal_a.jpg';
    b.src = 'images/1_normal_a.jpg';

    waitsFor(function () {
      return a.complete & b.complete;
    }, 'image not loaded.', 2000);

    runs(function () {
      expect(a).toImageDiffEqual(b); // imagediff expects Image, Canvas, CanvasRenderingContext2D or ImageData
    });
  });
  
Fork me on GitHub