Skip to content

Commit 540ee8a

Browse files
committed
mocks
1 parent aebda32 commit 540ee8a

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

app/scripts/lib/snap-keyring/keyring-snaps-permissions.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
keyringSnapPermissionsBuilder,
99
} from './keyring-snaps-permissions';
1010

11+
// Run these tests as if we were in a Flask build
12+
jest.mock('../../../../shared/lib/build-types', () => ({
13+
...jest.requireActual('../../../../shared/lib/build-types'),
14+
isFlask: jest.fn().mockReturnValue(true),
15+
}));
16+
1117
const PORTFOLIO_ORIGINS: string[] = [
1218
'https://app.metamask.io',
1319
'https://dev.app.metamask.io',

app/scripts/lib/snap-keyring/utils/isBlockedUrl.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { Messenger } from '@metamask/messenger';
88
import { getRootMessenger } from '../../messenger';
99
import { isBlockedUrl } from './isBlockedUrl';
1010

11+
// Run these tests as if we were in a Flask build
12+
jest.mock('../../../../../shared/lib/build-types', () => ({
13+
...jest.requireActual('../../../../../shared/lib/build-types'),
14+
isFlask: jest.fn().mockReturnValue(true),
15+
}));
16+
1117
describe('isBlockedUrl', () => {
1218
const messenger = getRootMessenger<
1319
PhishingControllerActions,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import { mockNetworkState } from '../../../test/stub/networks';
2929
import { FirstTimeFlowType } from '../../../shared/constants/onboarding';
3030
import OnboardingFlow from './onboarding-flow';
3131

32+
// Run these tests as if we were in a Flask build
33+
jest.mock('../../../../shared/lib/build-types', () => ({
34+
...jest.requireActual('../../../../shared/lib/build-types'),
35+
isFlask: jest.fn().mockReturnValue(true),
36+
}));
37+
3238
const mockUseNavigate = jest.fn();
3339

3440
jest.mock('react-router-dom', () => ({

ui/pages/settings/experimental-tab/experimental-tab.test.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ import configureStore from '../../../store/store';
55
import mockState from '../../../../test/data/mock-state.json';
66
import { LegacyMetaMetricsProvider } from '../../../contexts/metametrics';
77
import * as storeActions from '../../../store/actions';
8+
import { isFlask } from '../../../../shared/lib/build-types';
89
import ExperimentalTab from './experimental-tab';
910

11+
// Allow each test to set whether it's Flask or not
12+
jest.mock('../../../../shared/lib/build-types', () => ({
13+
...jest.requireActual('../../../../shared/lib/build-types'),
14+
isFlask: jest.fn(),
15+
}));
16+
17+
const mockIsFlask = jest.mocked(isFlask);
18+
1019
jest.mock('../../../store/actions', () => ({
1120
...jest.requireActual('../../../store/actions'),
1221
setAddSnapAccountEnabled: jest.fn().mockReturnValue(async () => undefined),
@@ -29,28 +38,30 @@ const render = (overrideMetaMaskState = {}) => {
2938

3039
describe('ExperimentalTab', () => {
3140
it('renders ExperimentalTab component without error', () => {
41+
mockIsFlask.mockReturnValue(false);
3242
expect(() => {
3343
render();
3444
}).not.toThrow();
3545
});
3646

3747
it('renders one toggle option when build type is main', () => {
38-
process.env.METAMASK_BUILD_TYPE = 'main';
48+
mockIsFlask.mockReturnValue(false);
3949
const { getAllByRole } = render();
4050
const toggle = getAllByRole('checkbox');
4151

4252
expect(toggle).toHaveLength(1);
4353
});
4454

4555
it('renders two toggle options when build type is flask', () => {
46-
process.env.METAMASK_BUILD_TYPE = 'flask';
56+
mockIsFlask.mockReturnValue(true);
4757
const { getAllByRole } = render();
4858
const toggle = getAllByRole('checkbox');
4959

5060
expect(toggle).toHaveLength(2);
5161
});
5262

5363
it('enables add account snap', async () => {
64+
mockIsFlask.mockReturnValue(true);
5465
const { getByTestId } = render();
5566

5667
const toggle = getByTestId('add-account-snap-toggle-button');

0 commit comments

Comments
 (0)