Skip to content

Commit 844b56a

Browse files
test($shared-utils): complete existed tests of shared-utils (#2366)
* test($shared-utils): cover more cases for unescapeHtml * test($shared-utils): cover more cases for fileToPath * test($shared-utils): cover more cases for parseHeaders
1 parent 394c4f6 commit 844b56a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import fileToPath from '../src/fileToPath'
22

3-
test('fileToPath', () => {
3+
test('should return dirname of the path when it is index file ', () => {
44
const asserts: Record<string, string> = {
55
'README.md': '/',
6+
'README.vue': '/',
67
'foo/README.md': '/foo/',
7-
'foo.md': '/foo.html',
8-
'foo/bar.md': '/foo/bar.html'
8+
'foo/README.vue': '/foo/'
99
}
1010
Object.keys(asserts).forEach(file => {
1111
expect(fileToPath(file)).toBe(asserts[file])
1212
})
1313
})
1414

15+
test('should return a path with .html suffix', () => {
16+
const asserts: Record<string, string> = {
17+
'foo.md': '/foo.html',
18+
'foo.vue': '/foo.html',
19+
'foo/bar.md': '/foo/bar.html',
20+
'foo/bar.vue': '/foo/bar.html'
21+
}
22+
Object.keys(asserts).forEach(file => {
23+
expect(fileToPath(file)).toBe(asserts[file])
24+
})
25+
})

packages/@vuepress/shared-utils/__tests__/parseHeaders.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import parseHeaders from '../src/parseHeaders'
22

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

99
test('should remove markdown tokens correctly', () => {
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unescapeHtml from '../src/unescapeHtml'
22

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

0 commit comments

Comments
 (0)