Skip to content

Commit

Permalink
Refactor useCurrentColorScheme test
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Dec 6, 2024
1 parent 0ebf220 commit 9348865
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions packages/mui-system/src/cssVars/useCurrentColorScheme.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { createRenderer, fireEvent, act, screen, reactMajor } from '@mui/internal-test-utils';
import { createRenderer, fireEvent, act, screen } from '@mui/internal-test-utils';
import {
DEFAULT_MODE_STORAGE_KEY,
DEFAULT_COLOR_SCHEME_STORAGE_KEY,
Expand Down Expand Up @@ -85,26 +85,23 @@ describe('useCurrentColorScheme', () => {
});

it('trigger a re-render for a multi color schemes', () => {
let effectRunCount = 0;
function Data() {
const { mode } = useCurrentColorScheme({
supportedColorSchemes: ['light', 'dark'],
defaultLightColorScheme: 'light',
defaultDarkColorScheme: 'dark',
});
const count = React.useRef(0);
React.useEffect(() => {
count.current += 1;
effectRunCount += 1;
});
return (
<div>
{mode}:{count.current}
</div>
);
return <div>{mode}</div>;
}
const expectedCount = reactMajor >= 19 ? 1 : 2;

const { container } = render(<Data />);

expect(container.firstChild.textContent).to.equal(`light:${expectedCount}`);
expect(container.firstChild.textContent).to.equal('light');
expect(effectRunCount).to.equal(2);
});

it('[noSsr] does not trigger a re-render', () => {
Expand Down

0 comments on commit 9348865

Please sign in to comment.