|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { compile } from '.' |
| 3 | + |
| 4 | +const css = String.raw |
| 5 | + |
| 6 | +test('Utilities can be wrapped in a selector', async () => { |
| 7 | + // This is the v4 equivalent of `important: "#app"` from v3 |
| 8 | + let input = css` |
| 9 | + #app { |
| 10 | + @tailwind utilities; |
| 11 | + } |
| 12 | + ` |
| 13 | + |
| 14 | + let compiler = await compile(input) |
| 15 | + |
| 16 | + expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(` |
| 17 | + "#app { |
| 18 | + .underline { |
| 19 | + text-decoration-line: underline; |
| 20 | + } |
| 21 | + .hover\\:line-through { |
| 22 | + &:hover { |
| 23 | + @media (hover: hover) { |
| 24 | + text-decoration-line: line-through; |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + " |
| 30 | + `) |
| 31 | +}) |
| 32 | + |
| 33 | +test('Utilities can be marked with important', async () => { |
| 34 | + // This is the v4 equivalent of `important: true` from v3 |
| 35 | + let input = css` |
| 36 | + @import 'tailwindcss/utilities' important; |
| 37 | + ` |
| 38 | + |
| 39 | + let compiler = await compile(input, { |
| 40 | + loadStylesheet: async (id: string, base: string) => ({ |
| 41 | + base, |
| 42 | + content: '@tailwind utilities;', |
| 43 | + }), |
| 44 | + }) |
| 45 | + |
| 46 | + expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(` |
| 47 | + ".underline { |
| 48 | + text-decoration-line: underline!important; |
| 49 | + } |
| 50 | + .hover\\:line-through { |
| 51 | + &:hover { |
| 52 | + @media (hover: hover) { |
| 53 | + text-decoration-line: line-through!important; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + " |
| 58 | + `) |
| 59 | +}) |
| 60 | + |
| 61 | +test('Utilities can be wrapped with a selector and marked as important', async () => { |
| 62 | + // This does not have a direct equivalent in v3 but works as a consequence of |
| 63 | + // the new APIs |
| 64 | + let input = css` |
| 65 | + @media important { |
| 66 | + #app { |
| 67 | + @tailwind utilities; |
| 68 | + } |
| 69 | + } |
| 70 | + ` |
| 71 | + |
| 72 | + let compiler = await compile(input) |
| 73 | + |
| 74 | + expect(compiler.build(['underline', 'hover:line-through'])).toMatchInlineSnapshot(` |
| 75 | + "#app { |
| 76 | + .underline { |
| 77 | + text-decoration-line: underline!important; |
| 78 | + } |
| 79 | + .hover\\:line-through { |
| 80 | + &:hover { |
| 81 | + @media (hover: hover) { |
| 82 | + text-decoration-line: line-through!important; |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + " |
| 88 | + `) |
| 89 | +}) |
0 commit comments