-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
135 lines (121 loc) · 4.15 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require('jsdom-global')()
const assert = require('assert')
const attr = require('./')
describe('Bianco attr', function() {
it('export default contains all the module methods', function() {
assert.deepEqual(Object.keys(attr.default), [
'get',
'set',
'remove',
'has'
])
})
it('it can set an attribute', function() {
const div = document.createElement('div')
attr.set(div, 'hidden', 'val')
assert.equal(div.getAttribute('hidden'), 'val')
})
it('it can set an attribute on multiple nodes', function() {
const div = document.createElement('div')
const span = document.createElement('span')
attr.set([div, span], 'hidden', 'val')
assert.equal(div.getAttribute('hidden'), 'val')
assert.equal(span.getAttribute('hidden'), 'val')
})
it('it can set multiple attributes', function() {
const div = document.createElement('div')
attr.set(div, {
hidden: 'val',
canchange: 'val'
})
assert.equal(div.getAttribute('hidden'), 'val')
assert.equal(div.getAttribute('canchange'), 'val')
})
it('it can set multiple attributes on multiple nodes', function() {
const div = document.createElement('div')
const span = document.createElement('span')
attr.set([div, span], {
hidden: 'val',
canchange: 'val'
})
assert.equal(div.getAttribute('hidden'), 'val')
assert.equal(div.getAttribute('canchange'), 'val')
assert.equal(span.getAttribute('hidden'), 'val')
assert.equal(span.getAttribute('canchange'), 'val')
})
it('it can get attributes', function() {
const div = document.createElement('div')
attr.set(div, {
hidden: 'val',
canchange: 'val'
})
assert.equal(attr.get(div, 'hidden'), 'val')
assert.equal(attr.get(div, 'canchange'), 'val')
})
it('it can get attributes on multiple nodes', function() {
const div = document.createElement('div')
const span = document.createElement('span')
attr.set([div, span], {
hidden: 'val',
canchange: 'val'
})
assert.deepEqual(attr.get([div, span], 'hidden'), ['val', 'val'])
assert.deepEqual(attr.get([div, span], 'canchange'), ['val', 'val'])
})
it('it can get multiple attributes', function() {
const div = document.createElement('div')
attr.set(div, {
hidden: 'val',
canchange: 'val'
})
assert.deepEqual(attr.get(div, ['hidden', 'canchange']), ['val', 'val'])
})
it('it can get multiple attributes on multiple nodes', function() {
const div = document.createElement('div')
const span = document.createElement('span')
attr.set([div, span], {
hidden: 'val',
canchange: 'val'
})
assert.deepEqual(attr.get([div, span], ['hidden', 'canchange']), [['val', 'val'], ['val', 'val']])
})
it('it can remove attributes', function() {
const div = document.createElement('div')
attr.set(div, {
hidden: 'val',
canchange: 'val'
})
attr.remove(div, 'hidden')
attr.remove(div, 'canchange')
assert.deepEqual(attr.get(div, ['hidden', 'canchange']), [null, null])
})
it('it can remove attributes from multiple nodes', function() {
const div = document.createElement('div')
const span = document.createElement('span')
attr.set([div, span], {
hidden: 'val',
canchange: 'val'
})
attr.remove([div, span], ['hidden', 'canchange'])
assert.deepEqual(attr.get([div, span], ['hidden', 'canchange']), [[null, null], [null, null]])
})
it('it can detect attributes', function() {
const div = document.createElement('div')
attr.set(div, {
hidden: 'val',
canchange: 'val'
})
assert.equal(attr.has(div, 'hidden'), true)
assert.deepEqual(attr.has(div, ['hidden', 'canchange', 'foo']), [true, true, false])
})
it('it can detect attributes on multiple nodes', function() {
const div = document.createElement('div')
const span = document.createElement('span')
attr.set([div, span], {
hidden: 'val',
canchange: 'val'
})
assert.deepEqual(attr.has([div, span], 'hidden'), [true, true])
assert.deepEqual(attr.has([div, span], ['hidden', 'canchange', 'foo']), [[true, true, false], [true, true, false]])
})
})