Skip to content

Commit 188c06c

Browse files
committed
solving warnings
1 parent 1bd2d3d commit 188c06c

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

test/jest/console-baseline-unit.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,9 +3125,6 @@
31253125
},
31263126
"ui/pages/onboarding-flow/onboarding-flow.test.tsx": {
31273127
"MetaMask: Background connection not initialized": 13,
3128-
"React: State updates on unmounted components": 1,
3129-
"error: Error: Actions must be plain": 1,
3130-
"error: Warning: React does not recognize": 1,
31313128
"warn: No routes matched location \"/\"": 1,
31323129
"warn: ⚠️ React Router Future Flag": 2
31333130
},

ui/pages/onboarding-flow/onboarding-flow.test.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { act, fireEvent, waitFor } from '@testing-library/react';
1+
import { fireEvent, waitFor } from '@testing-library/react';
22
import React from 'react';
33
import configureMockStore from 'redux-mock-store';
44
import thunk from 'redux-thunk';
@@ -27,14 +27,20 @@ import {
2727
} from '../../store/actions';
2828
import { mockNetworkState } from '../../../test/stub/networks';
2929
import { FirstTimeFlowType } from '../../../shared/constants/onboarding';
30-
import { isFlask } from '../../../shared/lib/build-types';
3130
import OnboardingFlow from './onboarding-flow';
3231

33-
jest.mock('../../../shared/lib/build-types', () => ({
34-
...jest.requireActual('../../../shared/lib/build-types'),
35-
isFlask: jest.fn().mockReturnValue(true),
32+
// Mock mmLazy to return a synchronous component instead of React.lazy.
33+
// React 17's lazy resolution fires a state update after test cleanup unmounts
34+
// the tree, producing a spurious "state update on unmounted component" warning.
35+
//
36+
// NOTE: This mock hardcodes the ExperimentalArea import. If a second mmLazy
37+
// call is added to onboarding-flow.tsx, this mock must be updated to dispatch
38+
// on the importFn (or replaced with a generic solution).
39+
jest.mock('../../helpers/utils/mm-lazy', () => ({
40+
mmLazy: () =>
41+
jest.requireActual('../../components/app/flask/experimental-area/index.js')
42+
.default,
3643
}));
37-
const mockIsFlask = jest.mocked(isFlask);
3844

3945
const mockUseNavigate = jest.fn();
4046

@@ -360,23 +366,19 @@ describe('Onboarding Flow', () => {
360366
expect(onboardingMetametrics).toBeInTheDocument();
361367
});
362368

363-
it('should render onboarding experimental screen', async () => {
364-
// Run this test as if we were in a Flask build
365-
mockIsFlask.mockReturnValue(true);
369+
it('should render onboarding experimental screen', () => {
370+
// Enable Flask mode for this test only
371+
process.env.METAMASK_BUILD_TYPE = 'flask';
366372

367373
const { queryByTestId } = renderWithProvider(
368374
<OnboardingFlowWithRouteContext />,
369375
store,
370376
ONBOARDING_EXPERIMENTAL_AREA,
371377
);
372378

373-
// React.lazy needs microtasks to flush for the dynamic import to resolve.
374-
await act(async () => {
375-
await new Promise((resolve) => setTimeout(resolve, 0));
376-
});
379+
expect(queryByTestId('experimental-area')).toBeInTheDocument();
377380

378-
await waitFor(() => {
379-
expect(queryByTestId('experimental-area')).toBeInTheDocument();
380-
});
381+
// Restore build type
382+
process.env.METAMASK_BUILD_TYPE = 'main';
381383
});
382384
});

ui/pages/onboarding-flow/onboarding-flow.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ export default function OnboardingFlow() {
341341
: 'var(--color-background-muted)',
342342
}}
343343
>
344-
<Routes>
344+
<Suspense fallback={null}>
345+
<Routes>
345346
<Route
346347
path={toRelativePath(ONBOARDING_ACCOUNT_EXIST)}
347348
element={<AccountExist />}
@@ -420,14 +421,13 @@ export default function OnboardingFlow() {
420421
<Route
421422
path={toRelativePath(ONBOARDING_EXPERIMENTAL_AREA)}
422423
element={
423-
<Suspense fallback={null}>
424-
<ExperimentalArea redirectTo={ONBOARDING_WELCOME_ROUTE} />
425-
</Suspense>
424+
<ExperimentalArea redirectTo={ONBOARDING_WELCOME_ROUTE} />
426425
}
427426
/>
428427
)}
429428
<Route path="*" element={<OnboardingFlowSwitch />} />
430429
</Routes>
430+
</Suspense>
431431
</Box>
432432
{isLoading && <LoadingScreen />}
433433
</Box>

0 commit comments

Comments
 (0)