Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 031f7ca

Browse files
committed
Refactor canvas tests into other test sections.
1 parent c7a4d89 commit 031f7ca

File tree

1 file changed

+44
-68
lines changed

1 file changed

+44
-68
lines changed

test/test.js

Lines changed: 44 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -150,31 +150,33 @@
150150
expect(img.onerror).to.be.an.instanceOf(Function)
151151
})
152152

153-
it('Load image url', function (done) {
153+
it('Load image url as img element', function (done) {
154154
expect(
155155
loadImage(imageUrlGIF, function (img) {
156+
expect(img.nodeName.toLowerCase()).to.equal('img')
156157
expect(img.width).to.equal(60)
157158
expect(img.height).to.equal(40)
158159
done()
159160
})
160161
).to.be.ok
161162
})
162163

163-
it('Load image blob', function (done) {
164+
it('Load image blob as img element', function (done) {
164165
expect(
165166
loadImage(blobGIF, function (img) {
167+
expect(img.nodeName.toLowerCase()).to.equal('img')
166168
expect(img.width).to.equal(60)
167169
expect(img.height).to.equal(40)
168170
done()
169171
})
170172
).to.be.ok
171173
})
172174

173-
it('Return image loading error to callback', function (done) {
175+
it('Handle image loading error', function (done) {
174176
expect(
175-
loadImage('404', function (img) {
176-
expect(img).to.be.an.instanceOf(window.Event)
177-
expect(img.type).to.equal('error')
177+
loadImage('404', function (err) {
178+
expect(err).to.be.an.instanceOf(window.Event)
179+
expect(err.type).to.equal('error')
178180
done()
179181
})
180182
).to.be.ok
@@ -190,6 +192,20 @@
190192
).to.be.ok
191193
})
192194

195+
it('Load image as canvas for canvas: true', function (done) {
196+
expect(
197+
loadImage(
198+
imageUrlGIF,
199+
function (img) {
200+
expect(img.getContext).to.be.an.instanceOf(Function)
201+
expect(img.nodeName.toLowerCase()).to.equal('canvas')
202+
done()
203+
},
204+
{ canvas: true }
205+
)
206+
).to.be.ok
207+
})
208+
193209
describe('ObjectURL revoke', function () {
194210
// Using XMLHttpRequest via the request helper function to test Object
195211
// URLs to work around Edge Legacy and IE caching image URLs.
@@ -431,6 +447,28 @@
431447
)
432448
).to.be.ok
433449
})
450+
451+
it('Accept a canvas element as source image', function (done) {
452+
expect(
453+
loadImage(
454+
blobGIF,
455+
function (img) {
456+
expect(img.getContext).to.be.an.instanceOf(Function)
457+
expect(img.nodeName.toLowerCase()).to.equal('canvas')
458+
// eslint-disable-next-line no-param-reassign
459+
img = loadImage.scale(img, {
460+
maxWidth: 30
461+
})
462+
expect(img.getContext).to.be.an.instanceOf(Function)
463+
expect(img.nodeName.toLowerCase()).to.equal('canvas')
464+
expect(img.width).to.equal(30)
465+
expect(img.height).to.equal(20)
466+
done()
467+
},
468+
{ canvas: true }
469+
)
470+
).to.be.ok
471+
})
434472
})
435473

436474
describe('contain', function () {
@@ -2235,68 +2273,6 @@
22352273
})
22362274
})
22372275

2238-
describe('Canvas', function () {
2239-
it('Return img element to callback if canvas is not true', function (done) {
2240-
expect(
2241-
loadImage(blobGIF, function (img) {
2242-
expect(img.getContext).to.be.undefined
2243-
expect(img.nodeName.toLowerCase()).to.equal('img')
2244-
done()
2245-
})
2246-
).to.be.ok
2247-
})
2248-
2249-
it('Return canvas element to callback if canvas is true', function (done) {
2250-
expect(
2251-
loadImage(
2252-
blobGIF,
2253-
function (img) {
2254-
expect(img.getContext).to.be.an.instanceOf(Function)
2255-
expect(img.nodeName.toLowerCase()).to.equal('canvas')
2256-
done()
2257-
},
2258-
{ canvas: true }
2259-
)
2260-
).to.be.ok
2261-
})
2262-
2263-
it('Return scaled canvas element to callback', function (done) {
2264-
expect(
2265-
loadImage(
2266-
blobGIF,
2267-
function (img) {
2268-
expect(img.getContext).to.be.an.instanceOf(Function)
2269-
expect(img.nodeName.toLowerCase()).to.equal('canvas')
2270-
expect(img.width).to.equal(30)
2271-
expect(img.height).to.equal(20)
2272-
done()
2273-
},
2274-
{ canvas: true, maxWidth: 30 }
2275-
)
2276-
).to.be.ok
2277-
})
2278-
2279-
it('Accept a canvas element as parameter for loadImage.scale', function (done) {
2280-
expect(
2281-
loadImage(
2282-
blobGIF,
2283-
function (img) {
2284-
// eslint-disable-next-line no-param-reassign
2285-
img = loadImage.scale(img, {
2286-
maxWidth: 30
2287-
})
2288-
expect(img.getContext).to.be.an.instanceOf(Function)
2289-
expect(img.nodeName.toLowerCase()).to.equal('canvas')
2290-
expect(img.width).to.equal(30)
2291-
expect(img.height).to.equal(20)
2292-
done()
2293-
},
2294-
{ canvas: true }
2295-
)
2296-
).to.be.ok
2297-
})
2298-
})
2299-
23002276
describe('Metadata', function () {
23012277
it('Parse EXIF tags', function (done) {
23022278
loadImage.parseMetaData(blobJPEG, function (data) {

0 commit comments

Comments
 (0)