Skip to content

Commit a691211

Browse files
committed
[EuiButtonIcon] Convert Enzyme tests to RTL
1 parent 5799190 commit a691211

File tree

2 files changed

+44
-43
lines changed

2 files changed

+44
-43
lines changed

src/components/button/button_icon/__snapshots__/button_icon.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ exports[`EuiButtonIcon props color danger is rendered 1`] = `
4949
exports[`EuiButtonIcon props color ghost is rendered 1`] = `
5050
<button
5151
aria-label="button"
52-
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text"
52+
class="euiButtonIcon emotion-euiButtonIcon-xs-empty-text-euiColorMode-dark-colorClassName"
5353
type="button"
5454
>
5555
<span
@@ -257,7 +257,7 @@ exports[`EuiButtonIcon props isLoading is rendered 1`] = `
257257
aria-label="Loading"
258258
class="euiLoadingSpinner emotion-euiLoadingSpinner-m"
259259
role="progressbar"
260-
style="border-color:#07C currentcolor currentcolor currentcolor"
260+
style="border-color: #07c currentcolor currentcolor currentcolor;"
261261
/>
262262
</button>
263263
`;

src/components/button/button_icon/button_icon.test.tsx

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,47 @@
77
*/
88

99
import React from 'react';
10-
import { render, mount } from 'enzyme';
10+
import { fireEvent } from '@testing-library/dom';
11+
import { render } from '../../../test/rtl';
1112
import { requiredProps } from '../../../test/required_props';
1213
import { shouldRenderCustomStyles } from '../../../test/internal';
1314

1415
import { EuiButtonIcon, DISPLAYS, SIZES } from './button_icon';
1516
import { BUTTON_COLORS } from '../../../themes/amsterdam/global_styling/mixins';
1617

1718
describe('EuiButtonIcon', () => {
19+
shouldRenderCustomStyles(
20+
<EuiButtonIcon iconType="user" {...requiredProps} />
21+
);
22+
1823
test('is rendered', () => {
19-
const component = render(
24+
const { container } = render(
2025
<EuiButtonIcon iconType="user" {...requiredProps} />
2126
);
2227

23-
expect(component).toMatchSnapshot();
28+
expect(container.firstChild).toMatchSnapshot();
2429
});
2530

26-
shouldRenderCustomStyles(
27-
<EuiButtonIcon iconType="user" {...requiredProps} />
28-
);
29-
3031
describe('props', () => {
3132
describe('isDisabled', () => {
3233
it('is rendered', () => {
33-
const component = render(
34+
const { container } = render(
3435
<EuiButtonIcon iconType="user" aria-label="button" isDisabled />
3536
);
3637

37-
expect(component).toMatchSnapshot();
38+
expect(container.firstChild).toMatchSnapshot();
3839
});
3940

4041
it('or disabled is rendered', () => {
41-
const component = render(
42+
const { container } = render(
4243
<EuiButtonIcon iconType="user" aria-label="button" disabled />
4344
);
4445

45-
expect(component).toMatchSnapshot();
46+
expect(container.firstChild).toMatchSnapshot();
4647
});
4748

4849
it('renders a button even when href is defined', () => {
49-
const component = render(
50+
const { container } = render(
5051
<EuiButtonIcon
5152
iconType="user"
5253
aria-label="button"
@@ -55,93 +56,93 @@ describe('EuiButtonIcon', () => {
5556
/>
5657
);
5758

58-
expect(component).toMatchSnapshot();
59+
expect(container.firstChild).toMatchSnapshot();
5960
});
6061
});
6162

6263
describe('iconType', () => {
6364
it('is rendered', () => {
64-
const component = render(
65+
const { container } = render(
6566
<EuiButtonIcon aria-label="button" iconType="user" />
6667
);
6768

68-
expect(component).toMatchSnapshot();
69+
expect(container.firstChild).toMatchSnapshot();
6970
});
7071
});
7172

7273
describe('color', () => {
7374
BUTTON_COLORS.forEach((color) => {
7475
test(`${color} is rendered`, () => {
75-
const component = render(
76+
const { container } = render(
7677
<EuiButtonIcon iconType="user" aria-label="button" color={color} />
7778
);
7879

79-
expect(component).toMatchSnapshot();
80+
expect(container.firstChild).toMatchSnapshot();
8081
});
8182
});
8283

8384
test('ghost is rendered', () => {
84-
const component = render(
85+
const { container } = render(
8586
<EuiButtonIcon iconType="user" aria-label="button" color={'ghost'} />
8687
);
8788

88-
expect(component).toMatchSnapshot();
89+
expect(container.firstChild).toMatchSnapshot();
8990
});
9091
});
9192

9293
describe('display', () => {
9394
DISPLAYS.forEach((display) => {
9495
test(`${display} is rendered`, () => {
95-
const component = render(
96+
const { container } = render(
9697
<EuiButtonIcon
9798
iconType="user"
9899
aria-label="button"
99100
display={display}
100101
/>
101102
);
102103

103-
expect(component).toMatchSnapshot();
104+
expect(container.firstChild).toMatchSnapshot();
104105
});
105106
});
106107
});
107108

108109
describe('size', () => {
109110
SIZES.forEach((size) => {
110111
test(`${size} is rendered`, () => {
111-
const component = render(
112+
const { container } = render(
112113
<EuiButtonIcon iconType="user" aria-label="button" size={size} />
113114
);
114115

115-
expect(component).toMatchSnapshot();
116+
expect(container.firstChild).toMatchSnapshot();
116117
});
117118
});
118119
});
119120

120121
describe('isSelected', () => {
121122
it('is rendered as true', () => {
122-
const component = render(
123+
const { container } = render(
123124
<EuiButtonIcon iconType="user" aria-label="button" isSelected />
124125
);
125126

126-
expect(component).toMatchSnapshot();
127+
expect(container.firstChild).toMatchSnapshot();
127128
});
128129

129130
it('is rendered as false', () => {
130-
const component = render(
131+
const { container } = render(
131132
<EuiButtonIcon
132133
iconType="user"
133134
aria-label="button"
134135
isSelected={false}
135136
/>
136137
);
137138

138-
expect(component).toMatchSnapshot();
139+
expect(container.firstChild).toMatchSnapshot();
139140
});
140141
});
141142

142143
describe('href', () => {
143144
it('secures the rel attribute when the target is _blank', () => {
144-
const component = render(
145+
const { container } = render(
145146
<EuiButtonIcon
146147
iconType="user"
147148
aria-label="button"
@@ -150,42 +151,42 @@ describe('EuiButtonIcon', () => {
150151
/>
151152
);
152153

153-
expect(component).toMatchSnapshot();
154+
expect(container.firstChild).toMatchSnapshot();
154155
});
155156
});
156157

157158
describe('onClick', () => {
158159
it('supports onClick and href', () => {
159-
const handler = jest.fn();
160-
const component = mount(
160+
const onClick = jest.fn();
161+
const { container } = render(
161162
<EuiButtonIcon
162163
iconType="user"
163164
aria-label="hoi"
164165
href="#"
165-
onClick={handler}
166+
onClick={onClick}
166167
/>
167168
);
168-
component.find('a').simulate('click');
169-
expect(handler.mock.calls.length).toEqual(1);
169+
fireEvent.click(container.querySelector('a')!);
170+
expect(onClick).toHaveBeenCalledTimes(1);
170171
});
171172

172173
it('supports onClick as a button', () => {
173-
const handler = jest.fn();
174-
const component = mount(
175-
<EuiButtonIcon iconType="user" aria-label="hoi" onClick={handler} />
174+
const onClick = jest.fn();
175+
const { container } = render(
176+
<EuiButtonIcon iconType="user" aria-label="hoi" onClick={onClick} />
176177
);
177-
component.find('button').simulate('click');
178-
expect(handler.mock.calls.length).toEqual(1);
178+
fireEvent.click(container.querySelector('button')!);
179+
expect(onClick).toHaveBeenCalledTimes(1);
179180
});
180181
});
181182

182183
describe('isLoading', () => {
183184
it('is rendered', () => {
184-
const component = render(
185+
const { container } = render(
185186
<EuiButtonIcon aria-label="button" iconType="user" isLoading />
186187
);
187188

188-
expect(component).toMatchSnapshot();
189+
expect(container.firstChild).toMatchSnapshot();
189190
});
190191
});
191192
});

0 commit comments

Comments
 (0)