custom-bind.spec.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { haveText, html, test } from '../utils'
  2. test('can register custom bind object',
  3. html`
  4. <script>
  5. document.addEventListener('alpine:init', () => {
  6. Alpine.bind('Foo', {
  7. 'x-init'() { this.$el.innerText = 'bar' },
  8. })
  9. })
  10. </script>
  11. <div x-data x-bind="Foo"></div>
  12. `,
  13. ({ get }) => get('div').should(haveText('bar'))
  14. )
  15. test('can register custom bind as function',
  16. html`
  17. <script>
  18. document.addEventListener('alpine:init', () => {
  19. Alpine.bind('Foo', () => ({
  20. 'x-init'() { this.$el.innerText = 'bar' },
  21. }))
  22. })
  23. </script>
  24. <div x-data x-bind="Foo"></div>
  25. `,
  26. ({ get }) => get('div').should(haveText('bar'))
  27. )
  28. test('can consume custom bind as function',
  29. html`
  30. <script>
  31. document.addEventListener('alpine:init', () => {
  32. Alpine.bind('Foo', (subject) => ({
  33. 'x-init'() { this.$el.innerText = subject },
  34. }))
  35. })
  36. </script>
  37. <div x-data x-bind="Foo('bar')"></div>
  38. `,
  39. ({ get }) => get('div').should(haveText('bar'))
  40. )