From 934886594c2a6b25ffc8d8125b69cc647e86eac1 Mon Sep 17 00:00:00 2001 From: DiegoAndai Date: Fri, 6 Dec 2024 10:09:53 -0300 Subject: [PATCH] Refactor useCurrentColorScheme test --- .../src/cssVars/useCurrentColorScheme.test.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/mui-system/src/cssVars/useCurrentColorScheme.test.js b/packages/mui-system/src/cssVars/useCurrentColorScheme.test.js index 32ba4e9b67029a..fd508886202766 100644 --- a/packages/mui-system/src/cssVars/useCurrentColorScheme.test.js +++ b/packages/mui-system/src/cssVars/useCurrentColorScheme.test.js @@ -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, @@ -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 ( -
- {mode}:{count.current} -
- ); + return
{mode}
; } - const expectedCount = reactMajor >= 19 ? 1 : 2; + const { container } = render(); - 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', () => {