Skip to content

Commit 9055272

Browse files
committed
Improve unit test stability
1 parent 47d1c38 commit 9055272

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/Calendar/Navigation.spec.jsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@ describe('Navigation', () => {
2020
it('renders prev2, prev, drill up, next and next2 buttons', () => {
2121
const { container } = render(<Navigation {...defaultProps} view="month" />);
2222

23-
const children = [...container.firstChild.children];
23+
const children = [...container.firstElementChild.children];
2424

2525
const [prev2, prev, drillUp, next, next2] = children;
2626

2727
expect(children).toHaveLength(5);
28-
expect(prev2.type).toBe('button');
29-
expect(prev.type).toBe('button');
30-
expect(drillUp.type).toBe('button');
31-
expect(next.type).toBe('button');
32-
expect(next2.type).toBe('button');
28+
expect(prev2.getAttribute('type')).toBe('button');
29+
expect(prev.getAttribute('type')).toBe('button');
30+
expect(drillUp.getAttribute('type')).toBe('button');
31+
expect(next.getAttribute('type')).toBe('button');
32+
expect(next2.getAttribute('type')).toBe('button');
3333
});
3434

3535
it('renders prev, drill up, next and buttons only for century view', () => {
3636
const { container } = render(<Navigation {...defaultProps} view="century" />);
3737

38-
const children = [...container.firstChild.children];
38+
const children = [...container.firstElementChild.children];
3939

4040
const [prev, drillUp, next] = children;
4141

4242
expect(children).toHaveLength(3);
43-
expect(prev.type).toBe('button');
44-
expect(drillUp.type).toBe('button');
45-
expect(next.type).toBe('button');
43+
expect(prev.getAttribute('type')).toBe('button');
44+
expect(drillUp.getAttribute('type')).toBe('button');
45+
expect(next.getAttribute('type')).toBe('button');
4646
});
4747

4848
it('displays proper title for month view', () => {
@@ -97,7 +97,7 @@ describe('Navigation', () => {
9797
/>,
9898
);
9999

100-
const [prev2, prev, , next, next2] = [...container.firstChild.children];
100+
const [prev2, prev, , next, next2] = [...container.firstElementChild.children];
101101

102102
expect(prev2).toHaveTextContent('prev2Label');
103103
expect(prev).toHaveTextContent('prevLabel');
@@ -110,7 +110,7 @@ describe('Navigation', () => {
110110
<Navigation {...defaultProps} navigationAriaLive="polite" view="month" />,
111111
);
112112

113-
const [, , navigation] = [...container.firstChild.children];
113+
const [, , navigation] = [...container.firstElementChild.children];
114114

115115
expect(navigation).toHaveAttribute('aria-live', 'polite');
116116
});
@@ -128,7 +128,7 @@ describe('Navigation', () => {
128128
/>,
129129
);
130130

131-
const [prev2, prev, navigation, next, next2] = [...container.firstChild.children];
131+
const [prev2, prev, navigation, next, next2] = [...container.firstElementChild.children];
132132

133133
expect(prev2).toHaveAccessibleName('prev2AriaLabel');
134134
expect(prev).toHaveAccessibleName('prevAriaLabel');

src/Flex.spec.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Flex', () => {
1313
</Flex>,
1414
);
1515

16-
const wrapper = container.firstChild;
16+
const wrapper = container.firstElementChild;
1717

1818
expect(wrapper).toHaveStyle('display: flex');
1919
expect(wrapper).toHaveStyle('flex-wrap: nowrap');
@@ -28,7 +28,7 @@ describe('Flex', () => {
2828
</Flex>,
2929
);
3030

31-
const wrapper = container.firstChild;
31+
const wrapper = container.firstElementChild;
3232

3333
expect(wrapper).toHaveStyle('display: flex');
3434
expect(wrapper).toHaveStyle('flex-wrap: wrap');
@@ -43,7 +43,7 @@ describe('Flex', () => {
4343
</Flex>,
4444
);
4545

46-
const children = [...container.firstChild.children];
46+
const children = [...container.firstElementChild.children];
4747

4848
expect(children).toHaveLength(3);
4949
expect(children[0]).toHaveTextContent('Hey');
@@ -59,7 +59,7 @@ describe('Flex', () => {
5959
</Flex>,
6060
);
6161

62-
const children = [...container.firstChild.children];
62+
const children = [...container.firstElementChild.children];
6363

6464
children.forEach((child) => expect(child).toHaveStyle('flex-basis: 33.333333333333336%'));
6565
expect(children[0]).toHaveStyle('margin-left: 33.333333333333336%');

0 commit comments

Comments
 (0)