You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mercury-parser/src/utils/dom/convert-to-paragraphs.test.js

36 lines
973 B
JavaScript

import cheerio from 'cheerio';
import { assertClean } from 'test-helpers';
import HTML from './fixtures/html';
import convertToParagraphs from './convert-to-paragraphs';
function assertBeforeAndAfter(key, fn) {
const $ = cheerio.load(HTML[key].before);
assertClean(fn($).html(), HTML[key].after);
}
describe('convertToParagraphs($)', () => {
it('performs simple conversions', () => {
// Skipping this one in the browser. It works, but since the browser wraps
// elements in a div, the last span conversion won't work as expected.
if (!cheerio.browser) {
assertBeforeAndAfter('convertToParagraphs', convertToParagraphs);
}
});
it('does not convert a div with nested p children', () => {
const html = `
<div>
<div>
<div>
<p>This is a paragraph</p>
</div>
</div>
</div>
`;
const $ = cheerio.load(html);
assertClean(convertToParagraphs($).html(), html);
});
});