parallel-variants.test.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { run, html, css } from './util/run'
  2. test('basic parallel variants', async () => {
  3. let config = {
  4. content: [
  5. {
  6. raw: html`<div
  7. class="hover:test:font-black test:font-bold test:font-medium font-normal"
  8. ></div>`,
  9. },
  10. ],
  11. plugins: [
  12. function test({ addVariant }) {
  13. addVariant('test', ['& *::test', '&::test'])
  14. },
  15. ],
  16. }
  17. return run('@tailwind utilities', config).then((result) => {
  18. expect(result.css).toMatchFormattedCss(css`
  19. .font-normal {
  20. font-weight: 400;
  21. }
  22. .test\:font-bold ::test {
  23. font-weight: 700;
  24. }
  25. .test\:font-medium ::test {
  26. font-weight: 500;
  27. }
  28. .hover\:test\:font-black ::test:hover {
  29. font-weight: 900;
  30. }
  31. .test\:font-bold::test {
  32. font-weight: 700;
  33. }
  34. .test\:font-medium::test {
  35. font-weight: 500;
  36. }
  37. .hover\:test\:font-black::test:hover {
  38. font-weight: 900;
  39. }
  40. `)
  41. })
  42. })
  43. test('parallel variants can be generated using a function that returns parallel variants', async () => {
  44. let config = {
  45. content: [
  46. {
  47. raw: html`<div
  48. class="hover:test:font-black test:font-bold test:font-medium font-normal"
  49. ></div>`,
  50. },
  51. ],
  52. plugins: [
  53. function test({ addVariant }) {
  54. addVariant('test', () => ['& *::test', '&::test'])
  55. },
  56. ],
  57. }
  58. return run('@tailwind utilities', config).then((result) => {
  59. expect(result.css).toMatchFormattedCss(css`
  60. .font-normal {
  61. font-weight: 400;
  62. }
  63. .test\:font-bold ::test {
  64. font-weight: 700;
  65. }
  66. .test\:font-medium ::test {
  67. font-weight: 500;
  68. }
  69. .test\:font-bold::test {
  70. font-weight: 700;
  71. }
  72. .test\:font-medium::test {
  73. font-weight: 500;
  74. }
  75. .hover\:test\:font-black ::test:hover {
  76. font-weight: 900;
  77. }
  78. .hover\:test\:font-black::test:hover {
  79. font-weight: 900;
  80. }
  81. `)
  82. })
  83. })
  84. test('a function that returns parallel variants can modify the container', async () => {
  85. let config = {
  86. content: [
  87. {
  88. raw: html`<div
  89. class="hover:test:font-black test:font-bold test:font-medium font-normal"
  90. ></div>`,
  91. },
  92. ],
  93. plugins: [
  94. function test({ addVariant }) {
  95. addVariant('test', ({ container }) => {
  96. container.walkDecls((decl) => {
  97. decl.value = `calc(0 + ${decl.value})`
  98. })
  99. return ['& *::test', '&::test']
  100. })
  101. },
  102. ],
  103. }
  104. return run('@tailwind utilities', config).then((result) => {
  105. expect(result.css).toMatchFormattedCss(css`
  106. .font-normal {
  107. font-weight: 400;
  108. }
  109. .test\:font-bold ::test {
  110. font-weight: 700;
  111. }
  112. .test\:font-medium ::test {
  113. font-weight: 500;
  114. }
  115. .test\:font-bold::test {
  116. font-weight: 700;
  117. }
  118. .test\:font-medium::test {
  119. font-weight: 500;
  120. }
  121. .hover\:test\:font-black ::test:hover {
  122. font-weight: 900;
  123. }
  124. .hover\:test\:font-black::test:hover {
  125. font-weight: 900;
  126. }
  127. `)
  128. })
  129. })