dark-mode.test.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { run, html, css, defaults } from './util/run'
  2. it('should be possible to use the darkMode "class" mode', () => {
  3. let config = {
  4. darkMode: 'class',
  5. content: [{ raw: html`<div class="dark:font-bold"></div>` }],
  6. corePlugins: { preflight: false },
  7. }
  8. let input = css`
  9. @tailwind base;
  10. @tailwind components;
  11. @tailwind utilities;
  12. `
  13. return run(input, config).then((result) => {
  14. expect(result.css).toMatchFormattedCss(css`
  15. ${defaults}
  16. .dark .dark\:font-bold {
  17. font-weight: 700;
  18. }
  19. `)
  20. })
  21. })
  22. it('should be possible to change the class name', () => {
  23. let config = {
  24. darkMode: ['class', '.test-dark'],
  25. content: [{ raw: html`<div class="dark:font-bold"></div>` }],
  26. corePlugins: { preflight: false },
  27. }
  28. let input = css`
  29. @tailwind base;
  30. @tailwind components;
  31. @tailwind utilities;
  32. `
  33. return run(input, config).then((result) => {
  34. expect(result.css).toMatchFormattedCss(css`
  35. ${defaults}
  36. .test-dark .dark\:font-bold {
  37. font-weight: 700;
  38. }
  39. `)
  40. })
  41. })
  42. it('should be possible to use the darkMode "media" mode', () => {
  43. let config = {
  44. darkMode: 'media',
  45. content: [{ raw: html`<div class="dark:font-bold"></div>` }],
  46. corePlugins: { preflight: false },
  47. }
  48. let input = css`
  49. @tailwind base;
  50. @tailwind components;
  51. @tailwind utilities;
  52. `
  53. return run(input, config).then((result) => {
  54. expect(result.css).toMatchFormattedCss(css`
  55. ${defaults}
  56. @media (prefers-color-scheme: dark) {
  57. .dark\:font-bold {
  58. font-weight: 700;
  59. }
  60. }
  61. `)
  62. })
  63. })
  64. it('should default to the `media` mode when no mode is provided', () => {
  65. let config = {
  66. content: [{ raw: html`<div class="dark:font-bold"></div>` }],
  67. corePlugins: { preflight: false },
  68. }
  69. let input = css`
  70. @tailwind base;
  71. @tailwind components;
  72. @tailwind utilities;
  73. `
  74. return run(input, config).then((result) => {
  75. expect(result.css).toMatchFormattedCss(css`
  76. ${defaults}
  77. @media (prefers-color-scheme: dark) {
  78. .dark\:font-bold {
  79. font-weight: 700;
  80. }
  81. }
  82. `)
  83. })
  84. })
  85. it('should default to the `media` mode when mode is set to `false`', () => {
  86. let config = {
  87. darkMode: false,
  88. content: [{ raw: html`<div class="dark:font-bold"></div>` }],
  89. corePlugins: { preflight: false },
  90. }
  91. let input = css`
  92. @tailwind base;
  93. @tailwind components;
  94. @tailwind utilities;
  95. `
  96. return run(input, config).then((result) => {
  97. expect(result.css).toMatchFormattedCss(css`
  98. ${defaults}
  99. @media (prefers-color-scheme: dark) {
  100. .dark\:font-bold {
  101. font-weight: 700;
  102. }
  103. }
  104. `)
  105. })
  106. })