animations.test.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. import { run, html, css } from './util/run'
  2. test('basic', () => {
  3. let config = {
  4. content: [
  5. {
  6. raw: html`
  7. <div class="animate-spin"></div>
  8. <div class="hover:animate-ping"></div>
  9. <div class="group-hover:animate-bounce"></div>
  10. `,
  11. },
  12. ],
  13. }
  14. return run('@tailwind utilities', config).then((result) => {
  15. expect(result.css).toMatchFormattedCss(css`
  16. @keyframes spin {
  17. to {
  18. transform: rotate(360deg);
  19. }
  20. }
  21. .animate-spin {
  22. animation: spin 1s linear infinite;
  23. }
  24. @keyframes ping {
  25. 75%,
  26. 100% {
  27. transform: scale(2);
  28. opacity: 0;
  29. }
  30. }
  31. .hover\:animate-ping:hover {
  32. animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;
  33. }
  34. @keyframes bounce {
  35. 0%,
  36. 100% {
  37. transform: translateY(-25%);
  38. animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  39. }
  40. 50% {
  41. transform: none;
  42. animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  43. }
  44. }
  45. .group:hover .group-hover\:animate-bounce {
  46. animation: bounce 1s infinite;
  47. }
  48. `)
  49. })
  50. })
  51. test('custom', () => {
  52. let config = {
  53. content: [{ raw: html`<div class="animate-one"></div>` }],
  54. theme: {
  55. extend: {
  56. keyframes: {
  57. one: { to: { transform: 'rotate(360deg)' } },
  58. },
  59. animation: {
  60. one: 'one 2s',
  61. },
  62. },
  63. },
  64. }
  65. return run('@tailwind utilities', config).then((result) => {
  66. expect(result.css).toMatchFormattedCss(css`
  67. @keyframes one {
  68. to {
  69. transform: rotate(360deg);
  70. }
  71. }
  72. .animate-one {
  73. animation: one 2s;
  74. }
  75. `)
  76. })
  77. })
  78. test('custom prefixed', () => {
  79. let config = {
  80. prefix: 'tw-',
  81. content: [{ raw: `<div class="tw-animate-one"></div>` }],
  82. theme: {
  83. extend: {
  84. keyframes: {
  85. one: { to: { transform: 'rotate(360deg)' } },
  86. },
  87. animation: {
  88. one: 'one 2s',
  89. },
  90. },
  91. },
  92. }
  93. return run('@tailwind utilities', config).then((result) => {
  94. expect(result.css).toMatchFormattedCss(css`
  95. @keyframes tw-one {
  96. to {
  97. transform: rotate(360deg);
  98. }
  99. }
  100. .tw-animate-one {
  101. animation: tw-one 2s;
  102. }
  103. `)
  104. })
  105. })
  106. test('multiple', () => {
  107. let config = {
  108. content: [{ raw: html`<div class="animate-multiple"></div>` }],
  109. theme: {
  110. extend: {
  111. animation: {
  112. multiple: 'bounce 2s linear, pulse 3s ease-in',
  113. },
  114. },
  115. },
  116. }
  117. return run('@tailwind utilities', config).then((result) => {
  118. expect(result.css).toMatchFormattedCss(css`
  119. @keyframes bounce {
  120. 0%,
  121. 100% {
  122. transform: translateY(-25%);
  123. animation-timing-function: cubic-bezier(0.8, 0, 1, 1);
  124. }
  125. 50% {
  126. transform: none;
  127. animation-timing-function: cubic-bezier(0, 0, 0.2, 1);
  128. }
  129. }
  130. @keyframes pulse {
  131. 50% {
  132. opacity: 0.5;
  133. }
  134. }
  135. .animate-multiple {
  136. animation: bounce 2s linear, pulse 3s ease-in;
  137. }
  138. `)
  139. })
  140. })
  141. test('multiple custom', () => {
  142. let config = {
  143. content: [{ raw: html`<div class="animate-multiple"></div>` }],
  144. theme: {
  145. extend: {
  146. keyframes: {
  147. one: { to: { transform: 'rotate(360deg)' } },
  148. two: { to: { transform: 'scale(1.23)' } },
  149. },
  150. animation: {
  151. multiple: 'one 2s, two 3s',
  152. },
  153. },
  154. },
  155. }
  156. return run('@tailwind utilities', config).then((result) => {
  157. expect(result.css).toMatchFormattedCss(css`
  158. @keyframes one {
  159. to {
  160. transform: rotate(360deg);
  161. }
  162. }
  163. @keyframes two {
  164. to {
  165. transform: scale(1.23);
  166. }
  167. }
  168. .animate-multiple {
  169. animation: one 2s, two 3s;
  170. }
  171. `)
  172. })
  173. })
  174. test('with dots in the name', () => {
  175. let config = {
  176. content: [
  177. {
  178. raw: html`
  179. <div class="animate-zoom-.5"></div>
  180. <div class="animate-zoom-1.5"></div>
  181. `,
  182. },
  183. ],
  184. theme: {
  185. extend: {
  186. keyframes: {
  187. 'zoom-.5': { to: { transform: 'scale(0.5)' } },
  188. 'zoom-1.5': { to: { transform: 'scale(1.5)' } },
  189. },
  190. animation: {
  191. 'zoom-.5': 'zoom-.5 2s',
  192. 'zoom-1.5': 'zoom-1.5 2s',
  193. },
  194. },
  195. },
  196. }
  197. return run('@tailwind utilities', config).then((result) => {
  198. expect(result.css).toMatchFormattedCss(css`
  199. @keyframes zoom-\.5 {
  200. to {
  201. transform: scale(0.5);
  202. }
  203. }
  204. .animate-zoom-\.5 {
  205. animation: zoom-\.5 2s;
  206. }
  207. @keyframes zoom-1\.5 {
  208. to {
  209. transform: scale(1.5);
  210. }
  211. }
  212. .animate-zoom-1\.5 {
  213. animation: zoom-1\.5 2s;
  214. }
  215. `)
  216. })
  217. })
  218. test('with dots in the name and prefix', () => {
  219. let config = {
  220. prefix: 'tw-',
  221. content: [
  222. {
  223. raw: html`
  224. <div class="tw-animate-zoom-.5"></div>
  225. <div class="tw-animate-zoom-1.5"></div>
  226. `,
  227. },
  228. ],
  229. theme: {
  230. extend: {
  231. keyframes: {
  232. 'zoom-.5': { to: { transform: 'scale(0.5)' } },
  233. 'zoom-1.5': { to: { transform: 'scale(1.5)' } },
  234. },
  235. animation: {
  236. 'zoom-.5': 'zoom-.5 2s',
  237. 'zoom-1.5': 'zoom-1.5 2s',
  238. },
  239. },
  240. },
  241. }
  242. return run('@tailwind utilities', config).then((result) => {
  243. expect(result.css).toMatchFormattedCss(css`
  244. @keyframes tw-zoom-\.5 {
  245. to {
  246. transform: scale(0.5);
  247. }
  248. }
  249. .tw-animate-zoom-\.5 {
  250. animation: tw-zoom-\.5 2s;
  251. }
  252. @keyframes tw-zoom-1\.5 {
  253. to {
  254. transform: scale(1.5);
  255. }
  256. }
  257. .tw-animate-zoom-1\.5 {
  258. animation: tw-zoom-1\.5 2s;
  259. }
  260. `)
  261. })
  262. })