-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.js
70 lines (63 loc) · 1.61 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
import test from 'ava'
import React from 'react'
import { create as render } from 'react-test-renderer'
import tag from './index'
test('renders', t => {
const json = render(React.createElement(tag)).toJSON()
t.is(json.type, 'div')
t.snapshot(json)
})
test('omits props', t => {
const json = render(React.createElement(tag, {
id: 'hello',
theme: {},
m: 2,
px: 3,
color: 'blue'
})).toJSON()
t.is(json.props.m, undefined)
t.is(json.props.px, undefined)
t.is(json.props.blue, undefined)
t.is(json.props.theme, undefined)
t.is(json.props.id, 'hello')
})
test('exports html tags', t => {
const h1 = render(React.createElement(tag.h1)).toJSON()
const header = render(React.createElement(tag.header)).toJSON()
t.is(h1.type, 'h1')
t.is(header.type, 'header')
})
test('exported html tags only omits props', t => {
const json = render(React.createElement(tag.h1, {
id: 'hello',
m: 2,
px: 3,
color: 'blue'
})).toJSON()
t.is(json.props.m, undefined)
t.is(json.props.px, undefined)
t.is(json.props.blue, undefined)
t.is(json.props.id, 'hello')
})
test('accepts an is prop to change the underlying element', t => {
const json = render(React.createElement(tag, {
is: 'header'
})).toJSON()
t.is(json.type, 'header')
})
test('accepts custom omitProps', t => {
const json = render(React.createElement(tag, {
hello: 'hi',
omitProps: [ 'hello' ]
})).toJSON()
t.is(json.props.hello, undefined)
})
test('forwards ref', t => {
let ref = 'hi'
const json = render(
React.createElement(tag, {
ref: r => ref = r
})
).toJSON()
t.not(ref, 'hi')
})