forked from lingui/js-lingui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRender.test.js
65 lines (55 loc) · 1.77 KB
/
Render.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
// @flow
import * as React from "react"
import { shallow } from "enzyme"
import Render from "./Render"
describe("Render", function() {
it("should render just a text without wrapping element", function() {
const ctx = shallow(<Render value="Just a text" />)
expect(ctx).toMatchSnapshot()
const context = {
linguiDefaultRender: null
}
const span = shallow(<Render render={null} value="Just a text" />, {
context
})
expect(span).toMatchSnapshot()
const withClass = shallow(
<Render render={null} className="info" value="Just a text" />,
{ context }
)
expect(withClass).toMatchSnapshot()
})
it("should render with span wrapping element", function() {
const context = {
linguiDefaultRender: "span"
}
const span = shallow(<Render value="Just a text" />, { context })
expect(span).toMatchSnapshot()
const withClass = shallow(<Render className="info" value="Just a text" />, {
context
})
expect(withClass).toMatchSnapshot()
})
it("should render custom element", function() {
const builtin = shallow(<Render render="h1" value="Headline" />)
expect(builtin).toMatchSnapshot()
const element = shallow(<Render render={<h1 />} value="Headline" />)
expect(element).toMatchSnapshot()
})
it("should render custom component", function() {
const component = shallow(
<Render
value="Title"
render={({ translation }) => <a title={translation}>X</a>}
/>
)
expect(component.dive()).toMatchSnapshot()
})
it("should take default render element from context", function() {
const context = {
linguiDefaultRender: <h1 />
}
const span = shallow(<Render value="Just a text" />, { context })
expect(span).toMatchSnapshot()
})
})