ssrAttrFallthrough.spec.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { createApp } from 'vue'
  2. import { renderToString } from '../src/renderToString'
  3. describe('ssr: attr fallthrough', () => {
  4. test('basic', async () => {
  5. const Child = {
  6. template: `<div class="foo" />`
  7. }
  8. const Parent = {
  9. components: { Child },
  10. template: `<child class="bar"/>`
  11. }
  12. const app = createApp(Parent)
  13. expect(await renderToString(app)).toBe(`<div class="foo bar"></div>`)
  14. })
  15. test('with v-if', async () => {
  16. const Child = {
  17. props: ['ok'],
  18. template: `<div v-if="ok" class="foo" /><span v-else />`
  19. }
  20. const Parent = {
  21. props: ['ok'],
  22. components: { Child },
  23. template: `<child :ok="ok" class="bar"/>`
  24. }
  25. expect(await renderToString(createApp(Parent, { ok: true }))).toBe(
  26. `<div class="foo bar"></div>`
  27. )
  28. expect(await renderToString(createApp(Parent, { ok: false }))).toBe(
  29. `<span class="bar"></span>`
  30. )
  31. })
  32. test('with v-model', async () => {
  33. const Child = {
  34. props: ['text'],
  35. template: `<input v-model="text">`
  36. }
  37. const Parent = {
  38. components: { Child },
  39. template: `<child text="hello" class="bar"/>`
  40. }
  41. expect(await renderToString(createApp(Parent))).toBe(
  42. `<input class="bar" value="hello">`
  43. )
  44. })
  45. test('with v-bind', async () => {
  46. const Child = {
  47. props: ['obj'],
  48. template: `<div v-bind="obj" />`
  49. }
  50. const Parent = {
  51. components: { Child },
  52. template: `<child :obj="{ class: 'foo' }" class="bar"/>`
  53. }
  54. expect(await renderToString(createApp(Parent))).toBe(
  55. `<div class="foo bar"></div>`
  56. )
  57. })
  58. test('nested fallthrough', async () => {
  59. const Child = {
  60. props: ['id'],
  61. template: `<div :id="id"></div>`
  62. }
  63. const Parent = {
  64. components: { Child },
  65. template: `<child id="foo" class="bar"/>`
  66. }
  67. // pass to parent, fallthrough to child and merge
  68. const app = createApp(Parent, { class: 'baz' })
  69. expect(await renderToString(app)).toBe(
  70. `<div id="foo" class="bar baz"></div>`
  71. )
  72. })
  73. })