-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
73 lines (63 loc) · 1.49 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
'use strict'
global.document = require('jsdom').jsdom('<body></body>')
global.window = document.defaultView
global.navigator = window.navigator
var test = require('tape')
var h = require('react-hyperscript')
var Provider = require('./provider')
var Translate = require('./translate')
var TranslateRaw = require('./translate-raw')
var {mount} = require('enzyme')
var dictionary = {
id: 'en_US',
values: {
HELLO: 'Hello, {{name}}.'
}
}
test('it works', t => {
var wrapper = mount(
h(Provider, {dictionary}, [
h(Translate, {
id: 'HELLO',
data: {name: 'robot'}
})
])
)
t.equal(wrapper.html(), '<span>Hello, robot.</span>')
t.end()
})
test('fail without context', t => {
t.throws(
() => mount(h(Translate, {
id: 'HELLO',
data: {name: 'robot'}
}))
)
t.end()
})
test('allow custom tagName and other props', t => {
var wrapper = mount(
h(Provider, {dictionary}, [
h(Translate, {
tagName: 'article',
className: 'my-class',
id: 'HELLO',
data: {name: 'robot'}
})
])
)
t.equal(wrapper.html(), '<article class="my-class">Hello, robot.</article>')
t.end()
})
test('TranslateRaw', t => {
var wrapper = mount(
h(Provider, {dictionary}, [
h(TranslateRaw, null, (translate) => {
t.equal(typeof translate, 'function')
return h('.foo', translate('HELLO', {name: 'world'}))
})
])
)
t.equal(wrapper.html(), '<div class="foo">Hello, world.</div>')
t.end()
})