diff options
author | Revanshu Paliwal <revanshu.paliwal@sonarsource.com> | 2022-10-18 17:23:24 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-10-20 20:03:03 +0000 |
commit | d75de0570fc03c35f71569021454aa1d1f326d62 (patch) | |
tree | 6223f8f6d2cfd00d437e73c18ff520ccf527e87e /server/sonar-web/src/main/js | |
parent | f4ce3356ce0704278833ec8d7cddc9d0c4f4bcbb (diff) | |
download | sonarqube-d75de0570fc03c35f71569021454aa1d1f326d62.tar.gz sonarqube-d75de0570fc03c35f71569021454aa1d1f326d62.zip |
[NO JIRA] Upgrade @swc/core and @swc/jest
Diffstat (limited to 'server/sonar-web/src/main/js')
-rw-r--r-- | server/sonar-web/src/main/js/apps/projects/components/__tests__/AllProjects-test.tsx | 9 | ||||
-rw-r--r-- | server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx | 59 |
2 files changed, 38 insertions, 30 deletions
diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/AllProjects-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/AllProjects-test.tsx index f574600c073..4d2e70ff7cc 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/AllProjects-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/AllProjects-test.tsx @@ -51,11 +51,10 @@ jest.mock( } ); -jest.mock('../../utils', () => { - const utils = jest.requireActual('../../utils'); - utils.fetchProjects = jest.fn(() => Promise.resolve({ projects: [] })); - return utils; -}); +jest.mock('../../utils', () => ({ + ...jest.requireActual('../../utils'), + fetchProjects: jest.fn(() => Promise.resolve({ projects: [] })) +})); jest.mock('../../../../helpers/storage', () => ({ get: jest.fn(() => null), diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx index 3e10ea0b3bd..fee7bd3c13e 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx @@ -19,8 +19,7 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import * as apiQP from '../../../../api/quality-profiles'; -import * as apiRules from '../../../../api/rules'; +import { getQualityProfile } from '../../../../api/quality-profiles'; import { mockQualityProfile } from '../../../../helpers/testMocks'; import { waitAndUpdate } from '../../../../helpers/testUtils'; import ProfileRules from '../ProfileRules'; @@ -65,17 +64,29 @@ const apiResponseActive = { ] }; -// Mock api some api functions -(apiRules as any).searchRules = (data: any) => - Promise.resolve(data.activation === 'true' ? apiResponseActive : apiResponseAll); -(apiQP as any).getQualityProfile = () => - Promise.resolve({ - compareToSonarWay: { - profile: 'sonarway', - profileName: 'Sonar way', - missingRuleCount: 4 - } - }); +jest.mock('../../../../api/rules', () => ({ + ...jest.requireActual('../../../../api/rules'), + searchRules: jest + .fn() + .mockImplementation((data: any) => + Promise.resolve(data.activation === 'true' ? apiResponseActive : apiResponseAll) + ) +})); + +jest.mock('../../../../api/quality-profiles', () => ({ + ...jest.requireActual('../../../../api/quality-profiles'), + getQualityProfile: jest.fn().mockImplementation(() => + Promise.resolve({ + compareToSonarWay: { + profile: 'sonarway', + profileName: 'Sonar way', + missingRuleCount: 4 + } + }) + ) +})); + +beforeEach(jest.clearAllMocks); it('should render the quality profiles rules with sonarway comparison', async () => { const wrapper = shallow(<ProfileRules profile={PROFILE} />); @@ -112,26 +123,24 @@ it('should not show a button to activate more rules on built in profiles', () => }); it('should not show sonarway comparison for built in profiles', async () => { - (apiQP as any).getQualityProfile = jest.fn(() => Promise.resolve()); + (getQualityProfile as jest.Mock).mockReturnValueOnce({}); const wrapper = shallow(<ProfileRules profile={{ ...PROFILE, isBuiltIn: true }} />); await new Promise(setImmediate); wrapper.update(); - expect(apiQP.getQualityProfile).toHaveBeenCalledTimes(0); + expect(getQualityProfile).toHaveBeenCalledTimes(0); expect(wrapper.find('ProfileRulesSonarWayComparison')).toHaveLength(0); }); it('should not show sonarway comparison if there is no missing rules', async () => { - (apiQP as any).getQualityProfile = jest.fn(() => - Promise.resolve({ - compareToSonarWay: { - profile: 'sonarway', - profileName: 'Sonar way', - missingRuleCount: 0 - } - }) - ); + (getQualityProfile as jest.Mock).mockReturnValueOnce({ + compareToSonarWay: { + profile: 'sonarway', + profileName: 'Sonar way', + missingRuleCount: 0 + } + }); const wrapper = shallow(<ProfileRules profile={PROFILE} />); await waitAndUpdate(wrapper); - expect(apiQP.getQualityProfile).toHaveBeenCalledTimes(1); + expect(getQualityProfile).toHaveBeenCalledTimes(1); expect(wrapper.find('ProfileRulesSonarWayComparison')).toHaveLength(0); }); |