-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
69 lines (56 loc) · 1.41 KB
/
index.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
import test from 'ava'
import React, { Fragment } from 'react'
import { shallow, mount, configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import Knit, {
withSeparator,
withOxfordComma,
withTag,
} from './index.js'
configure({ adapter: new Adapter() })
test('Should join with comma by default', t => {
const result = shallow(<Knit items={['a','b','c']} />)
t.is(result.contains(<Fragment>a, b, c</Fragment>), true)
})
test('Oxford comma', t => {
const result = shallow(<Knit items={['a','b','c']} render={withOxfordComma()} />)
t.is(result.contains(<Fragment>a, b, and c</Fragment>), true)
})
test('Custom renderer', t => {
const result = shallow(
<Knit
items={['a','b','c']}
render={({ item, index, last }) => (
<p key={index}>{item}{ !last && ', ' }</p>
)}
/>
)
t.is(result.contains(<Fragment>
<p>a, </p>
<p>b, </p>
<p>c</p>
</Fragment>), true)
})
test('Create withTag and classname', t => {
const result = shallow(
<Knit
items={['Joe']}
wrap="p"
render={withTag('span', {className: 'user'})}
/>
)
t.is(result.contains(<p>
<span className="user">Joe</span>
</p>), true)
})
test('Custom separator as separator', t => {
const result = shallow(
<Knit
items={['Joe', 'Jane']}
render={withSeparator(' - ')}
/>
)
t.is(result.contains(<Fragment>
Joe - Jane
</Fragment>), true)
})