|
1 | | -const { parse } = require('../dist'); |
| 1 | +const { parse, NodeType } = require('../dist'); |
2 | 2 |
|
| 3 | +// Also see comments on https://github.com/taoqf/node-html-parser/pull/148 for additional issues corrected |
3 | 4 | describe('issue 144', function () { |
4 | 5 | it('Nested A tags parsed improperly', function () { |
5 | | - const html = `<a href="#">link <a href="#">nested link</a> end</a>`; |
| 6 | + const html = `<A href="#"><b>link <a href="#">nested link</a> end</b></A>`; |
| 7 | + |
6 | 8 | const root = parse(html); |
7 | | - root.innerHTML.should.eql(`<a href="#">link </a><a href="#">nested link</a> end`); |
| 9 | + |
| 10 | + root.innerHTML.should.eql(`<A href="#"><b>link </b></A><a href="#">nested link</a> end`); |
8 | 11 | root.childNodes.length.should.eql(3); |
| 12 | + |
9 | 13 | const a1 = root.childNodes[0]; |
10 | 14 | a1.tagName.should.eql('A'); |
11 | | - a1.nodeType.should.eql(1); |
| 15 | + a1.nodeType.should.eql(NodeType.ELEMENT_NODE); |
| 16 | + a1.childNodes.length.should.eql(1); |
| 17 | + |
| 18 | + const b = a1.childNodes[0]; |
| 19 | + b.tagName.should.eql('B'); |
| 20 | + b.childNodes.length.should.eql(1); |
| 21 | + b.text.should.eql('link '); |
| 22 | + |
12 | 23 | const a2 = root.childNodes[1]; |
13 | | - a2.nodeType.should.eql(1); |
14 | | - const t1 = root.childNodes[2]; |
15 | | - t1.nodeType.should.eql(3); |
16 | | - t1.textContent.should.eql(' end'); |
| 24 | + a2.tagName.should.eql('A'); |
| 25 | + a2.nodeType.should.eql(NodeType.ELEMENT_NODE); |
| 26 | + a2.childNodes.length.should.eql(1); |
| 27 | + a2.childNodes[0].nodeType.should.eql(NodeType.TEXT_NODE); |
| 28 | + a2.text.should.eql('nested link'); |
| 29 | + |
| 30 | + const endText = root.childNodes[2]; |
| 31 | + endText.nodeType.should.eql(NodeType.TEXT_NODE); |
| 32 | + endText.textContent.should.eql(' end'); |
17 | 33 | }); |
18 | 34 | }); |
0 commit comments