|
|
@ -150,4 +150,56 @@ describe('Image', function () { |
|
|
|
image.src = new Buffer(0); |
|
|
|
image.src = new Buffer(''); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should unbind Image#onload', function() { |
|
|
|
var img = new Image |
|
|
|
, onloadCalled = 0; |
|
|
|
|
|
|
|
img.onload = function() { |
|
|
|
onloadCalled += 1; |
|
|
|
}; |
|
|
|
|
|
|
|
img.src = png_checkers; |
|
|
|
assert.equal(img.src, png_checkers); |
|
|
|
assert.strictEqual(true, img.complete); |
|
|
|
assert.strictEqual(2, img.width); |
|
|
|
assert.strictEqual(2, img.height); |
|
|
|
|
|
|
|
assert.equal(onloadCalled, 1); |
|
|
|
|
|
|
|
onloadCalled = 0; |
|
|
|
img.onload = null; |
|
|
|
img.src = png_clock; |
|
|
|
assert.equal(img.src, png_clock); |
|
|
|
assert.strictEqual(true, img.complete); |
|
|
|
assert.strictEqual(320, img.width); |
|
|
|
assert.strictEqual(320, img.height); |
|
|
|
|
|
|
|
assert.equal(onloadCalled, 0); |
|
|
|
}); |
|
|
|
|
|
|
|
it('should unbind Image#onerror', function() { |
|
|
|
var img = new Image |
|
|
|
, onerrorCalled = 0; |
|
|
|
|
|
|
|
|
|
|
|
img.onload = function() { |
|
|
|
assert.fail('called onload'); |
|
|
|
}; |
|
|
|
|
|
|
|
img.onerror = function() { |
|
|
|
onerrorCalled += 1; |
|
|
|
}; |
|
|
|
|
|
|
|
img.src = png_clock + 's1'; |
|
|
|
assert.equal(img.src, png_clock + 's1'); |
|
|
|
|
|
|
|
assert.equal(onerrorCalled, 1); |
|
|
|
|
|
|
|
onerrorCalled = 0; |
|
|
|
img.onerror = null; |
|
|
|
img.src = png_clock + 's3'; |
|
|
|
assert.equal(img.src, png_clock + 's3'); |
|
|
|
assert.equal(onerrorCalled, 0); |
|
|
|
}); |
|
|
|
}); |
|
|
|