getElementsByAttribute.js
1.51 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
describe('getting elements by attribute', function () {
var
chai = require('chai'),
assert = chai.assert;
var
DomParser = require('../index.js'),
parser = new DomParser();
context('Dom', function(){
it('similar attribute names', function(){
var html =
'<form id="form">\n' +
' <input name="example" type="text"/><span>text</span>\n' +
' <span bad-name="example">text</span>\n' +
' <span name-similar="example">text</span>\n' +
' <div class="example"></div>\n' +
' <span>example</span>\n' +
'</form>';
var
dom = parser.parseFromString(html),
elements = dom.getElementsByName('example');
assert.equal(elements.length, 1, 'html contains 1 elements with name "example"');
});
});
context('Dom', 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>example</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),
elements = dom.getElementsByName('example');
assert.equal(elements.length, 2, 'html contains 2 elements with name "example"');
});
});
});