/
getUtils.test.ts
82 lines (76 loc) · 1.93 KB
/
getUtils.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { createGenerator, warnOnce } from '@unocss/core'
import presetUno from '@unocss/preset-uno'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { getUtils } from './getUtils'
vi.mock('@unocss/core', async () => {
const actual = await vi.importActual<typeof import('@unocss/core')>('@unocss/core')
return {
...actual,
warnOnce: vi.fn(),
// warnOnce: vi.fn().mockImplementation(() => console.log('hello')),
}
})
describe('getUtils', async () => {
afterEach(() => {
vi.restoreAllMocks()
})
const uno = createGenerator({
presets: [
presetUno(),
],
})
it('combines rules with same selector', async () => {
const body = 'mb-1 mr-1 hover:mr-2'
const result = await getUtils(body, uno)
expect(result).toMatchInlineSnapshot(`
[
[
84,
".\\\\-",
"margin-bottom:0.25rem;margin-right:0.25rem;",
undefined,
{
"layer": undefined,
"sort": undefined,
},
undefined,
undefined,
],
[
84,
".\\\\-:hover",
"margin-right:0.5rem;",
undefined,
{
"layer": undefined,
"sort": 22,
},
undefined,
true,
],
]
`)
})
it('expands variant groups and warns on incorrect class', async () => {
// const warnOnceMock = (warnOnce as Mock).mockImplementation(message => console.warn(`${message}HI`))
const body = 'hover:(mr-1 font-medium foo fee)'
const result = await getUtils(body, uno)
expect(result).toMatchInlineSnapshot(`
[
[
84,
".\\\\-:hover",
"margin-right:0.25rem;font-weight:500;",
undefined,
{
"layer": undefined,
"sort": 22,
},
undefined,
true,
],
]
`)
expect(warnOnce).toHaveBeenCalledTimes(2)
})
})