fix: handling case where node.get(0) returns null

pull/3/head
Adam Pash 8 years ago
parent 2bf274114f
commit 6263e505d5

@ -1,6 +1,10 @@
import 'babel-polyfill';
export default function convertNodeTo($node, $, tag = 'p') {
const node = $node.get(0);
if (!node) {
return $;
}
const { attribs } = $node.get(0);
const attribString = Reflect.ownKeys(attribs)
.map(key => `${key}=${attribs[key]}`)

@ -25,5 +25,17 @@ describe('convertNodeTo(node, $)', () => {
assert.equal(result, after);
});
it('does nothing if node.get returns null', () => {
const html = '<span class="foo" score="100">Should keep its attrs</span>';
const $ = cheerio.load(html);
const node = {
get: () => null,
};
const result = convertNodeTo(node, $, 'div').html();
assert.equal(result, html);
});
});

Loading…
Cancel
Save