-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
86 lines (75 loc) · 1.99 KB
/
test.js
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
83
84
85
import test from 'ava'
import React from 'react'
import { create as render } from 'react-test-renderer'
import Base, { Style } from './src'
test.afterEach(() => {
Base.reset()
})
test('renders', t => {
const a = render(<Base />).toJSON()
t.snapshot(a)
})
test('Style renders', t => {
const a = render(<Style css='.tomato{color:tomato;}' />).toJSON()
t.snapshot(a)
})
test('renders with css prop', t => {
const a = render(<Base css='color:tomato;' />).toJSON()
t.snapshot(a)
})
test('renders with decorated HTML element key', t => {
const a = render(<Base.h2 css='color:tomato;' />).toJSON()
t.snapshot(a)
t.is(a[1].type, 'h2')
})
test('caches results', t => {
const a = render(
<React.Fragment>
<Base css='color:magenta;' />
<Base css='color:magenta;' />
</React.Fragment>
).toJSON()
t.snapshot(a)
})
test('Base.reset() clears cache', t => {
const a = render(<Base css='color:magenta;' />).toJSON()
Base.reset()
const b = render(<Base css='color:magenta;' />).toJSON()
t.snapshot(a)
t.snapshot(b)
t.deepEqual(a[0], b[0])
})
test('Updates styles on css change', t => {
const base = render(<Base css='color:tomato;' />)
const a = base.toJSON()
base.update(<Base css='color:green;' />)
const b = base.toJSON()
t.is(a[1].props.className, 'x0')
t.is(b[1].props.className, 'x1')
t.snapshot(a)
t.snapshot(b)
})
test('Skips update when css is the same', t => {
const base = render(<Base css='color:tomato;' />)
const a = base.toJSON()
base.update(<Base css='color:tomato;' />)
const b = base.toJSON()
t.is(a[1].props.className, 'x0')
t.is(b[1].props.className, 'x0')
t.deepEqual(a, b)
t.snapshot(a)
t.snapshot(b)
})
test('Extends Axs components', t => {
const A = props => (
<Base {...props}
css={`
color: tomato;
${props.css}
`}
/>
)
const a = render(<Base is={A} css='font-size:32px;' />).toJSON()
t.regex(a[0].props.dangerouslySetInnerHTML.__html, /color:tomato;font-size:32px/)
t.snapshot(a)
})