import assert from 'assert'; import cheerio from 'cheerio'; import convertNodeTo from './convert-node-to'; describe('convertNodeTo(node, $)', () => { it('takes a node and converts it to a diff tag', () => { const html = '
Should become a p
'; const $ = cheerio.load(html); const node = $('div').first(); const result = convertNodeTo(node, $).html(); const after = '

Should become a p

'; assert.equal(result, after); }); it('retains attributes on conversion', () => { const html = 'Should keep its attrs'; const $ = cheerio.load(html); const node = $('span').first(); const result = convertNodeTo(node, $, 'div').html(); const after = '
Should keep its attrs
'; assert.equal(result, after); }); it('does nothing if node.get returns null', () => { const html = 'Should keep its attrs'; const $ = cheerio.load(html); const node = { get: () => null, }; const result = convertNodeTo(node, $, 'div').html(); assert.equal(result, html); }); // In the browser, the contents of noscript tags aren't rendered, therefore // transforms on the noscript tag (commonly used for lazy-loading) don't work // as expected. This test case handles that it('handles noscript tags in the browser', () => { const html = ''; const resultHtml = '
'; const $ = cheerio.load(html); const node = $('noscript'); const result = convertNodeTo(node, $, 'figure', 'noscript').html(); assert.equal(result, resultHtml); }); });