提交 4f0b3162 编写于 作者: U ULIVZ

test: add test for parseHeaders

上级 ec330f09
......@@ -18,7 +18,7 @@ const removeMarkdownToken = str => String(str)
.replace(/(\\)(\*|_|`)/g, '$2') // remove escape char '\'
exports.removeTailHtml = (str) => {
return String(str).replace(/<.*>\s*$/g, '')
return String(str).replace(/\s*?<.*>\s*$/g, '')
}
// only remove some md tokens.
......
import {
parseHeaders,
removeTailHtml
} from '@/util/parseHeaders'
describe('parseHeaders', () => {
test('should unescape html', () => {
const input = '&lt;div&gt;'
expect(parseHeaders(input)).toBe('<div>')
})
test('should remove markdown tokens correctly', () => {
const asserts = {
// #238
'[vue](vuejs.org)': 'vue',
'`vue`': 'vue',
'*vue*': 'vue',
'**vue**': 'vue',
'***vue***': 'vue',
'_vue_': 'vue',
'\\_vue\\_': '_vue_',
'\\*vue\\*': '*vue*',
// #564 For multiple markdown tokens
'`a` and `b`': 'a and b',
'***bold and italic***': 'bold and italic',
'**bold** and *italic*': 'bold and italic'
}
Object.keys(asserts).forEach(input => {
expect(parseHeaders(input)).toBe(asserts[input])
})
})
test('should remove tail html correctly', () => {
expect(removeTailHtml('# H1 <div></div>>')).toBe('# H1')
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册