" and return root element', function () {
- var root = parseHTML('
');
+ const root = parseHTML('
');
- var div = new HTMLElement('div', {}, '');
- var a = div.appendChild(new HTMLElement('a', {}, ''));
- var img = a.appendChild(new HTMLElement('img', {}, ''));
- var p = div.appendChild(new HTMLElement('p', {}, ''));
+ const div = new HTMLElement('div', {}, '');
+ const a = div.appendChild(new HTMLElement('a', {}, ''));
+ const img = a.appendChild(new HTMLElement('img', {}, ''));
+ const p = div.appendChild(new HTMLElement('p', {}, ''));
root.firstChild.should.eql(div);
});
it('should parse "
" and return root element without comments', function () {
- var root = parseHTML('
');
+ const root = parseHTML('
');
- var div = new HTMLElement('div', {}, '');
- var a = div.appendChild(new HTMLElement('a', {}, ''));
+ const div = new HTMLElement('div', {}, '');
+ const a = div.appendChild(new HTMLElement('a', {}, ''));
root.firstChild.should.eql(div);
});
it('should parse "
" and return root element with comments', function () {
- var root = parseHTML('
', { comment: true });
+ const root = parseHTML('
', { comment: true });
- var div = new HTMLElement('div', {}, '');
- var a = div.appendChild(new HTMLElement('a', {}, ''));
- var comment = a.appendChild(new CommentNode(' my comment '));
+ const div = new HTMLElement('div', {}, '');
+ const a = div.appendChild(new HTMLElement('a', {}, ''));
+ const comment = a.appendChild(new CommentNode(' my comment '));
root.firstChild.should.eql(div);
});
it('should not parse HTML inside comments', function () {
- var root = parseHTML('', { comment: true });
+ const root = parseHTML('', { comment: true });
- var div = new HTMLElement('div', {}, '');
- var comment = div.appendChild(new CommentNode(''));
+ const div = new HTMLElement('div', {}, '');
+ const comment = div.appendChild(new CommentNode(''));
root.firstChild.should.eql(div);
});
it('should parse picture element', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
- var picture = new HTMLElement('picture', {}, '');
- var source = picture.appendChild(new HTMLElement('source', {}, 'srcset="/images/example-1.jpg 1200w, /images/example-2.jpg 1600w" sizes="100vw"'));
- var img = picture.appendChild(new HTMLElement('img', {}, 'src="/images/example.jpg" alt="Example"'));
+ const picture = new HTMLElement('picture', {}, '');
+ const source = picture.appendChild(new HTMLElement('source', {}, 'srcset="/images/example-1.jpg 1200w, /images/example-2.jpg 1600w" sizes="100vw"'));
+ const img = picture.appendChild(new HTMLElement('img', {}, 'src="/images/example.jpg" alt="Example"'));
root.firstChild.should.eql(picture);
@@ -150,7 +149,7 @@ describe('HTML Parser', function () {
it('should not extract text in script and style by default', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.childNodes.should.be.empty;
root.lastChild.childNodes.should.be.empty;
@@ -159,7 +158,7 @@ describe('HTML Parser', function () {
it('should extract text in script and style when ask so', function () {
- var root = parseHTML('', {
+ const root = parseHTML('', {
script: true,
style: true
});
@@ -175,7 +174,7 @@ describe('HTML Parser', function () {
it('should be able to parse "html/incomplete-script" file', function () {
- var root = parseHTML(fs.readFileSync(__dirname + '/html/incomplete-script').toString(), {
+ const root = parseHTML(fs.readFileSync(__dirname + '/html/incomplete-script').toString(), {
script: true
});
@@ -188,14 +187,14 @@ describe('HTML Parser', function () {
it('should parse "
.." very fast', function () {
- for (var i = 0; i < 100; i++)
+ for (let i = 0; i < 100; i++)
parseHTML('
');
});
it('should parse "
.." fast', function () {
- for (var i = 0; i < 100; i++)
+ for (let i = 0; i < 100; i++)
parseHTML('
', {
lowerCaseTagName: true
});
@@ -205,7 +204,7 @@ describe('HTML Parser', function () {
// Test for broken tags.
something
it('should parse "
content
other
" (fix h3, span closing tag) very fast', function () {
- var root = parseHTML(fs.readFileSync(__dirname + '/html/incomplete-script').toString());
+ const root = parseHTML(fs.readFileSync(__dirname + '/html/incomplete-script').toString());
});
});
@@ -214,43 +213,43 @@ describe('HTML Parser', function () {
// parse with validation tests
it('should return Object with valid: true. does not count
as error. instead fixes it to ', function () {
- var result = parseHTML('');
+ const result = parseHTML('');
result.valid.should.eql(true);
})
it('should return Object with valid: true. does not count as error. instead fixes it to ', function () {
- var result = parseHTML('');
+ const result = parseHTML('');
result.valid.should.eql(true);
})
it('should return Object with valid: false. does not count
as error', function () {
- var result = parseHTML('
');
+ const result = parseHTML('
');
result.valid.should.eql(false);
})
it('hillcrestpartyrentals.html should return Object with valid: false. not closing
tag on line 476', function () {
- var result = parseHTML(fs.readFileSync(__dirname + '/html/hillcrestpartyrentals.html').toString(), {
+ const result = parseHTML(fs.readFileSync(__dirname + '/html/hillcrestpartyrentals.html').toString(), {
noFix: true
});
result.valid.should.eql(false);
})
it('google.html should return Object with valid: true', function () {
- var result = parseHTML(fs.readFileSync(__dirname + '/html/google.html').toString(), {
+ const result = parseHTML(fs.readFileSync(__dirname + '/html/google.html').toString(), {
noFix: true
});
result.valid.should.eql(true);
})
it('gmail.html should return Object with valid: true', function () {
- var result = parseHTML(fs.readFileSync(__dirname + '/html/gmail.html').toString(), {
+ const result = parseHTML(fs.readFileSync(__dirname + '/html/gmail.html').toString(), {
noFix: true
});
result.valid.should.eql(true);
})
it('ffmpeg.html should return Object with valid: false (extra opening
', function () {
- var result = parseHTML(fs.readFileSync(__dirname + '/html/ffmpeg.html').toString(), {
+ const result = parseHTML(fs.readFileSync(__dirname + '/html/ffmpeg.html').toString(), {
noFix: true
});
result.valid.should.eql(false);
@@ -259,24 +258,24 @@ describe('HTML Parser', function () {
// fix issue speed test
it('should fix "
');
})
it('gmail.html should return Object with valid: true', function () {
- var result = parseHTML(fs.readFileSync(__dirname + '/html/gmail.html').toString().replace(/<\//gi, '<'));
+ const result = parseHTML(fs.readFileSync(__dirname + '/html/gmail.html').toString().replace(/<\//gi, '<'));
result.valid.should.eql(false);
})
it('gmail.html should return Object with valid: true', function () {
- var result = parseHTML(fs.readFileSync(__dirname + '/html/nice.html').toString().replace(/<\//gi, '<'));
+ const result = parseHTML(fs.readFileSync(__dirname + '/html/nice.html').toString().replace(/<\//gi, '<'));
result.valid.should.eql(false);
})
@@ -284,7 +283,7 @@ describe('HTML Parser', function () {
describe('TextNode', function () {
describe('#isWhitespace', function () {
- var node = new TextNode('');
+ let node = new TextNode('');
node.isWhitespace.should.be.ok;
node = new TextNode(' \t');
node.isWhitespace.should.be.ok;
@@ -297,9 +296,9 @@ describe('HTML Parser', function () {
describe('#removeWhitespace()', function () {
it('should remove whitespaces while preserving nodes with content', function () {
- var root = parseHTML('
\r \n \t
123
');
+ const root = parseHTML('
\r \n \t
123
');
- var p = new HTMLElement('p', {}, '');
+ const p = new HTMLElement('p', {}, '');
p.appendChild(new HTMLElement('h5', {}, ''))
.appendChild(new TextNode('123'));
@@ -309,7 +308,7 @@ describe('HTML Parser', function () {
describe('#rawAttributes', function () {
it('should return escaped attributes of the element', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.rawAttributes.should.eql({
'a': '12',
'data-id': '!$$&',
@@ -320,7 +319,7 @@ describe('HTML Parser', function () {
describe('#attributes', function () {
it('should return attributes of the element', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.attributes.should.eql({
'a': '12',
'data-id': '!$$&',
@@ -333,24 +332,24 @@ describe('HTML Parser', function () {
describe('#getAttribute', function () {
it('should return value of the attribute', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.getAttribute('a').should.eql('a1b');
});
it('should return null when there is no such attribute', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
should.equal(root.firstChild.getAttribute('b'), null);
});
it('should return empty string as broser behavior', function () {
- var root = parseHTML('');
- var input = root.firstChild;
+ const root = parseHTML('');
+ const input = root.firstChild;
input.getAttribute('required').should.eql('');
});
it('should return null as broser behavior', function () {
- var root = parseHTML('');
- var input = root.firstChild;
+ const root = parseHTML('');
+ const input = root.firstChild;
input.setAttribute('readonly', null);
input.getAttribute('readonly').should.eql('null');
});
@@ -358,8 +357,8 @@ describe('HTML Parser', function () {
describe('#setAttribute', function () {
it('should edit the attributes of the element', function () {
- var root = parseHTML('');
- var attr = root.firstChild.attributes;
+ const root = parseHTML('');
+ const attr = root.firstChild.attributes;
root.firstChild.setAttribute('a', 13);
attr.should.eql({
'a': '13',
@@ -368,7 +367,7 @@ describe('HTML Parser', function () {
root.firstChild.toString().should.eql('');
});
it('should add an attribute to the element', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.setAttribute('b', 13);
root.firstChild.attributes.should.eql({
'a': '12',
@@ -377,8 +376,8 @@ describe('HTML Parser', function () {
root.firstChild.toString().should.eql('');
});
it('should convert value to string', function () {
- var root = parseHTML('');
- var p = root.firstChild;
+ const root = parseHTML('');
+ const p = root.firstChild;
p.setAttribute('b', null);
p.setAttribute('c', undefined);
p.getAttribute('b').should.eql('null');
@@ -386,13 +385,13 @@ describe('HTML Parser', function () {
p.toString().should.eql('');
});
it('should throw type Error', function () {
- var root = parseHTML('');
- var p = root.firstChild;
+ const root = parseHTML('');
+ const p = root.firstChild;
should.throws(function () { p.setAttribute('b') });
should.throws(function () { p.setAttribute() });
});
it('should keep quotes arount value', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.setAttribute('b', 13);
root.firstChild.setAttribute('c', '2');
root.firstChild.attributes.should.eql({
@@ -406,7 +405,7 @@ describe('HTML Parser', function () {
describe('#setAttributes', function () {
it('should return attributes of the element', function () {
- var root = parseHTML('');
+ const root = parseHTML('');
root.firstChild.setAttributes({
c: 12,
d: '&&<>foo'
@@ -421,16 +420,16 @@ describe('HTML Parser', function () {
});
describe('#removeAttribute', function () {
- var root = parseHTML('');
- var input = root.firstChild;
+ const root = parseHTML('');
+ const input = root.firstChild;
input.removeAttribute('required');
input.toString().should.eql('');
});
describe('#hasAttribute', function () {
it('should return true or false when has or has not some attribute', function () {
- var root = parseHTML('');
- var input = root.firstChild;
+ const root = parseHTML('');
+ const input = root.firstChild;
input.hasAttribute('required').should.eql(true);
input.removeAttribute('required');
input.hasAttribute('required').should.eql(false);
@@ -439,7 +438,7 @@ describe('HTML Parser', function () {
describe('#querySelector()', function () {
it('should return correct elements in DOM tree', function () {
- var root = parseHTML('
');
+ const root = parseHTML('
');
root.querySelector('#id').should.eql(root.firstChild);
root.querySelector('span.a').should.eql(root.firstChild.firstChild.firstChild);
root.querySelector('span.b').should.eql(root.firstChild.firstChild.firstChild);
@@ -453,7 +452,7 @@ describe('HTML Parser', function () {
describe('#querySelectorAll()', function () {
it('should return correct elements in DOM tree', function () {
- var root = parseHTML('
');
+ const root = parseHTML('
');
root.querySelectorAll('#id').should.eql([root.firstChild]);
root.querySelectorAll('span.a').should.eql([root.firstChild.firstChild.firstChild]);
root.querySelectorAll('span.b').should.eql([root.firstChild.firstChild.firstChild]);
@@ -463,19 +462,19 @@ describe('HTML Parser', function () {
root.querySelectorAll('#id, #id .b').should.eql([root.firstChild, root.firstChild.firstChild.firstChild]);
});
it('should return just one element', function () {
- var root = parseHTML('