-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathtest.mjs
More file actions
69 lines (61 loc) · 1.77 KB
/
test.mjs
File metadata and controls
69 lines (61 loc) · 1.77 KB
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
// @ts-check
import themeUICustomProperties from '..'
import mockConsole from 'jest-mock-console'
const toCustomProperties = /** @type {{ default: import('..').default }} */ (
/** @type {any} */ (themeUICustomProperties)
).default
const theme = {
colors: {
text: '#000',
background: '#fff',
primary: '#07c',
secondary: '#05a',
accent: '#609',
muted: '#f6f6f6',
dark: {
foreground: {
text: '#000',
},
background: {
surface: '#fff',
},
},
},
fonts: {
body: 'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif',
heading:
'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif',
monospace: 'Menlo, monospace',
},
fontWeights: {
body: 400,
heading: 700,
bold: 700,
},
lineHeights: [1.5, 1.125],
space: [0, 2, 3, 4, 5, 6],
size: ['10em', '20em', '30em', '40em'],
radii: {
s: '0.125em',
m: '0.25em',
l: '0.5em',
},
}
it('transforms a theme config to CSS custom properties', () => {
mockConsole()
const result = toCustomProperties(theme)
expect(result).toMatchSnapshot()
expect(console.warn).toHaveBeenCalledTimes(0)
})
it('transforms a theme config to CSS custom properties with prefix', () => {
const result = toCustomProperties(theme, '🍭')
expect(result).toMatchSnapshot()
})
it('warns on invalid CSS custom property key', () => {
mockConsole()
toCustomProperties({ sizes: { '1/4': 1 / 4, '1/2': 1 / 2 } })
expect(console.warn).toHaveBeenCalledTimes(2)
expect(console.warn).toHaveBeenLastCalledWith(
'[theme-ui] Theme key "0.5" found will produce an invalid CSS custom property. Keys must only contain the following: A-Z, a-z, 0-9, hyphen, underscore.'
)
})