x-html.spec.js 862 B

12345678910111213141516171819202122232425262728293031323334353637
  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. )