1
0

x-html.spec.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { haveText, notHaveText, html, test } from '../../utils'
  2. test('sets html on init',
  3. html`
  4. <div x-data="{ foo: '<h1>hey</h1>' }">
  5. <span x-html="foo"></span>
  6. </div>
  7. `,
  8. ({ get }) => {
  9. get('h1').should(haveText('hey'))
  10. }
  11. )
  12. test('sets html on update',
  13. html`
  14. <div x-data="{ foo: '' }">
  15. <button x-on:click="foo = '<h1>hey</h1>'">Show "bar"</button>
  16. <span x-html="foo"></span>
  17. </div>
  18. `,
  19. ({ get }) => {
  20. get('span').should(notHaveText('hey'))
  21. get('button').click()
  22. get('h1').should(haveText('hey'))
  23. }
  24. )
  25. test('x-html allows alpine code within',
  26. html`
  27. <div x-data="{ foo: '<h1 x-text=&quot;bar&quot;></h1>', bar: 'baz' }" x-html="foo"></div>
  28. `,
  29. ({ get }) => {
  30. get('h1').should(haveText('baz'))
  31. }
  32. )
  33. test.only('x-html runs even after x-if or x-for',
  34. html`
  35. <div x-data="{ html: '<span x-text=&quot;foo&quot;></span>', foo: 'bar' }">
  36. <template x-if="true">
  37. <h1>yoyoyo</h1>
  38. </template>
  39. <div x-html="html"></div>
  40. </div>
  41. `,
  42. ({ get }) => {
  43. get('span').should(haveText('bar'))
  44. }
  45. )