chore: refactored tests

pull/1/head
Adam Pash 8 years ago
parent d4a19e6a27
commit f3b1fefba6

@ -23,3 +23,6 @@ x `_score_paragraph`
- `_find_top_candidate`
- `extract_clean_node`
- `_clean_conditionally`
Add helper methods to clean up tests

@ -7,6 +7,11 @@ import {
brsToPs
} from './index'
function assertBeforeAndAfter(key, fn) {
const $ = cheerio.load(HTML[key].before)
assert.equal(clean(fn($).html()), clean(HTML[key].after))
}
describe('Generic Extractor Utils', () => {
describe('brsToPs(node)', () => {
@ -16,29 +21,19 @@ describe('Generic Extractor Utils', () => {
})
it("does nothing when a single BR is present", () => {
const $ = cheerio.load(HTML.singleBr.before)
assert.equal(brsToPs($).html(), HTML.singleBr.after)
assertBeforeAndAfter('singleBr', brsToPs)
})
it("converts double BR tags to an empty P tag", () => {
const $ = cheerio.load(HTML.doubleBrs.before)
const result = brsToPs($).html()
assert.equal(clean(result), clean(HTML.doubleBrs.after))
assertBeforeAndAfter('doubleBrs', brsToPs)
})
it("converts several BR tags to an empty P tag", () => {
const $ = cheerio.load(HTML.severalBrs.before)
const result = brsToPs($).html()
assert.equal(clean(result), clean(HTML.severalBrs.after))
assertBeforeAndAfter('severalBrs', brsToPs)
})
it("converts BR tags in a P tag into a P containing inline children", () => {
const $ = cheerio.load(HTML.brsInP.before)
// Note: result is malformed HTML
// Will be handled elsewhere
const result = brsToPs($).html()
assert.equal(clean(result), clean(HTML.brsInP.after))
assertBeforeAndAfter('brsInP', brsToPs)
})
})

Loading…
Cancel
Save