ssrCompile.spec.ts 950 B

123456789101112131415161718192021222324252627282930313233
  1. import { compile } from '../src'
  2. function getElementString(src: string): string {
  3. return compile(src).code.match(/_push\((.*)\)/)![1]
  4. }
  5. describe('ssr compile integration test', () => {
  6. test('basic elements', () => {
  7. expect(getElementString(`<div></div>`)).toMatchInlineSnapshot(
  8. `"\`<div></div>\`"`
  9. )
  10. })
  11. test('static attrs', () => {
  12. expect(
  13. getElementString(`<div id="foo" class="bar"></div>`)
  14. ).toMatchInlineSnapshot(`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`)
  15. })
  16. test('nested elements', () => {
  17. expect(
  18. getElementString(`<div><span></span><span></span></div>`)
  19. ).toMatchInlineSnapshot(`"\`<div><span></span><span></span></div>\`"`)
  20. })
  21. test('nested elements with static text', () => {
  22. expect(
  23. getElementString(`<div><span>hello</span>&gt;<span>bye</span></div>`)
  24. ).toMatchInlineSnapshot(
  25. `"\`<div><span>hello</span>&gt;<span>bye</span></div>\`"`
  26. )
  27. })
  28. })