|
150 | 150 | expect(img.onerror).to.be.an.instanceOf(Function) |
151 | 151 | }) |
152 | 152 |
|
153 | | - it('Load image url', function (done) { |
| 153 | + it('Load image url as img element', function (done) { |
154 | 154 | expect( |
155 | 155 | loadImage(imageUrlGIF, function (img) { |
| 156 | + expect(img.nodeName.toLowerCase()).to.equal('img') |
156 | 157 | expect(img.width).to.equal(60) |
157 | 158 | expect(img.height).to.equal(40) |
158 | 159 | done() |
159 | 160 | }) |
160 | 161 | ).to.be.ok |
161 | 162 | }) |
162 | 163 |
|
163 | | - it('Load image blob', function (done) { |
| 164 | + it('Load image blob as img element', function (done) { |
164 | 165 | expect( |
165 | 166 | loadImage(blobGIF, function (img) { |
| 167 | + expect(img.nodeName.toLowerCase()).to.equal('img') |
166 | 168 | expect(img.width).to.equal(60) |
167 | 169 | expect(img.height).to.equal(40) |
168 | 170 | done() |
169 | 171 | }) |
170 | 172 | ).to.be.ok |
171 | 173 | }) |
172 | 174 |
|
173 | | - it('Return image loading error to callback', function (done) { |
| 175 | + it('Handle image loading error', function (done) { |
174 | 176 | 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') |
178 | 180 | done() |
179 | 181 | }) |
180 | 182 | ).to.be.ok |
|
190 | 192 | ).to.be.ok |
191 | 193 | }) |
192 | 194 |
|
| 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 | + |
193 | 209 | describe('ObjectURL revoke', function () { |
194 | 210 | // Using XMLHttpRequest via the request helper function to test Object |
195 | 211 | // URLs to work around Edge Legacy and IE caching image URLs. |
|
431 | 447 | ) |
432 | 448 | ).to.be.ok |
433 | 449 | }) |
| 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 | + }) |
434 | 472 | }) |
435 | 473 |
|
436 | 474 | describe('contain', function () { |
|
2235 | 2273 | }) |
2236 | 2274 | }) |
2237 | 2275 |
|
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 | | - |
2300 | 2276 | describe('Metadata', function () { |
2301 | 2277 | it('Parse EXIF tags', function (done) { |
2302 | 2278 | loadImage.parseMetaData(blobJPEG, function (data) { |
|
0 commit comments