|
1 | | -import { act, fireEvent, waitFor } from '@testing-library/react'; |
| 1 | +import { fireEvent, waitFor } from '@testing-library/react'; |
2 | 2 | import React from 'react'; |
3 | 3 | import configureMockStore from 'redux-mock-store'; |
4 | 4 | import thunk from 'redux-thunk'; |
@@ -27,14 +27,20 @@ import { |
27 | 27 | } from '../../store/actions'; |
28 | 28 | import { mockNetworkState } from '../../../test/stub/networks'; |
29 | 29 | import { FirstTimeFlowType } from '../../../shared/constants/onboarding'; |
30 | | -import { isFlask } from '../../../shared/lib/build-types'; |
31 | 30 | import OnboardingFlow from './onboarding-flow'; |
32 | 31 |
|
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, |
36 | 43 | })); |
37 | | -const mockIsFlask = jest.mocked(isFlask); |
38 | 44 |
|
39 | 45 | const mockUseNavigate = jest.fn(); |
40 | 46 |
|
@@ -360,23 +366,19 @@ describe('Onboarding Flow', () => { |
360 | 366 | expect(onboardingMetametrics).toBeInTheDocument(); |
361 | 367 | }); |
362 | 368 |
|
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'; |
366 | 372 |
|
367 | 373 | const { queryByTestId } = renderWithProvider( |
368 | 374 | <OnboardingFlowWithRouteContext />, |
369 | 375 | store, |
370 | 376 | ONBOARDING_EXPERIMENTAL_AREA, |
371 | 377 | ); |
372 | 378 |
|
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(); |
377 | 380 |
|
378 | | - await waitFor(() => { |
379 | | - expect(queryByTestId('experimental-area')).toBeInTheDocument(); |
380 | | - }); |
| 381 | + // Restore build type |
| 382 | + process.env.METAMASK_BUILD_TYPE = 'main'; |
381 | 383 | }); |
382 | 384 | }); |
0 commit comments