templateUtils.spec.ts 1.7 KB

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