diff --git a/test/fixtures/clock.png b/test/fixtures/clock.png new file mode 100644 index 0000000..f0729bf Binary files /dev/null and b/test/fixtures/clock.png differ diff --git a/test/image.test.js b/test/image.test.js new file mode 100644 index 0000000..36719ff --- /dev/null +++ b/test/image.test.js @@ -0,0 +1,56 @@ + +/** + * Module dependencies. + */ + +var Canvas = require('canvas') + , Image = Canvas.Image; + +var png = __dirname + '/fixtures/clock.png'; + +module.exports = { + 'tset Image': function(assert){ + assert.ok(Image instanceof Function); + }, + + 'test Image#onload': function(assert, beforeExit){ + var img = new Image + , n = 0; + + assert.strictEqual(false, img.complete); + img.onload = function(){ + assert.strictEqual(true, img.complete); + ++n; + }; + + img.src = png; + assert.equal(img.src, png); + + beforeExit(function(){ + assert.equal(1, n); + }); + }, + + 'test Image#onerror': function(assert, beforeExit){ + var img = new Image + , n = 0; + + assert.strictEqual(false, img.complete); + img.onload = function(){ + assert.fail('called onload'); + }; + + img.onerror = function(err){ + assert.strictEqual(false, img.complete); + assert.ok(err instanceof Error, 'did not invoke onerror() with error'); + ++n; + }; + + img.src = png + 's'; + assert.equal(img.src, png + 's'); + + beforeExit(function(){ + assert.equal(1, n); + }); + } +}; \ No newline at end of file