important-selector.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import fs from 'fs'
  2. import path from 'path'
  3. import { run, css } from './util/run'
  4. test('important selector', () => {
  5. let config = {
  6. important: '#app',
  7. darkMode: 'class',
  8. content: [path.resolve(__dirname, './important-selector.test.html')],
  9. corePlugins: { preflight: false },
  10. plugins: [
  11. function ({ addComponents, addUtilities }) {
  12. addComponents(
  13. {
  14. '.btn': {
  15. button: 'yes',
  16. },
  17. },
  18. { respectImportant: true }
  19. )
  20. addComponents(
  21. {
  22. '@font-face': {
  23. 'font-family': 'Inter',
  24. },
  25. '@page': {
  26. margin: '1cm',
  27. },
  28. },
  29. { respectImportant: true }
  30. )
  31. addUtilities(
  32. {
  33. '.custom-util': {
  34. button: 'no',
  35. },
  36. },
  37. { respectImportant: false }
  38. )
  39. },
  40. ],
  41. }
  42. let input = css`
  43. @tailwind base;
  44. @tailwind components;
  45. @layer components {
  46. .custom-component {
  47. @apply font-bold;
  48. }
  49. .custom-important-component {
  50. @apply text-center !important;
  51. }
  52. }
  53. @tailwind utilities;
  54. `
  55. return run(input, config).then((result) => {
  56. let expectedPath = path.resolve(__dirname, './important-selector.test.css')
  57. let expected = fs.readFileSync(expectedPath, 'utf8')
  58. expect(result.css).toMatchFormattedCss(expected)
  59. })
  60. })