x-transition.spec.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { beHidden, beVisible, haveClasses, haveComputedStyle, html, notBeVisible, notHaveClasses, notHaveComputedStyle, 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. )
  53. test('transition:enter in nested x-show visually runs',
  54. html`
  55. <style>
  56. .transition { transition: opacity 1s ease; }
  57. .opacity-0 {opacity: 0}
  58. .opacity-1 {opacity: 1}
  59. </style>
  60. <div x-data="{ show: false }">
  61. <span x-show="show">
  62. <h1 x-show="show"
  63. x-transition:enter="transition"
  64. x-transition:enter-start="opacity-0"
  65. x-transition:enter-end="opacity-1">thing</h1>
  66. </span>
  67. <button x-on:click="show = true"></button>
  68. </div>
  69. `,
  70. ({ get }) => {
  71. get('button').click()
  72. get('span').should(beVisible())
  73. get('h1').should(notHaveComputedStyle('opacity', '1')) // We expect a value between 0 and 1
  74. get('h1').should(haveComputedStyle('opacity', '1')) // Eventually opacity will be 1
  75. }
  76. )