Skip to content

Commit 4a1d5d3

Browse files
authored
chore: fix focus assertions in tests (#34129)
1 parent 7fb72e7 commit 4a1d5d3

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

packages/react-components/react-list/library/src/components/List/List.cy.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const mount = (element: JSX.Element) => {
2424
*/
2525
const testSequence = (sequence: Array<string>) => {
2626
cy.get('#outside-button').click();
27-
cy.get('#outside-button').focused();
27+
cy.get('#outside-button').should('be.focused');
2828

2929
cy.get('[data-test^=list-item-]').first().focus();
30-
cy.get('[data-test^=list-item-]').focused();
30+
cy.get('[data-test^=list-item-]').should('be.focused');
3131

3232
for (const command of sequence) {
3333
if (command.startsWith('focused:')) {

packages/react-components/react-tabster/src/hooks/useFocusedElementChange.cy.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ describe('useFocusedElementChange', () => {
2525
mount(<Example callback={callback} />);
2626

2727
cy.get('#anchor').click();
28-
cy.get('#anchor').focused();
28+
cy.get('#anchor').should('be.focused');
2929

3030
cy.get('#button').focus();
31-
cy.get('#button').focused();
31+
cy.get('#button').should('be.focused');
3232

3333
cy.get('@callback').should('have.been.calledWith', Cypress.sinon.match.instanceOf(HTMLButtonElement), {
3434
relatedTarget: Cypress.sinon.match.instanceOf(HTMLAnchorElement),
@@ -41,10 +41,10 @@ describe('useFocusedElementChange', () => {
4141
mount(<Example callback={callback} />);
4242

4343
cy.get('#anchor').click();
44-
cy.get('#anchor').focused();
44+
cy.get('#anchor').should('be.focused');
4545

4646
cy.get('#button').invoke('focus');
47-
cy.get('#button').focused();
47+
cy.get('#button').should('be.focused');
4848

4949
cy.get('@callback').should('have.been.calledWith', Cypress.sinon.match.instanceOf(HTMLButtonElement), {
5050
relatedTarget: Cypress.sinon.match.instanceOf(HTMLAnchorElement),

packages/react-components/react-toolbar/library/src/components/Toolbar/Toolbar.cy.tsx

+12-11
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ describe('Toolbar', () => {
3131
);
3232

3333
cy.get(button).eq(0).click();
34-
cy.get(button).eq(0).focused();
34+
cy.get(button).eq(0).should('be.focused');
3535

3636
cy.get(button).eq(0).type('{rightArrow}');
37-
cy.get(button).eq(1).focused();
37+
cy.get(button).eq(1).should('be.focused');
3838

3939
cy.get(button).eq(1).type('{downArrow}');
40-
cy.get(button).eq(2).focused();
40+
cy.get(button).eq(2).should('be.focused');
4141

4242
cy.get(button).eq(2).type('{upArrow}');
43-
cy.get(button).eq(1).focused();
43+
cy.get(button).eq(1).should('be.focused');
4444

4545
cy.get(button).eq(1).type('{leftArrow}');
46-
cy.get(button).eq(0).focused();
46+
cy.get(button).eq(0).should('be.focused');
4747
});
4848

4949
it('should have circular navigation', () => {
@@ -57,13 +57,13 @@ describe('Toolbar', () => {
5757
);
5858

5959
cy.get(button).eq(3).click();
60-
cy.get(button).eq(3).focused();
60+
cy.get(button).eq(3).should('be.focused');
6161

6262
cy.get(button).eq(3).type('{rightArrow}');
63-
cy.get(button).eq(0).focused();
63+
cy.get(button).eq(0).should('be.focused');
6464

6565
cy.get(button).eq(0).type('{leftArrow}');
66-
cy.get(button).eq(3).focused();
66+
cy.get(button).eq(3).should('be.focused');
6767
});
6868
});
6969

@@ -174,7 +174,8 @@ describe('ToolbarDivider', () => {
174174
</Toolbar>,
175175
);
176176

177-
cy.get('html').type('Tab').type('{rightarrow}').get(button).eq(0).focused();
177+
cy.get('html').type('Tab').type('{rightarrow}');
178+
cy.get(button).eq(0).should('be.focused');
178179
});
179180

180181
it('should navigate with arrow key', () => {
@@ -190,7 +191,7 @@ describe('ToolbarDivider', () => {
190191
cy.get(button).eq(0).click();
191192

192193
cy.get(button).eq(0).type('{rightarrow}');
193-
cy.get(button).eq(1).focused();
194+
cy.get(button).eq(1).should('be.focused');
194195
});
195196

196197
it('should have circular navigation', () => {
@@ -206,6 +207,6 @@ describe('ToolbarDivider', () => {
206207
cy.get(button).eq(0).click();
207208

208209
cy.get(button).eq(0).type('{leftarrow}');
209-
cy.get(button).eq(2).focused();
210+
cy.get(button).eq(2).should('be.focused');
210211
});
211212
});

0 commit comments

Comments
 (0)