/
templateUtils.spec.ts
53 lines (45 loc) 路 1.54 KB
/
templateUtils.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import {
isRelativeUrl,
isExternalUrl,
isDataUrl
} from '../../compiler-sfc/src/templateUtils'
describe('compiler sfc:templateUtils isRelativeUrl', () => {
test('should return true when The first character of the string path is .', () => {
const url = './**.vue'
const result = isRelativeUrl(url)
expect(result).toBe(true)
})
test('should return true when The first character of the string path is ~', () => {
const url = '~/xx.vue'
const result = isRelativeUrl(url)
expect(result).toBe(true)
})
test('should return true when The first character of the string path is @', () => {
const url = '@/xx.vue'
const result = isRelativeUrl(url)
expect(result).toBe(true)
})
})
describe('compiler sfc:templateUtils isExternalUrl', () => {
test('should return true when String starts with http://', () => {
const url = 'http://vuejs.org/'
const result = isExternalUrl(url)
expect(result).toBe(true)
})
test('should return true when String starts with https://', () => {
const url = 'https://vuejs.org/'
const result = isExternalUrl(url)
expect(result).toBe(true)
})
})
describe('compiler sfc:templateUtils isDataUrl', () => {
test('should return true w/ hasn`t media type and encode', () => {
expect(isDataUrl('data:,i')).toBe(true)
})
test('should return true w/ media type + encode', () => {
expect(isDataUrl('data:image/png;base64,i')).toBe(true)
})
test('should return true w/ media type + hasn`t encode', () => {
expect(isDataUrl('data:image/png,i')).toBe(true)
})
})