Skip to content

Commit

Permalink
Add tests for base and preset layers in CSS layer handling
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Jan 14, 2025
1 parent 49a65ef commit 2a6331f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/core/tests/layers/base.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test } from 'vitest'
import { expectLayers } from '../test'

test.concurrent('basic', () => {
expectLayers({ base: '.block\\@base{display:block}' }, 'block@base')
})

test.concurrent('with selectors', () => {
expectLayers({ base: '.font\\:12_\\:is\\(code\\,pre\\)\\@base :is(code,pre){font-size:0.75rem}' }, 'font:12_:is(code,pre)@base')
})
6 changes: 5 additions & 1 deletion packages/core/tests/layers/preset.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { test } from 'vitest'
import { expectLayers } from '../test'

test.concurrent('add to @layer preset by @preset', () => {
test.concurrent('basic', () => {
expectLayers({ preset: '.block\\@preset{display:block}' }, 'block@preset')
})

test.concurrent('with selectors', () => {
expectLayers({ preset: '.font\\:12_\\:is\\(code\\,pre\\)\\@preset :is(code,pre){font-size:0.75rem}' }, 'font:12_:is(code,pre)@preset')
})
2 changes: 2 additions & 0 deletions packages/core/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const expectLayers = (
theme?: string
styles?: string
general?: string
base?: string
animations?: string
preset?: string
},
Expand All @@ -16,6 +17,7 @@ export const expectLayers = (
if (layers.theme) expect(cssRuleText).toContain(`@layer theme{${layers.theme ?? ''}}`)
if (layers.styles) expect(cssRuleText).toContain(`@layer styles{${layers.styles ?? ''}}`)
if (layers.preset) expect(cssRuleText).toContain(`@layer preset{${layers.preset ?? ''}}`)
if (layers.base) expect(cssRuleText).toContain(`@layer base{${layers.base ?? ''}}`)
if (layers.general) expect(cssRuleText).toContain(`@layer general{${layers.general ?? ''}}`)
if (layers.animations) expect(cssRuleText).toContain(`${layers.animations ?? ''}`)
}
Expand Down

0 comments on commit 2a6331f

Please sign in to comment.