detect-nesting.test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { run, html, css } from './util/run'
  2. it('should warn when we detect nested css', () => {
  3. let config = {
  4. content: [{ raw: html`<div class="nested"></div>` }],
  5. }
  6. let input = css`
  7. @tailwind utilities;
  8. .nested {
  9. .example {
  10. }
  11. }
  12. `
  13. return run(input, config).then((result) => {
  14. expect(result.messages).toHaveLength(1)
  15. expect(result.messages).toMatchObject([
  16. {
  17. type: 'warning',
  18. text: [
  19. 'Nested CSS was detected, but CSS nesting has not been configured correctly.',
  20. 'Please enable a CSS nesting plugin *before* Tailwind in your configuration.',
  21. 'See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting',
  22. ].join('\n'),
  23. },
  24. ])
  25. })
  26. })
  27. it('should warn when we detect namespaced @tailwind at rules', () => {
  28. let config = {
  29. content: [{ raw: html`<div class="text-center"></div>` }],
  30. }
  31. let input = css`
  32. .namespace {
  33. @tailwind utilities;
  34. }
  35. `
  36. return run(input, config).then((result) => {
  37. expect(result.messages).toHaveLength(1)
  38. expect(result.messages).toMatchObject([
  39. {
  40. type: 'warning',
  41. text: [
  42. 'Nested @tailwind rules were detected, but are not supported.',
  43. "Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix",
  44. 'Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy',
  45. ].join('\n'),
  46. },
  47. ])
  48. })
  49. })
  50. it('should not warn when nesting a single rule inside a media query', () => {
  51. let config = {
  52. content: [{ raw: html`<div class="nested"></div>` }],
  53. }
  54. let input = css`
  55. @tailwind utilities;
  56. @media (min-width: 768px) {
  57. .nested {
  58. }
  59. }
  60. `
  61. return run(input, config).then((result) => {
  62. expect(result.messages).toHaveLength(0)
  63. expect(result.messages).toEqual([])
  64. })
  65. })
  66. it('should only warn for the first detected nesting ', () => {
  67. let config = {
  68. content: [{ raw: html`<div class="nested other"></div>` }],
  69. }
  70. let input = css`
  71. @tailwind utilities;
  72. .nested {
  73. .example {
  74. }
  75. .other {
  76. }
  77. }
  78. .other {
  79. .example {
  80. }
  81. }
  82. `
  83. return run(input, config).then((result) => {
  84. expect(result.messages).toHaveLength(1)
  85. })
  86. })