x-transition.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { beHidden, beVisible, haveClasses, html, notBeVisible, notHaveClasses, test } from '../../utils'
  2. test('transition in',
  3. html`
  4. <style>
  5. .transition { transition-property: background-color, border-color, color, fill, stroke; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; }
  6. .duration-100 { transition-duration: 100ms; }
  7. </style>
  8. <div x-data="{ show: false }">
  9. <button x-on:click="show = ! show"></button>
  10. <span
  11. x-show="show"
  12. x-transition:enter="transition duration-100 enter"
  13. x-transition:enter-start="enter-start"
  14. x-transition:enter-end="enter-end"
  15. >thing</span>
  16. </div>
  17. `,
  18. ({ get }) => {
  19. get('span').should(beHidden())
  20. get('span').should(notHaveClasses(['enter', 'enter-start', 'enter-end']))
  21. get('button').click()
  22. get('span').should(beVisible())
  23. get('span').should(notHaveClasses(['enter-start']))
  24. get('span').should(haveClasses(['enter', 'enter-end']))
  25. }
  26. )
  27. test('transition out',
  28. html`
  29. <style>
  30. .transition { transition-property: background-color, border-color, color, fill, stroke; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 150ms; }
  31. .duration-100 { transition-duration: 100ms; }
  32. </style>
  33. <div x-data="{ show: true }">
  34. <button x-on:click="show = ! show"></button>
  35. <span
  36. x-show="show"
  37. x-transition:leave="transition duration-100 leave"
  38. x-transition:leave-start="leave-start"
  39. x-transition:leave-end="leave-end"
  40. >thing</span>
  41. </div>
  42. `,
  43. ({ get }) => {
  44. get('span').should(beVisible())
  45. get('span').should(notHaveClasses(['leave', 'leave-start', 'leave-end']))
  46. get('button').click()
  47. get('span').should(beVisible())
  48. get('span').should(notHaveClasses(['leave-start']))
  49. get('span').should(haveClasses(['leave', 'leave-end']))
  50. get('span').should(beHidden())
  51. }
  52. )