/
ender-test.coffee
29 lines (24 loc) · 1.48 KB
/
ender-test.coffee
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
assert = require('assert')
vows = require('vows')
# Force using Sel as the selector library
$._select = sel.sel
vows.add 'Ender Tests',
'basic tests':
'`.parent .child`':
topic: -> $('.parent .child')
'should return 4 elements': (result) -> assert.equal result.length, 4
'should return the h1 first': (result) -> assert.equal result[0].tagName.toLowerCase(), 'h1'
'should return the h2 second': (result) -> assert.equal result[1].tagName.toLowerCase(), 'h2'
'should return the h3 third': (result) -> assert.equal result[2].tagName.toLowerCase(), 'h3'
'should return the h4 fourth': (result) -> assert.equal result[3].tagName.toLowerCase(), 'h4'
'and using the .matching method':
topic: (els) -> els.matching('h1')
'should return 1 element': (result) -> assert.equal result.length, 1
'should return the h1 element': (result) -> assert.equal result[0].tagName.toLowerCase(), 'h1'
'and using the result as roots':
topic: (roots) -> $('.grandchild')
'we should find the grandchild': (result) -> assert.equal result[0].className, 'grandchild'
'and nothing else': (result) -> assert.equal result.length, 1
'and passing the result as a new selector':
topic: (s) -> $(s, document)
'should return the same elements': (result) -> assert.equal result.length, 4