cheerio
cheerio copied to clipboard
replaceWith doesn't work with nested elements
Not quite sure what's going on here, but I would expect it to replace the entire structure with my new string...but it injects "<item>" in an unexpected spot higher up the document tree.
Failing test
it('nested elements', () => {
const $$ = load('<menu><item>1</item></menu>', null, false)
const newStr = '<table><tbody><tr><td><table><tbody><tr><item>1</item></tr></tbody></table></td></tr></tbody></table>';
const $replaced = $$('menu').replaceWith(newStr);
expect($replaced[0].parentNode).toBe(null);
expect($$.html()).toBe(newStr);
});
Expected :<table><tbody><tr><td><table><tbody><tr><item>1</item></tr></tbody></table></td></tr></tbody></table>
Actual :<table><tbody><tr><td><item>1</item><table><tbody><tr></tr></tbody></table></td></tr></tbody></table>