Skip to content

Commit

Permalink
Improve unit test stability
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Mar 1, 2023
1 parent f1623cb commit edb305d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions src/Calendar/Navigation.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ describe('Navigation', () => {
it('renders prev2, prev, drill up, next and next2 buttons', () => {
const { container } = render(<Navigation {...defaultProps} view="month" />);

const children = [...container.firstChild.children];
const children = [...container.firstElementChild.children];

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

expect(children).toHaveLength(5);
expect(prev2.type).toBe('button');
expect(prev.type).toBe('button');
expect(drillUp.type).toBe('button');
expect(next.type).toBe('button');
expect(next2.type).toBe('button');
expect(prev2.getAttribute('type')).toBe('button');
expect(prev.getAttribute('type')).toBe('button');
expect(drillUp.getAttribute('type')).toBe('button');
expect(next.getAttribute('type')).toBe('button');
expect(next2.getAttribute('type')).toBe('button');
});

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

const children = [...container.firstChild.children];
const children = [...container.firstElementChild.children];

const [prev, drillUp, next] = children;

expect(children).toHaveLength(3);
expect(prev.type).toBe('button');
expect(drillUp.type).toBe('button');
expect(next.type).toBe('button');
expect(prev.getAttribute('type')).toBe('button');
expect(drillUp.getAttribute('type')).toBe('button');
expect(next.getAttribute('type')).toBe('button');
});

it('displays proper title for month view', () => {
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('Navigation', () => {
/>,
);

const [prev2, prev, , next, next2] = [...container.firstChild.children];
const [prev2, prev, , next, next2] = [...container.firstElementChild.children];

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

const [, , navigation] = [...container.firstChild.children];
const [, , navigation] = [...container.firstElementChild.children];

expect(navigation).toHaveAttribute('aria-live', 'polite');
});
Expand All @@ -128,7 +128,7 @@ describe('Navigation', () => {
/>,
);

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

expect(prev2).toHaveAccessibleName('prev2AriaLabel');
expect(prev).toHaveAccessibleName('prevAriaLabel');
Expand Down
8 changes: 4 additions & 4 deletions src/Flex.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Flex', () => {
</Flex>,
);

const wrapper = container.firstChild;
const wrapper = container.firstElementChild;

expect(wrapper).toHaveStyle('display: flex');
expect(wrapper).toHaveStyle('flex-wrap: nowrap');
Expand All @@ -28,7 +28,7 @@ describe('Flex', () => {
</Flex>,
);

const wrapper = container.firstChild;
const wrapper = container.firstElementChild;

expect(wrapper).toHaveStyle('display: flex');
expect(wrapper).toHaveStyle('flex-wrap: wrap');
Expand All @@ -43,7 +43,7 @@ describe('Flex', () => {
</Flex>,
);

const children = [...container.firstChild.children];
const children = [...container.firstElementChild.children];

expect(children).toHaveLength(3);
expect(children[0]).toHaveTextContent('Hey');
Expand All @@ -59,7 +59,7 @@ describe('Flex', () => {
</Flex>,
);

const children = [...container.firstChild.children];
const children = [...container.firstElementChild.children];

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

0 comments on commit edb305d

Please sign in to comment.