Skip to content

Commit 7128220

Browse files
Update npm dependencies
1 parent f820502 commit 7128220

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
"homepage": "https://github.com/biancojs/images-loader#readme",
3737
"devDependencies": {
3838
"@gianlucaguarini/eslint-config": "^2.0.0",
39-
"eslint": "^4.19.1",
40-
"jsdom": "9.5.0",
41-
"jsdom-global": "2.1.0",
39+
"eslint": "^5.8.0",
40+
"jsdom": "12.2.0",
41+
"jsdom-global": "3.0.2",
4242
"mocha": "^5.2.0",
43-
"rollup": "^0.59.4",
44-
"rollup-plugin-node-resolve": "^3.3.0"
43+
"rollup": "^0.66.6",
44+
"rollup-plugin-node-resolve": "^3.4.0"
4545
},
4646
"dependencies": {
47-
"bianco.dom-to-array": "0.0.8"
47+
"bianco.dom-to-array": "0.0.10"
4848
}
4949
}

test.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
11
require('jsdom-global')()
22

33
const assert = require('assert')
4-
const body = document.body
54
const { loadImage, loadImages } = require('./')
6-
const pathGen = pathGenerator()
75

86

7+
const LOAD_FAILURE_SRC = 'succes.jpg'
8+
const LOAD_SUCCESS_SRC = 'failed.jpg'
9+
910
/* eslint-disable */
10-
function * pathGenerator() {
11-
let i = 1
12-
while (i) {
13-
yield `data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7?${i++}`
11+
Object.defineProperty(global.Image.prototype, 'src', {
12+
set(src) {
13+
if (src === LOAD_FAILURE_SRC) {
14+
setTimeout(() => this.onerror(new Error('mocked error')), Math.random() * 1000)
15+
} else if (src === LOAD_SUCCESS_SRC) {
16+
setTimeout(() => this.onload(), Math.random() * 1000)
17+
}
1418
}
15-
}
19+
})
1620
/* eslint-enable */
1721

18-
describe('Bianco images-loader', function() {
19-
beforeEach(function() {
20-
const div = document.createElement('div')
21-
div.innerHTML = `
22-
<img src=''>
23-
`
24-
body.appendChild(div)
25-
})
2622

23+
describe('Bianco images-loader', function() {
2724
it('It can load images in the DOM', function(done) {
28-
const img = document.querySelector('img')
25+
const img = document.createElement('img')
26+
2927
loadImage(img).then(function(i) {
30-
assert.equal(typeof i.src, 'string')
28+
assert.ok(i)
3129
done()
3230
})
33-
img.src = pathGen.next().value
31+
32+
img.src = LOAD_SUCCESS_SRC
3433
})
3534

3635
// this test does not work in jsdom somehow
37-
/*it('It can throw properly the errors', function(done) {
38-
const img = document.querySelector('img')
39-
loadImage(img).catch(function(e) {
40-
assert.equal(typeof e, Error)
36+
it('It can throw properly the errors', function(done) {
37+
const img = document.createElement('img')
38+
39+
loadImage(img).then(() => {
40+
throw 'This image should be not loaded'
41+
}).catch(function(e) {
42+
assert.ok(e instanceof Error)
4143
done()
4244
})
43-
img.src = 'foo-bar'
44-
})*/
45+
46+
img.src = LOAD_FAILURE_SRC
47+
})
4548

4649
it('It can load arrays of images urls', function(done) {
47-
loadImages([pathGen.next().value, pathGen.next().value]).then(function(imgs) {
50+
loadImages([LOAD_SUCCESS_SRC, LOAD_SUCCESS_SRC]).then(function(imgs) {
4851
assert.equal(imgs.length, 2)
4952
done()
5053
})

0 commit comments

Comments
 (0)