/
utils.ts
62 lines (51 loc) · 1.65 KB
/
utils.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
import { Theme } from '../src'
import { makeColorsScale, makeStyles, makeTheme } from '../src/utils'
import { AssertTrue, expecter, IsExact } from '@theme-ui/test-utils'
const symbolPretendingToBeTheme = Symbol() as Theme
describe(makeTheme, () => {
it('returns input unchanged', () => {
const actual = makeTheme(symbolPretendingToBeTheme)
expect(actual).toEqual(symbolPretendingToBeTheme)
})
it('preserves type of the argument', () => {
const theme = makeTheme({
colors: {
primary: 'tomato',
},
})
type _ = AssertTrue<
IsExact<typeof theme, { colors: { primary: 'tomato' } }>
>
})
it('is exposed from entrypoint /utils and validates Theme type', () => {
expecter('import { makeTheme } from "@theme-ui/css/utils"')(
'const t = makeTheme("banana")'
).toFail(/Type '"banana"' has no properties in common with type 'Theme'./)
})
})
describe(makeStyles, () => {
it('returns input unchanged', () => {
const actual = makeTheme(symbolPretendingToBeTheme)
expect(actual).toEqual(symbolPretendingToBeTheme)
})
it('preserves type of the argument', () => {
const styles = makeStyles({
code: {},
})
type _ = AssertTrue<IsExact<typeof styles, { code: {} }>>
})
})
describe(makeColorsScale, () => {
it('returns input unchanged', () => {
const actual = makeTheme(symbolPretendingToBeTheme)
expect(actual).toEqual(symbolPretendingToBeTheme)
})
it('preserves type of the argument', () => {
const colors = makeColorsScale({
blue: {
light: '#e6f7ff',
},
})
type _ = AssertTrue<IsExact<typeof colors, { blue: { light: '#e6f7ff' } }>>
})
})