Skip to content

Commit 4d63b13

Browse files
test(widgets): refactor tests to use asFragment for snapshot matching
1 parent c42d1b2 commit 4d63b13

File tree

12 files changed

+145
-141
lines changed

12 files changed

+145
-141
lines changed

packages/pluggableWidgets/accordion-web/src/components/__tests__/Accordion.spec.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ describe("Accordion", () => {
129129
it("renders correctly without tabindex", () => {
130130
const accordion = renderAccordion({ tabIndex: undefined });
131131

132-
expect(accordion.container).toMatchSnapshot();
132+
expect(accordion.asFragment()).toMatchSnapshot();
133133
});
134134

135135
describe("in collapsible & single expanded group mode", () => {
136136
it("renders correctly", () => {
137137
const accordion = renderAccordion();
138138

139-
expect(accordion.container).toMatchSnapshot();
139+
expect(accordion.asFragment()).toMatchSnapshot();
140140
});
141141

142142
it("expands a group", async () => {
@@ -145,7 +145,7 @@ describe("Accordion", () => {
145145

146146
await user.click(button);
147147

148-
expect(accordion.container).toMatchSnapshot();
148+
expect(accordion.asFragment()).toMatchSnapshot();
149149
});
150150

151151
it("allows one group to be expanded only", async () => {
@@ -159,7 +159,7 @@ describe("Accordion", () => {
159159
await user.click(buttons[buttons.length - 1]);
160160

161161
expect(buttons[1]).toHaveFocus();
162-
expect(accordion.container).toMatchSnapshot();
162+
expect(accordion.asFragment()).toMatchSnapshot();
163163
});
164164

165165
it("collapses a group", async () => {
@@ -169,30 +169,30 @@ describe("Accordion", () => {
169169
await user.click(button);
170170
await user.click(button);
171171

172-
expect(accordion.container).toMatchSnapshot();
172+
expect(accordion.asFragment()).toMatchSnapshot();
173173
});
174174

175175
it("inits with group initially collapsed settings", () => {
176176
const groups = [...defaultProps.groups];
177177
groups[0].initiallyCollapsed = false;
178178
const accordion = renderAccordion({ groups });
179179

180-
expect(accordion.container).toMatchSnapshot();
180+
expect(accordion.asFragment()).toMatchSnapshot();
181181
});
182182

183183
it("inits with not more than one group expanded", () => {
184184
const groups = [...defaultProps.groups].map(group => ({ ...group, initiallyCollapsed: false }));
185185
const accordion = renderAccordion({ groups });
186186

187-
expect(accordion.container).toMatchSnapshot();
187+
expect(accordion.asFragment()).toMatchSnapshot();
188188
});
189189
});
190190

191191
describe("in collapsible & multiple expanded group mode", () => {
192192
it("renders correctly", () => {
193193
const accordion = renderAccordion({ singleExpandedGroup: false });
194194

195-
expect(accordion.container).toMatchSnapshot();
195+
expect(accordion.asFragment()).toMatchSnapshot();
196196
});
197197

198198
it("expands a group", async () => {
@@ -201,7 +201,7 @@ describe("Accordion", () => {
201201

202202
await user.click(button);
203203

204-
expect(accordion.container).toMatchSnapshot();
204+
expect(accordion.asFragment()).toMatchSnapshot();
205205
});
206206

207207
it("allows multiple groups to be expanded", async () => {
@@ -214,7 +214,7 @@ describe("Accordion", () => {
214214
await user.click(buttons[0]);
215215
await user.click(buttons[buttons.length - 1]);
216216

217-
expect(accordion.container).toMatchSnapshot();
217+
expect(accordion.asFragment()).toMatchSnapshot();
218218
});
219219

220220
it("collapses a group", async () => {
@@ -228,7 +228,7 @@ describe("Accordion", () => {
228228
await user.click(buttons[buttons.length - 1]);
229229
await user.click(buttons[0]);
230230

231-
expect(accordion.container).toMatchSnapshot();
231+
expect(accordion.asFragment()).toMatchSnapshot();
232232
});
233233

234234
it("inits with group initially collapsed settings", () => {
@@ -243,7 +243,7 @@ describe("Accordion", () => {
243243

244244
const accordion = renderAccordion({ singleExpandedGroup: false, groups });
245245

246-
expect(accordion.container).toMatchSnapshot();
246+
expect(accordion.asFragment()).toMatchSnapshot();
247247
});
248248

249249
it("applies group collapsed value changes", () => {
@@ -253,15 +253,15 @@ describe("Accordion", () => {
253253

254254
accordion.rerender(<Accordion {...defaultProps} singleExpandedGroup={false} groups={newGroups} />);
255255

256-
expect(accordion.container).toMatchSnapshot();
256+
expect(accordion.asFragment()).toMatchSnapshot();
257257
});
258258
});
259259

260260
describe("not collapsible", () => {
261261
it("renders correctly", () => {
262262
const accordion = renderAccordion({ collapsible: false });
263263

264-
expect(accordion.container).toMatchSnapshot();
264+
expect(accordion.asFragment()).toMatchSnapshot();
265265
});
266266
});
267267
});

packages/pluggableWidgets/accordion-web/src/components/__tests__/AccordionGroup.spec.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("AccordionGroup", () => {
3333
const accordionGroup = renderAccordionGroup({ visible: false });
3434

3535
expect(defaultAccordionGroupProps.generateHeaderIcon).not.toHaveBeenCalled();
36-
expect(accordionGroup.container).toMatchSnapshot();
36+
expect(accordionGroup.asFragment()).toMatchSnapshot();
3737
});
3838

3939
describe("collapsible", () => {
@@ -57,7 +57,7 @@ describe("AccordionGroup", () => {
5757

5858
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(1);
5959
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledWith(true);
60-
expect(accordionGroup.container).toMatchSnapshot();
60+
expect(accordionGroup.asFragment()).toMatchSnapshot();
6161
});
6262

6363
it("renders correctly when the group is visible and expanded", () => {
@@ -67,7 +67,7 @@ describe("AccordionGroup", () => {
6767

6868
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(1);
6969
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledWith(false);
70-
expect(accordionGroup.container).toMatchSnapshot();
70+
expect(accordionGroup.asFragment()).toMatchSnapshot();
7171
});
7272

7373
it("renders correctly when the group is visible and gets expanded", () => {
@@ -85,7 +85,7 @@ describe("AccordionGroup", () => {
8585
);
8686
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(3);
8787
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledWith(false);
88-
expect(accordionGroup.container).toMatchSnapshot();
88+
expect(accordionGroup.asFragment()).toMatchSnapshot();
8989
});
9090

9191
it("renders correctly when the group is visible and gets collapsed", () => {
@@ -100,7 +100,7 @@ describe("AccordionGroup", () => {
100100
);
101101
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(3);
102102
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledWith(true);
103-
expect(accordionGroup.container).toMatchSnapshot();
103+
expect(accordionGroup.asFragment()).toMatchSnapshot();
104104
});
105105

106106
it("renders correctly when the group becomes visible and is collapsed", () => {
@@ -114,7 +114,7 @@ describe("AccordionGroup", () => {
114114
);
115115
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(1);
116116
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledWith(true);
117-
expect(accordionGroup.container).toMatchSnapshot();
117+
expect(accordionGroup.asFragment()).toMatchSnapshot();
118118
});
119119

120120
it("renders correctly when the group becomes visible and is expanded", () => {
@@ -129,7 +129,7 @@ describe("AccordionGroup", () => {
129129
);
130130
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(2);
131131
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledWith(false);
132-
expect(accordionGroup.container).toMatchSnapshot();
132+
expect(accordionGroup.asFragment()).toMatchSnapshot();
133133
});
134134

135135
describe("header", () => {
@@ -273,7 +273,7 @@ describe("AccordionGroup", () => {
273273
showHeaderIcon: "no"
274274
});
275275

276-
expect(accordionGroup.container).toMatchSnapshot();
276+
expect(accordionGroup.asFragment()).toMatchSnapshot();
277277
});
278278
});
279279
});
@@ -285,7 +285,7 @@ describe("AccordionGroup", () => {
285285
});
286286

287287
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(0);
288-
expect(accordionGroup.container).toMatchSnapshot();
288+
expect(accordionGroup.asFragment()).toMatchSnapshot();
289289
});
290290

291291
it("renders the content when the group becomes visible dinamically", () => {
@@ -296,7 +296,7 @@ describe("AccordionGroup", () => {
296296

297297
accordionGroup.rerender(<AccordionGroup {...defaultAccordionGroupProps} visible collapsed={false} />);
298298
expect(defaultAccordionGroupProps.generateHeaderIcon).toHaveBeenCalledTimes(0);
299-
expect(accordionGroup.container).toMatchSnapshot();
299+
expect(accordionGroup.asFragment()).toMatchSnapshot();
300300
});
301301
});
302302

@@ -309,7 +309,7 @@ describe("AccordionGroup", () => {
309309
});
310310

311311
expect(accordionGroup.getByText("Widgets")).toBeInTheDocument();
312-
expect(accordionGroup.container).toMatchSnapshot();
312+
expect(accordionGroup.asFragment()).toMatchSnapshot();
313313
});
314314

315315
it("doesn't render widgets when 'loadContent' is set 'whenExpanded'", () => {
@@ -320,7 +320,7 @@ describe("AccordionGroup", () => {
320320
});
321321

322322
expect(accordionGroup.queryByText("Widgets")).not.toBeInTheDocument();
323-
expect(accordionGroup.container).toMatchSnapshot();
323+
expect(accordionGroup.asFragment()).toMatchSnapshot();
324324
});
325325

326326
it("render widgets when 'loadContent' is set 'whenExpanded' and 'collapsed' is set to false", () => {

packages/pluggableWidgets/accordion-web/src/components/__tests__/Header.spec.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,36 @@ describe("Header", () => {
2020
it("renders h1", () => {
2121
const header = renderHeader({ heading: "headingOne" });
2222

23-
expect(header.container).toMatchSnapshot();
23+
expect(header.asFragment()).toMatchSnapshot();
2424
});
2525

2626
it("renders h2", () => {
2727
const header = renderHeader({ heading: "headingTwo" });
2828

29-
expect(header.container).toMatchSnapshot();
29+
expect(header.asFragment()).toMatchSnapshot();
3030
});
3131

3232
it("renders h3", () => {
3333
const header = renderHeader();
3434

35-
expect(header.container).toMatchSnapshot();
35+
expect(header.asFragment()).toMatchSnapshot();
3636
});
3737

3838
it("renders h4", () => {
3939
const header = renderHeader({ heading: "headingFour" });
4040

41-
expect(header.container).toMatchSnapshot();
41+
expect(header.asFragment()).toMatchSnapshot();
4242
});
4343

4444
it("renders h5", () => {
4545
const header = renderHeader({ heading: "headingFive" });
4646

47-
expect(header.container).toMatchSnapshot();
47+
expect(header.asFragment()).toMatchSnapshot();
4848
});
4949

5050
it("renders h6", () => {
5151
const header = renderHeader({ heading: "headingSix" });
5252

53-
expect(header.container).toMatchSnapshot();
53+
expect(header.asFragment()).toMatchSnapshot();
5454
});
5555
});

packages/pluggableWidgets/accordion-web/src/components/__tests__/Icon.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ describe("Icon", () => {
2222
it("renders glyph icons", () => {
2323
const icon = renderIcon();
2424

25-
expect(icon.container).toMatchSnapshot();
25+
expect(icon.asFragment()).toMatchSnapshot();
2626
});
2727

2828
it("renders image icons", () => {
2929
const icon = renderIcon({ data: { type: "image", iconUrl: "icon.url" } });
3030

31-
expect(icon.container).toMatchSnapshot();
31+
expect(icon.asFragment()).toMatchSnapshot();
3232
});
3333

3434
it("renders a default icon", () => {
3535
const icon = renderIcon({ data: undefined });
3636

37-
expect(icon.container).toMatchSnapshot();
37+
expect(icon.asFragment()).toMatchSnapshot();
3838
});
3939

4040
it("doesn't render a default icon while loading", () => {
4141
const icon = renderIcon({ data: undefined, loading: true });
4242

43-
expect(icon.container).toMatchSnapshot();
43+
expect(icon.asFragment()).toMatchSnapshot();
4444
});
4545

4646
it("doesn't render an icon with an unknown icon data type", () => {
4747
const icon = renderIcon({ data: { type: "unknown" } as any });
4848

49-
expect(icon.container).toMatchSnapshot();
49+
expect(icon.asFragment()).toMatchSnapshot();
5050
});
5151
});
5252

0 commit comments

Comments
 (0)