parse.spec.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { parse } from '../src'
  2. import { mockWarn } from '@vue/runtime-test'
  3. describe('compiler:sfc', () => {
  4. mockWarn()
  5. describe('source map', () => {
  6. test('style block', () => {
  7. const style = parse(`<style>\n.color {\n color: red;\n }\n</style>\n`)
  8. .styles[0]
  9. expect(style.map).not.toBeUndefined()
  10. })
  11. test('script block', () => {
  12. const script = parse(`<script>\nconsole.log(1)\n }\n</script>\n`).script
  13. expect(script!.map).not.toBeUndefined()
  14. })
  15. })
  16. test('should ignore nodes with no content', () => {
  17. expect(parse(`<template/>`).template).toBe(null)
  18. expect(parse(`<script/>`).script).toBe(null)
  19. expect(parse(`<style/>`).styles.length).toBe(0)
  20. expect(parse(`<custom/>`).customBlocks.length).toBe(0)
  21. })
  22. describe('error', () => {
  23. test('should only allow single template element', () => {
  24. parse(`<template><div/></template><template><div/></template>`)
  25. expect(
  26. `Single file component can contain only one template element`
  27. ).toHaveBeenWarned()
  28. })
  29. test('should only allow single script element', () => {
  30. parse(`<script>console.log(1)</script><script>console.log(1)</script>`)
  31. expect(
  32. `Single file component can contain only one script element`
  33. ).toHaveBeenWarned()
  34. })
  35. })
  36. })