forked from ashi009/node-fast-html-parser
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from usagizmo/update/add-id-to-attr-handling
Fix id handling
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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>'); | ||
}); | ||
}); |