1
0

entangle.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { haveValue, html, test } from '../utils'
  2. test.skip('can entangle to getter/setter pairs',
  3. [html`
  4. <div x-data="{ outer: 'foo' }">
  5. <input x-model="outer" outer>
  6. <div x-data="{ inner: 'bar' }" x-init="() => {}; Alpine.entangle(
  7. {
  8. get() { return outer },
  9. set(value) { outer = value },
  10. },
  11. {
  12. get() { return inner },
  13. set(value) { inner = value },
  14. }
  15. )">
  16. <input x-model="inner" inner>
  17. </div>
  18. </div>
  19. `],
  20. ({ get }) => {
  21. get('input[outer]').should(haveValue('foo'))
  22. get('input[inner]').should(haveValue('foo'))
  23. get('input[inner]').type('bar')
  24. get('input[inner]').should(haveValue('foobar'))
  25. get('input[outer]').should(haveValue('foobar'))
  26. get('input[outer]').type('baz')
  27. get('input[outer]').should(haveValue('foobarbaz'))
  28. get('input[inner]').should(haveValue('foobarbaz'))
  29. }
  30. )
  31. test.skip('can release entanglement',
  32. [html`
  33. <div x-data="{ outer: 'foo' }">
  34. <input x-model="outer" outer>
  35. <div x-data="{ inner: 'bar', release: () => {} }" x-init="() => {}; release = Alpine.entangle(
  36. {
  37. get() { return outer },
  38. set(value) { outer = value },
  39. },
  40. {
  41. get() { return inner },
  42. set(value) { inner = value },
  43. }
  44. )">
  45. <input x-model="inner" inner>
  46. <button @click="release()">release</button>
  47. </div>
  48. </div>
  49. `],
  50. ({ get }) => {
  51. get('input[outer]').should(haveValue('foo'))
  52. get('input[inner]').should(haveValue('foo'))
  53. get('input[inner]').type('bar')
  54. get('input[inner]').should(haveValue('foobar'))
  55. get('input[outer]').should(haveValue('foobar'))
  56. get('button').click()
  57. get('input[inner]').type('baz')
  58. get('input[inner]').should(haveValue('foobarbaz'))
  59. get('input[outer]').should(haveValue('foobar'))
  60. }
  61. )