forked from hilongjw/vue-lazyload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.js
61 lines (49 loc) · 1.63 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const it = require('mocha').it
const chai = require('chai')
const expect = require('chai').expect
const lazyload = require('../lib')
const Vue = require('vue')
describe('VueLazyload.js Test Suite', function () {
it('install', function () {
Vue.use(lazyload)
const vm = new Vue()
expect(vm.$Lazyload, 'has $Lazyload')
})
it('_valueFormatter', function () {
const genLazyCore = require('../lib/lazy').default
const LazyCore = genLazyCore(Vue)
const lazyload = new LazyCore({
error: 'error',
loading: 'loading',
})
expect(lazyload._valueFormatter('src').src).to.equal('src')
expect(lazyload._valueFormatter('src').error).to.equal('error')
expect(lazyload._valueFormatter('src').loading).to.equal('loading')
expect(lazyload._valueFormatter({
src: 'src',
error: 'error',
loading: 'loading',
}).src).to.equal('src')
expect(lazyload._valueFormatter({
src: 'src',
error: 'error',
loading: 'loading',
}).error).to.equal('error')
expect(lazyload._valueFormatter({
src: 'src',
error: 'error',
loading: 'loading',
}).loading).to.equal('loading')
})
// it('add and remove TargetListener', function () {
// Vue.use(lazyload)
// const vm = new Vue()
// const list = Array.from({ length: 10 }).map((v, i) => {
// return { i, addEventListener () {}, removeEventListener () {} }
// })
// list.map(el => vm.$Lazyload._addListenerTarget(el))
// list.map(el => vm.$Lazyload._removeListenerTarget(el))
// expect(vm.$Lazyload.TargetQueue.length).to.equal(0)
// })
})