forked from ashi009/node-fast-html-parser
-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Labels
Description
Here is a failing test case:
it("reproduces error", () => {
const html = `
<html>
<body>
<div>
<p>b</p>
<p>c</p>
<div>
</body>
</html>`
const root = parse(html)
root.querySelector('div').childNodes.unshift(parse('<p>a</p>'));
expect(root.querySelector("p:nth-of-type(2)").rawText).toEqual("b");
/*
Expected: "b"
Received: "c"
28 | root.querySelector('div').childNodes.unshift(parse('<p>a</p>'));
29 |
> 30 | expect(root.querySelector("p:nth-of-type(2)").rawText).toEqual("b");
| ^
31 | });
*/
});My workaround was to use childNodes[0].set_content(newContent + oldContent).
The reason I wrote this code in the first place is because I couldn't figure out from the documentation how to prepend content. I looked at the tests and noticed some of them were using childNodes[0] and figured, if you can index that array, you should be able to call other functions on it and have it work.