prefers-contrast.test.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { run, html, css, defaults } from './util/run'
  2. it('should be possible to use contrast-more and contrast-less variants', () => {
  3. let config = {
  4. content: [
  5. { raw: html`<div class="contrast-more:bg-pink-500 contrast-less:bg-black bg-white"></div>` },
  6. ],
  7. corePlugins: { preflight: false },
  8. }
  9. let input = css`
  10. @tailwind base;
  11. @tailwind components;
  12. @tailwind utilities;
  13. `
  14. return run(input, config).then((result) => {
  15. expect(result.css).toMatchFormattedCss(css`
  16. ${defaults}
  17. .bg-white {
  18. --tw-bg-opacity: 1;
  19. background-color: rgb(255 255 255 / var(--tw-bg-opacity));
  20. }
  21. @media (prefers-contrast: more) {
  22. .contrast-more\:bg-pink-500 {
  23. --tw-bg-opacity: 1;
  24. background-color: rgb(236 72 153 / var(--tw-bg-opacity));
  25. }
  26. }
  27. @media (prefers-contrast: less) {
  28. .contrast-less\:bg-black {
  29. --tw-bg-opacity: 1;
  30. background-color: rgb(0 0 0 / var(--tw-bg-opacity));
  31. }
  32. }
  33. `)
  34. })
  35. })
  36. it('dark mode should appear after the contrast variants', () => {
  37. let config = {
  38. content: [{ raw: html`<div class="contrast-more:bg-black dark:bg-white"></div>` }],
  39. corePlugins: { preflight: false },
  40. }
  41. let input = css`
  42. @tailwind base;
  43. @tailwind components;
  44. @tailwind utilities;
  45. `
  46. return run(input, config).then((result) => {
  47. expect(result.css).toMatchFormattedCss(css`
  48. ${defaults}
  49. @media (prefers-contrast: more) {
  50. .contrast-more\:bg-black {
  51. --tw-bg-opacity: 1;
  52. background-color: rgb(0 0 0 / var(--tw-bg-opacity));
  53. }
  54. }
  55. @media (prefers-color-scheme: dark) {
  56. .dark\:bg-white {
  57. --tw-bg-opacity: 1;
  58. background-color: rgb(255 255 255 / var(--tw-bg-opacity));
  59. }
  60. }
  61. `)
  62. })
  63. })