|
| 1 | +import prefixSelector from '../src/util/prefixSelector.js' |
1 | 2 | import { run, html, css, defaults } from './util/run'
|
2 | 3 |
|
3 | 4 | test('prefix', () => {
|
@@ -607,3 +608,45 @@ test('supports non-word prefixes (2)', async () => {
|
607 | 608 | }
|
608 | 609 | `)
|
609 | 610 | })
|
| 611 | + |
| 612 | +test('does not prefix arbitrary group/peer classes', async () => { |
| 613 | + let config = { |
| 614 | + prefix: 'tw-', |
| 615 | + content: [ |
| 616 | + { |
| 617 | + raw: html` |
| 618 | + <div class="tw-group tw-peer lol"> |
| 619 | + <div class="group-[&.lol]:tw-flex"></div> |
| 620 | + </div> |
| 621 | + <div class="peer-[&.lol]:tw-flex"></div> |
| 622 | + `, |
| 623 | + }, |
| 624 | + ], |
| 625 | + corePlugins: { preflight: false }, |
| 626 | + } |
| 627 | + |
| 628 | + let input = css` |
| 629 | + @tailwind utilities; |
| 630 | + ` |
| 631 | + |
| 632 | + const result = await run(input, config) |
| 633 | + |
| 634 | + // TODO: The class `.hover\:before\:\@\]\$content-\[\'Hovering\'\]:hover::before` is not generated |
| 635 | + // This happens because of the parenthesis/brace/bracket clipping performed on candidates |
| 636 | + |
| 637 | + expect(result.css).toMatchFormattedCss(css` |
| 638 | + .tw-group.lol .group-\[\&\.lol\]\:tw-flex, |
| 639 | + .tw-peer.lol ~ .peer-\[\&\.lol\]\:tw-flex { |
| 640 | + display: flex; |
| 641 | + } |
| 642 | + `) |
| 643 | +}) |
| 644 | + |
| 645 | +// Unit tests for prefixSelector |
| 646 | +describe('prefixSelector', () => { |
| 647 | + it('works', () => { |
| 648 | + expect(prefixSelector('tw-', '.foo', false)).toBe('.tw-foo') |
| 649 | + expect(prefixSelector('tw-', '.foo.bar.baz', false)).toBe('.tw-foo.tw-bar.tw-baz') |
| 650 | + expect(prefixSelector('tw-', '.foo:tw-no-prefix(.bar).baz', false)).toBe('.tw-foo.bar.tw-baz') |
| 651 | + }) |
| 652 | +}) |
0 commit comments