Skip to content

Commit

Permalink
test($shared-utils): complete existed tests of shared-utils (#2366)
Browse files Browse the repository at this point in the history
* test($shared-utils): cover more cases for unescapeHtml

* test($shared-utils): cover more cases for fileToPath

* test($shared-utils): cover more cases for parseHeaders
  • Loading branch information
billyyyyy3320 authored Sep 13, 2020
1 parent 394c4f6 commit 844b56a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
17 changes: 14 additions & 3 deletions packages/@vuepress/shared-utils/__tests__/fileToPath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import fileToPath from '../src/fileToPath'

test('fileToPath', () => {
test('should return dirname of the path when it is index file ', () => {
const asserts: Record<string, string> = {
'README.md': '/',
'README.vue': '/',
'foo/README.md': '/foo/',
'foo.md': '/foo.html',
'foo/bar.md': '/foo/bar.html'
'foo/README.vue': '/foo/'
}
Object.keys(asserts).forEach(file => {
expect(fileToPath(file)).toBe(asserts[file])
})
})

test('should return a path with .html suffix', () => {
const asserts: Record<string, string> = {
'foo.md': '/foo.html',
'foo.vue': '/foo.html',
'foo/bar.md': '/foo/bar.html',
'foo/bar.vue': '/foo/bar.html'
}
Object.keys(asserts).forEach(file => {
expect(fileToPath(file)).toBe(asserts[file])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import parseHeaders from '../src/parseHeaders'

describe('parseHeaders', () => {
test('should unescape html', () => {
const input = '&lt;div&gt;'
expect(parseHeaders(input)).toBe('<div>')
const input = `&lt;div :id=&quot;&#39;app&#39;&quot;&gt;`
expect(parseHeaders(input)).toBe(`<div :id="'app'">`)
})

test('should remove markdown tokens correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unescapeHtml from '../src/unescapeHtml'

test('should unescape html', () => {
const input = '&lt;div&gt;'
expect(unescapeHtml(input)).toBe('<div>')
const input = `&lt;div :id=&quot;&#39;app&#39;&quot;&gt;`
expect(unescapeHtml(input)).toBe(`<div :id="'app'">`)
})

0 comments on commit 844b56a

Please sign in to comment.