Skip to content

Commit 43876a5

Browse files
authored
test(e2e): fix flaky tests with React 18 and StrictMode (#34549)
1 parent 3c4faa1 commit 43876a5

File tree

4 files changed

+20
-42
lines changed

4 files changed

+20
-42
lines changed

packages/react-components/react-card/library/src/components/Card/Card.cy.tsx

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,15 @@ describe('Card', () => {
161161
it('should focus inner elements on EnterKey press', () => {
162162
mountFluent(<CardSample focusMode="no-tab" />);
163163

164-
cy.get('#card').focus();
165-
166-
cy.realPress('Enter');
164+
cy.get('#card').realClick().realPress('Enter');
167165

168166
cy.get('#open-button').should('be.focused');
169167
});
170168

171169
it('should not focus inner elements on Tab press', () => {
172170
mountFluent(<CardSample focusMode="no-tab" />);
173171

174-
cy.get('#card').focus();
175-
176-
cy.realPress('Tab');
172+
cy.get('#card').realClick().realPress('Tab');
177173

178174
cy.get('#card').should('not.be.focused');
179175
cy.get('#after').should('be.focused');
@@ -182,9 +178,7 @@ describe('Card', () => {
182178
it('should trap focus', () => {
183179
mountFluent(<CardSample focusMode="no-tab" />);
184180

185-
cy.get('#open-button').focus();
186-
187-
cy.realPress('Tab');
181+
cy.get('#open-button').realClick().realPress('Tab');
188182

189183
cy.get('#open-button').should('not.be.focused');
190184
cy.get('#close-button').should('be.focused');
@@ -198,9 +192,7 @@ describe('Card', () => {
198192
it('should focus parent on Esc press', () => {
199193
mountFluent(<CardSample focusMode="no-tab" />);
200194

201-
cy.get('#open-button').focus();
202-
203-
cy.realPress('Escape');
195+
cy.get('#open-button').realClick().realPress('Escape');
204196

205197
cy.get('#open-button').should('not.be.focused');
206198
cy.get('#card').should('be.focused');
@@ -223,19 +215,15 @@ describe('Card', () => {
223215
it('should focus inner elements on EnterKey press', () => {
224216
mountFluent(<CardSample focusMode="tab-exit" />);
225217

226-
cy.get('#card').focus();
227-
228-
cy.realPress('Enter');
218+
cy.get('#card').realClick().realPress('Enter');
229219

230220
cy.get('#open-button').should('be.focused');
231221
});
232222

233223
it('should not focus inner elements on Tab press', () => {
234224
mountFluent(<CardSample focusMode="tab-exit" />);
235225

236-
cy.get('#card').focus();
237-
238-
cy.realPress('Tab');
226+
cy.get('#card').realClick().realPress('Tab');
239227

240228
cy.get('#card').should('not.be.focused');
241229
cy.get('#after').should('be.focused');
@@ -244,17 +232,15 @@ describe('Card', () => {
244232
it('should exit on Tab press', () => {
245233
mountFluent(<CardSample focusMode="tab-exit" />);
246234

247-
cy.get('#close-button').focus();
248-
249-
cy.realPress('Tab');
235+
cy.get('#close-button').realClick().realPress('Tab');
250236

251237
cy.get('#after').should('be.focused');
252238
});
253239

254240
it('should focus parent on Esc press', () => {
255241
mountFluent(<CardSample focusMode="tab-exit" />);
256242

257-
cy.get('#card').focus().realPress('Enter');
243+
cy.get('#card').realClick().realPress('Enter');
258244

259245
cy.get('#open-button').should('be.focused');
260246

@@ -280,19 +266,15 @@ describe('Card', () => {
280266
it('should focus inner elements on EnterKey press', () => {
281267
mountFluent(<CardSample focusMode="tab-only" />);
282268

283-
cy.get('#card').focus();
284-
285-
cy.realPress('Enter');
269+
cy.get('#card').realClick().realPress('Enter');
286270

287271
cy.get('#open-button').should('be.focused');
288272
});
289273

290274
it('should focus inner elements on Tab press', () => {
291275
mountFluent(<CardSample focusMode="tab-only" />);
292276

293-
cy.get('#card').focus();
294-
295-
cy.realPress('Tab');
277+
cy.get('#card').realClick().realPress('Tab');
296278

297279
cy.get('#card').should('not.be.focused');
298280
cy.get('#open-button').should('be.focused');
@@ -301,9 +283,7 @@ describe('Card', () => {
301283
it('should exit on Tab press', () => {
302284
mountFluent(<CardSample focusMode="tab-only" />);
303285

304-
cy.get('#close-button').focus();
305-
306-
cy.realPress('Tab');
286+
cy.get('#close-button').realClick().realPress('Tab');
307287

308288
cy.get('#after').should('be.focused');
309289
});

packages/react-components/react-tag-picker/library/src/components/TagPicker/TagPicker.cy.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ const TagPickerControlled = ({
4040
noPopover = false,
4141
}: TagPickerControlledProps) => {
4242
const [selectedOptions, setSelectedOptions] = React.useState<string[]>(defaultSelectedOptions);
43-
const onOptionSelect: TagPickerProps['onOptionSelect'] = (e, data) => {
44-
setSelectedOptions(data.selectedOptions);
45-
};
46-
const handleAllClear: React.MouseEventHandler = event => {
47-
setSelectedOptions([]);
48-
};
43+
const onOptionSelect: TagPickerProps['onOptionSelect'] = (_, data) => setSelectedOptions(data.selectedOptions);
44+
const handleAllClear: React.MouseEventHandler = _ => setSelectedOptions([]);
4945

5046
return (
5147
<div style={{ display: 'flex', maxWidth: 400, flexDirection: 'column', gap: 20 }}>
@@ -57,6 +53,7 @@ const TagPickerControlled = ({
5753
selectedOptions={selectedOptions}
5854
open={open}
5955
defaultOpen={defaultOpen}
56+
inline
6057
>
6158
<TagPickerControl
6259
data-testid="tag-picker-control"

packages/react-components/react-toast/library/src/components/Toast/Toast.cy.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { Toaster, ToastTitle, Toast, useToastController, toastClassNames } from
77
import { toastContainerClassNames } from '../ToastContainer/useToastContainerStyles.styles';
88

99
const mount = (element: JSX.Element) => {
10-
mountBase(<FluentProvider theme={teamsLightTheme}>{element}</FluentProvider>);
10+
mountBase(<FluentProvider theme={teamsLightTheme}>{element}</FluentProvider>, {
11+
strict: false, // TODO: Disable strict mode for toast tests until it gets fixed
12+
});
1113
};
1214

1315
describe('Toast', () => {
@@ -316,9 +318,8 @@ describe('Toast', () => {
316318
};
317319

318320
mount(<Example />);
319-
cy.get('#make')
320-
.click()
321-
.get('li')
321+
cy.get('#make').realClick();
322+
cy.get('li')
322323
.should('have.length', 4)
323324
.get('li')
324325
.eq(0)

packages/react-components/react-tree/library/src/components/FlatTree/FlatTree.cy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ describe('FlatTree', () => {
434434
/>,
435435
);
436436
cy.window().then(win => {
437-
expect(win.console.error).to.be.callCount(1);
437+
expect(win.console.error).to.be.called;
438438
});
439439
});
440440
it('should change selection when selecting a closed branch', () => {

0 commit comments

Comments
 (0)