-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
79 lines (65 loc) · 1.61 KB
/
test.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var expect = require('chai').expect
var assign = require('object-assign')
var template = '<button type="button" data-sharer="twitter">button</button>'
function makeV1() {
var wrapper = document.createElement('div')
wrapper.innerHTML = template
return assign({ el: wrapper.querySelector('button') }, require('./index'))
}
function makeV2() {
var wrapper = document.createElement('div')
wrapper.innerHTML = template
return {
component: assign(window, require('./index')),
el: wrapper.querySelector('button'),
}
}
describe('index', function () {
var sandbox
var spy
beforeEach(function () {
sandbox = sinon.createSandbox()
spy = sandbox.spy(window, 'open')
})
afterEach(function () {
sandbox.restore()
})
it('bind (v1)', function (cb) {
var sharer = makeV1()
sharer.bind()
sharer.el.click()
setTimeout(function () {
expect(spy.calledOnce).to.be.ok
cb()
}, 100)
})
it('bind (v2)', function (cb) {
var sharer = makeV2()
sharer.component.bind(sharer.el)
sharer.el.click()
setTimeout(function () {
expect(spy.calledOnce).to.be.ok
cb()
}, 100)
})
it('unbind (v1)', function (cb) {
var sharer = makeV1()
sharer.bind()
sharer.unbind()
sharer.el.click()
setTimeout(function () {
expect(spy.called).to.not.be.ok
cb()
}, 100)
})
it('unbind (v2)', function (cb) {
var sharer = makeV2()
sharer.component.bind(sharer.el)
sharer.component.unbind(sharer.el)
sharer.el.click()
setTimeout(function () {
expect(spy.called).to.not.be.ok
cb()
}, 100)
})
})