-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathTitle.test.js
85 lines (74 loc) · 2.44 KB
/
Title.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 { mount } from 'enzyme';
import React from 'react';
import Title from './Title';
describe('<Title />', () => {
describe('Prop spreading', () => {
test('should allow props to be spread to the Title component', () => {
const element = mount(
<Title
data-sample='Sample'
level={1} />
);
expect(
element.getDOMNode().attributes['data-sample'].value
).toBe('Sample');
});
});
describe('Title level', () => {
test('should set the tagname of the element', () => {
const element = mount(
<Title
data-sample='Sample'
level={1} />
);
expect(element.getDOMNode().tagName).toBe('H1');
});
test('should be used as the visual style by default', () => {
const element = mount(
<Title
data-sample='Sample'
level={1} />
);
expect(
element.getDOMNode().attributes.class.value
).toBe('fd-title fd-title--h1');
});
test('style should be overriden if levelStyle prop is passed', () => {
const element = mount(
<Title
data-sample='Sample'
level={1}
levelStyle={3} />
);
expect(
element.getDOMNode().attributes.class.value
).toBe('fd-title fd-title--h3');
});
});
describe('Wrap class name', () => {
test('should be added if the wrap prop is set to true', () => {
const element = mount(
<Title
data-sample='Sample'
level={1}
wrap />
);
expect(
element.getDOMNode().attributes.class.value
).toBe('fd-title fd-title--h1 fd-title--wrap');
});
});
test('forwards the ref', () => {
let ref;
class Test extends React.Component {
constructor(props) {
super(props);
ref = React.createRef();
}
render = () => <Title level={1} ref={ref} />;
}
mount(<Test />);
expect(ref.current.tagName).toEqual('H1');
expect(ref.current.className).toEqual('fd-title fd-title--h1');
});
});