describe('getting elements by class name', function () {
var
chai = require('chai'),
assert = chai.assert;
var
DomParser = require('../index.js'),
parser = new DomParser();
context('Dom', function(){
it('spaces and case', function(){
var html =
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
' +
'
\n' +
'
';
var
dom = parser.parseFromString(html),
elements = dom.getElementsByClassName('example');
assert.equal(elements.length, 5, 'html contains 5 elements with className "example"');
});
it('nested elements', function(){
var html =
'\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
' +
'
\n' +
'
' +
'
\n' +
'
';
var
dom = parser.parseFromString(html),
elements = dom.getElementsByClassName('example');
assert.equal(elements.length, 12, 'html contains 12 elements with className "example"');
});
});
context('Node', function(){
it('root: spaces and case', function(){
var html =
'\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
' +
'
\n' +
'
';
var
dom = parser.parseFromString(html),
root = dom.getElementsByClassName('root')[0],
elements = root.getElementsByClassName('example');
assert.equal(elements.length, 5, 'root element contains 5 elements with className "example"');
});
it('nested elements', function(){
var html =
'\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
\n' +
'
text\n' +
'
\n' +
'
\n' +
'
text\n' +
'
' +
'
\n' +
'
' +
'
\n' +
'
';
var
dom = parser.parseFromString(html),
root = dom.getElementsByClassName('root')[0],
elements = root.getElementsByClassName('example');
assert.equal(elements.length, 12, 'root element contains 12 elements with className "example"');
});
});
});