Skip to content

Commit

Permalink
add failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 4, 2023
1 parent 1dc2782 commit 8ebc301
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions packages/mui-material/src/useMediaQuery/useMediaQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('useMediaQuery', () => {
expect(getRenderCountRef.current()).to.equal(1);
});

it('should render twice if the default value does not match the expectation', () => {
it('render API: should render once if the default value does not match the expectation', () => {
const getRenderCountRef = React.createRef();
function Test() {
const matches = useMediaQuery('(min-width:2000px)', {
Expand All @@ -163,7 +163,7 @@ describe('useMediaQuery', () => {
expect(getRenderCountRef.current()).to.equal(usesUseSyncExternalStore ? 1 : 2);
});

it('should render once if the default value does not match the expectation but `noSsr` is enabled', () => {
it('render API: should render once if the default value does not match the expectation but `noSsr` is enabled', () => {
const getRenderCountRef = React.createRef();
function Test() {
const matches = useMediaQuery('(min-width:2000px)', {
Expand All @@ -182,6 +182,47 @@ describe('useMediaQuery', () => {
expect(screen.getByTestId('matches').textContent).to.equal('false');
expect(getRenderCountRef.current()).to.equal(1);
});

it('hydrate API: should render twice if the default value does not match the expectation', () => {
const getRenderCountRef = React.createRef();
function Test() {
const matches = useMediaQuery('(min-width:2000px)', {
defaultMatches: true,
});

return (
<RenderCounter ref={getRenderCountRef}>
<span data-testid="matches">{`${matches}`}</span>
</RenderCounter>
);
}

const { hydrate } = renderToString(<Test />);
hydrate();
expect(screen.getByTestId('matches').textContent).to.equal('false');
expect(getRenderCountRef.current()).to.equal(2);
});

it('hydrate API: should render once if the default value does not match the expectation but `noSsr` is enabled', () => {
const getRenderCountRef = React.createRef();
function Test() {
const matches = useMediaQuery('(min-width:2000px)', {
defaultMatches: true,
noSsr: true,
});

return (
<RenderCounter ref={getRenderCountRef}>
<span data-testid="matches">{`${matches}`}</span>
</RenderCounter>
);
}

const { hydrate } = renderToString(<Test />);
hydrate();
expect(screen.getByTestId('matches').textContent).to.equal('false');
expect(getRenderCountRef.current()).to.equal(1);
});
});

it('should try to reconcile each time', () => {
Expand Down

0 comments on commit 8ebc301

Please sign in to comment.