-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (39 loc) · 1.44 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
var expect = require('chai').expect
, client = require('utilise.client')
, shim = !client && polyfill()
, key = require('utilise.key')
, all = require('./')
, is = require('utilise.is')
, node
describe('all', function() {
before(function(){
/* istanbul ignore next */
if (!client) { return node = document.body.firstElementChild }
else {
node = document.body.appendChild(document.createElement('div'))
node.className = 'class-all'
node.appendChild(document.createElement('li'))
}
})
it('should call querySelectorAll with selector', function(){
expect(all('.class-all li', node)).to.be.eql([node.firstElementChild])
})
it('should call querySelectorAll with selector and global document', function(){
expect(all('.class-all')).to.be.eql([node])
})
it('should pierce boundaries if supports shadow dom', function(){
var realShadow = document.head.createShadowRoot
, realQuery = document.querySelectorAll
, result
document.querySelectorAll = function(selector){ result = selector; return [] }
document.head.createShadowRoot = true
all('.class-all li')
expect(result).to.be.eql('html /deep/ .class-all li')
document.head.createShadowRoot = realShadow
document.querySelectorAll = realQuery
})
})
function polyfill(){
window = require("jsdom").jsdom('<div class="class-all"><li></li></div>').defaultView
global.document = window.document
}