getElementsByName.js
1.59 KB
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
describe('getting elements by name', function () {
var
chai = require('chai'),
assert = chai.assert;
var
DomParser = require('../index.js'),
parser = new DomParser();
context('Dom', function(){
it('case', function(){
var html =
'<form id="form">\n' +
' <input name="example" type="text"/><span>text</span>\n' +
' <div class="example"></div>\n' +
' <span>text</span>\n' +
' <div class=" example"></div>\n' +
' <div class=" example">' +
' <input class="input" name="example">' +
' <input class="input" name="exaMple">' +
' </div>\n' +
' </div>\n' +
'</form>';
var
dom = parser.parseFromString(html),
root = dom.getElementById('form'),
elements = root.getElementsByName('example');
assert.equal(elements.length, 2, 'html contains 2 elements with name "example"');
});
});
context('Node', function(){
it('spaces and case', function(){
var html =
'<form id="form">\n' +
' <input name="example" type="text"/><span>text</span>\n' +
' <div class="example"></div>\n' +
' <span>text</span>\n' +
' <div class=" example"></div>\n' +
' <div class=" example">' +
' <input class="input" name="example">' +
' </div>\n' +
' </div>\n' +
'</form>';
var
dom = parser.parseFromString(html),
elements = dom.getElementsByName('example');
assert.equal(elements.length, 2, 'html contains 2 elements with name "example"');
});
});
});