forked from taoqf/node-html-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
112.js
39 lines (38 loc) · 1.32 KB
/
112.js
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
const { parse, HTMLElement } = require('../dist');
// https://github.com/taoqf/node-html-parser/pull/112
describe('pull/112', function () {
it('this.id is set to an empty string', async function () {
const el = new HTMLElement('div', {}, '', null);
el.id.should.eql('')
should.equal(el.getAttribute('id'), undefined);
el.toString().should.eql('<div></div>');
});
it('this.id is set to the value of keyAttrs', async function () {
const el = new HTMLElement('div', { id: 'id' }, 'id="id"', null);
el.id.should.eql('id')
el.getAttribute('id').should.eql('id')
el.toString().should.eql('<div id="id"></div>');
});
it('#removeAttribute()', async function () {
const html = '<div id="id"></div>';
const root = parse(html);
const el = root.firstChild;
el.id.should.eql('id')
el.getAttribute('id').should.eql('id')
el.removeAttribute('id')
el.id.should.eql('')
should.equal(el.getAttribute('id'), undefined);
el.toString().should.eql('<div></div>');
});
it('#setAttribute()', async function () {
const html = '<div></div>';
const root = parse(html);
const el = root.firstChild;
el.id.should.eql('')
should.equal(el.getAttribute('id'), undefined);
el.setAttribute('id', 'id')
el.id.should.eql('id')
el.getAttribute('id').should.eql('id')
el.toString().should.eql('<div id="id"></div>');
});
});