Skip to content

Commit

Permalink
JSDOM skip base performance tests that rely on focus visible
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Jun 26, 2024
1 parent 26075d5 commit 16dddbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 9 additions & 3 deletions packages/mui-base/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ describe('<Menu />', () => {
});
});

it('perf: does not rerender menu items unnecessarily', async () => {
it('perf: does not rerender menu items unnecessarily', async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// JSDOM doesn't support :focus-visible
this.skip();
}

const renderItem1Spy = spy();
const renderItem2Spy = spy();
const renderItem3Spy = spy();
Expand Down Expand Up @@ -683,9 +688,10 @@ describe('<Menu />', () => {
fireEvent.keyDown(menuItems[0], { key: 'ArrowDown' }); // highlights '2'

// React renders twice in strict mode, so we expect twice the number of spy calls
// Also, useButton's focusVisible polyfill causes an extra render when focus is gained/lost.

expect(renderItem1Spy.callCount).to.equal(2); // '1' rerenders as it loses highlight
expect(renderItem2Spy.callCount).to.equal(2); // '2' rerenders as it receives highlight
expect(renderItem1Spy.callCount).to.equal(4); // '1' rerenders as it loses highlight
expect(renderItem2Spy.callCount).to.equal(4); // '2' rerenders as it receives highlight

// neither the highlighted nor the selected state of these options changed,
// so they don't need to rerender:
Expand Down
16 changes: 11 additions & 5 deletions packages/mui-base/src/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,12 @@ describe('<Select />', () => {
expect(selectButton).to.have.text('1, 2');
});

it('perf: does not rerender options unnecessarily', async () => {
it('perf: does not rerender options unnecessarily', async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// JSDOM doesn't support :focus-visible
this.skip();
}

const renderOption1Spy = spy();
const renderOption2Spy = spy();
const renderOption3Spy = spy();
Expand Down Expand Up @@ -1325,14 +1330,15 @@ describe('<Select />', () => {
});

// React renders twice in strict mode, so we expect twice the number of spy calls
expect(renderOption1Spy.callCount).to.equal(2); // '1' as focusVisible becomes true

await userEvent.keyboard('{ArrowDown}'); // highlights '2'
expect(renderOption1Spy.callCount).to.equal(2); // '1' rerenders as it loses highlight
expect(renderOption2Spy.callCount).to.equal(2); // '2' rerenders as it receives highlight
expect(renderOption1Spy.callCount).to.equal(6); // '1' rerenders as it loses highlight
expect(renderOption2Spy.callCount).to.equal(4); // '2' rerenders as it receives highlight

await userEvent.keyboard('{Enter}'); // selects '2'
expect(renderOption1Spy.callCount).to.equal(2);
expect(renderOption2Spy.callCount).to.equal(4);
expect(renderOption1Spy.callCount).to.equal(6);
expect(renderOption2Spy.callCount).to.equal(8);

// neither the highlighted nor the selected state of these options changed,
// so they don't need to rerender:
Expand Down

0 comments on commit 16dddbb

Please sign in to comment.