diff options
267 files changed, 956 insertions, 890 deletions
diff --git a/server/sonar-docs/.eslintrc b/server/sonar-docs/.eslintrc index f60b942b885..d1c54fe54d4 100644 --- a/server/sonar-docs/.eslintrc +++ b/server/sonar-docs/.eslintrc @@ -3,9 +3,7 @@ "rules": { // some dependencies are implictly provided by gatsby - "import/no-extraneous-dependencies": "off" - }, - "parserOptions": { - "warnOnUnsupportedTypeScriptVersion": false + "import/no-extraneous-dependencies": "off", + "testing-library/render-result-naming-convention": "warn" } } diff --git a/server/sonar-docs/src/components/HeaderListProvider.tsx b/server/sonar-docs/src/components/HeaderListProvider.tsx index 05cfc420fad..0a22c4744ce 100644 --- a/server/sonar-docs/src/components/HeaderListProvider.tsx +++ b/server/sonar-docs/src/components/HeaderListProvider.tsx @@ -36,13 +36,13 @@ export default class HeaderListProvider extends React.Component<Props, State> { headers: PropTypes.object }; - getChildContext = () => { + getChildContext() { return { headers: { setHeaders: this.setHeaders } }; - }; + } setHeaders = (headers: MarkdownHeading[]) => { this.setState({ headers }); diff --git a/server/sonar-docs/src/components/__tests__/Search-test.tsx b/server/sonar-docs/src/components/__tests__/Search-test.tsx index b1a8a4bdd04..989e494e14e 100644 --- a/server/sonar-docs/src/components/__tests__/Search-test.tsx +++ b/server/sonar-docs/src/components/__tests__/Search-test.tsx @@ -118,7 +118,9 @@ it('should search', () => { ); wrapper.instance().handleChange({ currentTarget: { value: 'simply text+:' } } as any); expect(wrapper).toMatchSnapshot(); - expect(lunr).toBeCalled(); + expect(lunr).toHaveBeenCalled(); expect(wrapper.instance().index).toBeDefined(); - expect((wrapper.instance().index as any).search).toBeCalledWith('simply~1 simply* text~1 text*'); + expect((wrapper.instance().index as any).search).toHaveBeenCalledWith( + 'simply~1 simply* text~1 text*' + ); }); diff --git a/server/sonar-web/.eslintrc b/server/sonar-web/.eslintrc index 9ba34dede11..61e982205a5 100644 --- a/server/sonar-web/.eslintrc +++ b/server/sonar-web/.eslintrc @@ -3,26 +3,7 @@ "rules": { "camelcase": "off", "promise/no-return-wrap": "warn", - "react/jsx-curly-brace-presence": "warn" - }, - "parserOptions": { - "warnOnUnsupportedTypeScriptVersion": false - }, - "plugins": ["testing-library"], - "overrides": [ - { - "files": [ - "**/__tests__/**/*-it.{ts,tsx}" - ], - "extends": [ - "plugin:testing-library/react" - ], - "rules": { - "testing-library/await-async-query": "error", - "testing-library/no-await-sync-query": "error", - "testing-library/no-debugging-utils": "error", - "testing-library/no-dom-import": "error" - } - } - ] + "react/jsx-curly-brace-presence": "warn", + "testing-library/render-result-naming-convention": "warn" + } } diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx index 9e571d079a1..8f637b05dc4 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx @@ -121,7 +121,7 @@ it('loads the project binding, if any', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getProjectAlmBinding).toBeCalled(); + expect(getProjectAlmBinding).toHaveBeenCalled(); expect(wrapper.state().projectBinding).toBeUndefined(); wrapper.setProps({ location: mockLocation({ query: { id: 'bar' } }) }); @@ -132,10 +132,13 @@ it('loads the project binding, if any', async () => { it("doesn't load branches portfolio", async () => { const wrapper = shallowRender({ location: mockLocation({ query: { id: 'portfolioKey' } }) }); await waitAndUpdate(wrapper); - expect(getBranches).not.toBeCalled(); - expect(getPullRequests).not.toBeCalled(); - expect(getComponentData).toBeCalledWith({ component: 'portfolioKey', branch: undefined }); - expect(getComponentNavigation).toBeCalledWith({ component: 'portfolioKey', branch: undefined }); + expect(getBranches).not.toHaveBeenCalled(); + expect(getPullRequests).not.toHaveBeenCalled(); + expect(getComponentData).toHaveBeenCalledWith({ component: 'portfolioKey', branch: undefined }); + expect(getComponentNavigation).toHaveBeenCalledWith({ + component: 'portfolioKey', + branch: undefined + }); }); it('updates branches on change', async () => { @@ -153,10 +156,10 @@ it('updates branches on change', async () => { loading: false }); wrapper.instance().handleBranchesChange(); - expect(getBranches).toBeCalledWith('projectKey'); - expect(getPullRequests).toBeCalledWith('projectKey'); + expect(getBranches).toHaveBeenCalledWith('projectKey'); + expect(getPullRequests).toHaveBeenCalledWith('projectKey'); await waitAndUpdate(wrapper); - expect(updateBranchStatus).toBeCalledTimes(2); + expect(updateBranchStatus).toHaveBeenCalledTimes(2); }); it('fetches status', async () => { @@ -166,7 +169,7 @@ it('fetches status', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getTasksForComponent).toBeCalledWith('portfolioKey'); + expect(getTasksForComponent).toHaveBeenCalledWith('portfolioKey'); }); it('filters correctly the pending tasks for a main branch', () => { @@ -338,7 +341,7 @@ it('should redirect if the user has no access', async () => { ); const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(handleRequiredAuthorization).toBeCalled(); + expect(handleRequiredAuthorization).toHaveBeenCalled(); }); it('should redirect if the component is a portfolio', async () => { @@ -354,7 +357,7 @@ it('should redirect if the component is a portfolio', async () => { router: mockRouter({ replace }) }); await waitAndUpdate(wrapper); - expect(replace).toBeCalledWith({ pathname: '/portfolio', search: `?id=${componentKey}` }); + expect(replace).toHaveBeenCalledWith({ pathname: '/portfolio', search: `?id=${componentKey}` }); }); it('should display display the unavailable page if the component needs issue sync', async () => { @@ -382,7 +385,7 @@ it('should correctly reload last task warnings if anything got dismissed', async (getAnalysisStatus as jest.Mock).mockClear(); wrapper.instance().handleWarningDismiss(); - expect(getAnalysisStatus).toBeCalledTimes(1); + expect(getAnalysisStatus).toHaveBeenCalledTimes(1); }); describe('should correctly validate the project binding depending on the context', () => { @@ -407,7 +410,7 @@ describe('should correctly validate the project binding depending on the context await waitAndUpdate(wrapper); expect(wrapper.state().projectBindingErrors).toBe(projectBindingErrors); - expect(validateProjectAlmBinding).toBeCalledTimes(n); + expect(validateProjectAlmBinding).toHaveBeenCalledTimes(n); }); }); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx index 5e7d3dfde6c..e94c228a5e0 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/PageTracker-test.tsx @@ -59,7 +59,7 @@ it('should work for WebAnalytics plugin', () => { expect(wrapper).toMatchSnapshot(); expect(wrapper.find('Helmet').prop('onChangeClientState')).toBe(wrapper.instance().trackPage); - expect(installScript).toBeCalledWith(webAnalyticsJsPath, 'head'); + expect(installScript).toHaveBeenCalledWith(webAnalyticsJsPath, 'head'); (getWebAnalyticsPageHandlerFromCache as jest.Mock).mockReturnValueOnce(pageChange); wrapper.instance().trackPage(); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/PluginRiskConsent-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/PluginRiskConsent-test.tsx index dca6ce7d236..49decfbdbbb 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/PluginRiskConsent-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/PluginRiskConsent-test.tsx @@ -50,7 +50,7 @@ it('should redirect non-admin users', () => { router: mockRouter({ replace }) }); expect(wrapper.type()).toBeNull(); - expect(replace).toBeCalled(); + expect(replace).toHaveBeenCalled(); }); it('should handle acknowledgement and redirect', async () => { @@ -63,7 +63,7 @@ it('should handle acknowledgement and redirect', async () => { await new Promise(setImmediate); - expect(setSimpleSettingValue).toBeCalled(); + expect(setSimpleSettingValue).toHaveBeenCalled(); }); function shallowRender(props: Partial<PluginRiskConsentProps> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx index 445de3ac747..e15c12f9d9a 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ProjectAdminContainer-test.tsx @@ -33,7 +33,7 @@ it('should render correctly', () => { it('should redirect for authorization if needed', () => { mountRender({ component: mockComponent({ configuration: { showSettings: false } }) }); - expect(handleRequiredAuthorization).toBeCalled(); + expect(handleRequiredAuthorization).toHaveBeenCalled(); }); function mountRender(props: Partial<ProjectAdminContainer['props']> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/__tests__/RecentHistory-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/RecentHistory-test.tsx index 29968901c95..6afd157eab0 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/RecentHistory-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/RecentHistory-test.tsx @@ -36,38 +36,38 @@ it('should get existing history', () => { const history = [{ key: 'foo', name: 'Foo', icon: 'TRK' }]; (get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); expect(RecentHistory.get()).toEqual(history); - expect(get).toBeCalledWith('sonar_recent_history'); + expect(get).toHaveBeenCalledWith('sonar_recent_history'); }); it('should get empty history', () => { (get as jest.Mock).mockReturnValueOnce(null); expect(RecentHistory.get()).toEqual([]); - expect(get).toBeCalledWith('sonar_recent_history'); + expect(get).toHaveBeenCalledWith('sonar_recent_history'); }); it('should return [] and clear history in case of failure', () => { (get as jest.Mock).mockReturnValueOnce('not a json'); expect(RecentHistory.get()).toEqual([]); - expect(get).toBeCalledWith('sonar_recent_history'); - expect(remove).toBeCalledWith('sonar_recent_history'); + expect(get).toHaveBeenCalledWith('sonar_recent_history'); + expect(remove).toHaveBeenCalledWith('sonar_recent_history'); }); it('should save history', () => { const history = [{ key: 'foo', name: 'Foo', icon: 'TRK' }]; RecentHistory.set(history); - expect(save).toBeCalledWith('sonar_recent_history', JSON.stringify(history)); + expect(save).toHaveBeenCalledWith('sonar_recent_history', JSON.stringify(history)); }); it('should clear history', () => { RecentHistory.clear(); - expect(remove).toBeCalledWith('sonar_recent_history'); + expect(remove).toHaveBeenCalledWith('sonar_recent_history'); }); it('should add item to history', () => { const history = [{ key: 'foo', name: 'Foo', icon: 'TRK' }]; (get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); RecentHistory.add('bar', 'Bar', 'VW'); - expect(save).toBeCalledWith( + expect(save).toHaveBeenCalledWith( 'sonar_recent_history', JSON.stringify([{ key: 'bar', name: 'Bar', icon: 'VW' }, ...history]) ); @@ -80,7 +80,7 @@ it('should keep 10 items maximum', () => { } (get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); RecentHistory.add('bar', 'Bar', 'VW'); - expect(save).toBeCalledWith( + expect(save).toHaveBeenCalledWith( 'sonar_recent_history', JSON.stringify([{ key: 'bar', name: 'Bar', icon: 'VW' }, ...history.slice(0, 9)]) ); @@ -93,7 +93,7 @@ it('should remove component from history', () => { } (get as jest.Mock).mockReturnValueOnce(JSON.stringify(history)); RecentHistory.remove('key-5'); - expect(save).toBeCalledWith( + expect(save).toHaveBeenCalledWith( 'sonar_recent_history', JSON.stringify([...history.slice(0, 5), ...history.slice(6)]) ); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/SonarLintConnection-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/SonarLintConnection-test.tsx index a023d6d4896..2137385bb1b 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/SonarLintConnection-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/SonarLintConnection-test.tsx @@ -120,7 +120,7 @@ it('should handle connection errors', async () => { it('should require authentication if user is not logged in', () => { renderSonarLintConnection({ currentUser: mockCurrentUser() }); - expect(handleRequiredAuthentication).toBeCalled(); + expect(handleRequiredAuthentication).toHaveBeenCalled(); }); it('should redirect if port is not provided', () => { diff --git a/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx index e958ef8ae47..3dda2518c26 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { fireEvent, screen } from '@testing-library/dom'; +import { fireEvent, screen } from '@testing-library/react'; import * as React from 'react'; import { getValues } from '../../../api/settings'; import { renderComponent } from '../../../helpers/testReactTestingUtils'; diff --git a/server/sonar-web/src/main/js/app/components/branch-status/__tests__/BranchStatusContextProvider-test.tsx b/server/sonar-web/src/main/js/app/components/branch-status/__tests__/BranchStatusContextProvider-test.tsx index 9b9e26dfea3..8dc38012f1d 100644 --- a/server/sonar-web/src/main/js/app/components/branch-status/__tests__/BranchStatusContextProvider-test.tsx +++ b/server/sonar-web/src/main/js/app/components/branch-status/__tests__/BranchStatusContextProvider-test.tsx @@ -43,7 +43,7 @@ describe('fetchBranchStatus', () => { wrapper.instance().fetchBranchStatus(mockBranch({ name: branchName }), projectKey); - expect(getQualityGateProjectStatus).toBeCalledWith({ projectKey, branch: branchName }); + expect(getQualityGateProjectStatus).toHaveBeenCalledWith({ projectKey, branch: branchName }); await waitAndUpdate(wrapper); diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx index 7f2166da2be..ab75057a69f 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/Extension-test.tsx @@ -48,9 +48,9 @@ it('should render React extensions correctly', async () => { const wrapper = shallowRender(); expect(wrapper).toMatchSnapshot(); - expect(getExtensionStart).toBeCalledWith('foo'); + expect(getExtensionStart).toHaveBeenCalledWith('foo'); await waitAndUpdate(wrapper); - expect(start).toBeCalled(); + expect(start).toHaveBeenCalled(); expect(wrapper).toMatchSnapshot(); }); @@ -63,11 +63,11 @@ it('should handle Function extensions correctly', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(start).toBeCalled(); + expect(start).toHaveBeenCalled(); wrapper.setProps({ extension: { key: 'bar', name: 'Bar' } }); await waitAndUpdate(wrapper); - expect(stop).toBeCalled(); + expect(stop).toHaveBeenCalled(); }); it('should unmount an extension before starting a new one', async () => { diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx index eea7470d3c2..685a32e0897 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectAdminPageExtension-test.tsx @@ -40,7 +40,7 @@ it('should render correctly when the extension is found', () => { }), { pluginKey: 'pluginId', extensionKey: 'extensionId' } ); - expect(getExtensionStart).toBeCalledWith('pluginId/extensionId'); + expect(getExtensionStart).toHaveBeenCalledWith('pluginId/extensionId'); }); it('should render correctly when the extension is not found', () => { diff --git a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx index 0e8517dab9d..43120a4ccb1 100644 --- a/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx +++ b/server/sonar-web/src/main/js/app/components/extensions/__tests__/ProjectPageExtension-test.tsx @@ -36,7 +36,7 @@ jest.mock('../../../../helpers/extensions', () => ({ it('should not render when no component is passed', () => { renderProjectPageExtension(); expect(screen.queryByText('page_not_found')).not.toBeInTheDocument(); - expect(getExtensionStart).not.toBeCalledWith('pluginId/extensionId'); + expect(getExtensionStart).not.toHaveBeenCalledWith('pluginId/extensionId'); }); it('should render correctly when the extension is found', () => { @@ -44,7 +44,7 @@ it('should render correctly when the extension is found', () => { mockComponent({ extensions: [{ key: 'pluginId/extensionId', name: 'name' }] }), { params: { pluginKey: 'pluginId', extensionKey: 'extensionId' } } ); - expect(getExtensionStart).toBeCalledWith('pluginId/extensionId'); + expect(getExtensionStart).toHaveBeenCalledWith('pluginId/extensionId'); }); it('should render correctly when the extension is not found', () => { diff --git a/server/sonar-web/src/main/js/app/components/languages/__tests__/LanguagesContextProvider-test.tsx b/server/sonar-web/src/main/js/app/components/languages/__tests__/LanguagesContextProvider-test.tsx index a25d44bda93..aab258a5dc0 100644 --- a/server/sonar-web/src/main/js/app/components/languages/__tests__/LanguagesContextProvider-test.tsx +++ b/server/sonar-web/src/main/js/app/components/languages/__tests__/LanguagesContextProvider-test.tsx @@ -32,7 +32,7 @@ it('should call language', async () => { (getLanguages as jest.Mock).mockResolvedValueOnce(languages); const wrapper = shallowRender(); - expect(getLanguages).toBeCalled(); + expect(getLanguages).toHaveBeenCalled(); await waitAndUpdate(wrapper); expect(wrapper.state()).toEqual({ languages }); }); diff --git a/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx b/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx index be30d4fa999..169d7765aa3 100644 --- a/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx +++ b/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx @@ -34,7 +34,7 @@ it('should call metric', async () => { (getAllMetrics as jest.Mock).mockResolvedValueOnce(Object.values(metrics)); const wrapper = shallowRender(); - expect(getAllMetrics).toBeCalled(); + expect(getAllMetrics).toHaveBeenCalled(); await waitAndUpdate(wrapper); expect(wrapper.state()).toEqual({ metrics }); }); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx index f96144b1b32..0d7ee55a610 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx @@ -288,28 +288,42 @@ it.each([ expect(wrapper.find(Alert).props().variant).toBe(alertVariant); // Formatted message values prop. + // eslint-disable-next-line jest/no-conditional-in-test if (/_X/.test(expectedMessage)) { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.type).toBe(`background_task.type.${currentTask.type}`); } else { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.type).toBeUndefined(); } + // eslint-disable-next-line jest/no-conditional-in-test if (currentTask.branch) { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.branch).toBe(currentTask.branch); } else { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.branch).toBeUndefined(); } + // eslint-disable-next-line jest/no-conditional-in-test if (showBackgroundTasks) { + // eslint-disable-next-line jest/no-conditional-in-test if (onBackgroudTaskPage) { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.url).toBeUndefined(); + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.stacktrace).toBe('background_tasks.show_stacktrace'); } else { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.url).toBeDefined(); + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.stacktrace).toBeUndefined(); } } else { + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.url).toBeUndefined(); + // eslint-disable-next-line jest/no-conditional-expect expect(messageProps.values?.stacktrace).toBeUndefined(); } } diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/DrawerLink-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/DrawerLink-test.tsx index 0c4c5dff688..4fd26a4e205 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/DrawerLink-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/DrawerLink-test.tsx @@ -32,7 +32,7 @@ it('should call onPageChange when clicked', () => { wrapper.simulate('click'); - expect(onPageChange).toBeCalledWith(to); + expect(onPageChange).toHaveBeenCalledWith(to); }); function shallowRender(props: Partial<DrawerLinkProps<string>> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawer-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawer-test.tsx index 742ea4fe146..f0dde39d479 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawer-test.tsx @@ -32,7 +32,7 @@ it('should call onClose when button is clicked', () => { const wrapper = shallowRender({ onClose, displayed: true }); wrapper.find(ClearButton).simulate('click'); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); function shallowRender(props: Partial<InfoDrawerProps> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawerPage-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawerPage-test.tsx index 9584c8862a5..b90a60bcf7d 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawerPage-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/__tests__/InfoDrawerPage-test.tsx @@ -32,7 +32,7 @@ it('should call onPageChange when clicked', () => { wrapper.find('.back-button').simulate('click'); - expect(onPageChange).toBeCalledTimes(1); + expect(onPageChange).toHaveBeenCalledTimes(1); }); function shallowRender(props: Partial<InfoDrawerPageProps> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaQualityProfiles-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaQualityProfiles-test.tsx index 6715757d7ac..b0723fa199e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaQualityProfiles-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaQualityProfiles-test.tsx @@ -40,7 +40,7 @@ it('should render correctly', async () => { expect(wrapper).toMatchSnapshot(); expect(wrapper.find('.project-info-deprecated-rules').exists()).toBe(true); expect(wrapper.find('.project-info-deleted-profile').exists()).toBe(true); - expect(searchRules).toBeCalled(); + expect(searchRules).toHaveBeenCalled(); }); function shallowRender(props: Partial<MetaQualityProfiles['props']> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTagsSelector-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTagsSelector-test.tsx index f96f150bf68..0306128976c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTagsSelector-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/projectInformation/meta/__tests__/MetaTagsSelector-test.tsx @@ -38,7 +38,7 @@ it('searches tags on mount', () => { Promise.resolve({ tags: ['foo', 'bar'] }) ); mount(<MetaTagsSelector selectedTags={[]} setProjectTags={jest.fn()} />); - expect(searchProjectTags).toBeCalledWith({ ps: 9, q: '' }); + expect(searchProjectTags).toHaveBeenCalledWith({ ps: 9, q: '' }); }); it('selects and deselects tags', () => { diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.tsx index 0beed7916cf..b93c16c239e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { screen } from '@testing-library/dom'; +import { screen } from '@testing-library/react'; import * as React from 'react'; import { mockAppState, mockCurrentUser } from '../../../../../helpers/testMocks'; import { renderComponent } from '../../../../../helpers/testReactTestingUtils'; diff --git a/server/sonar-web/src/main/js/app/components/promotion-notification/__tests__/PromotionNotification-test.tsx b/server/sonar-web/src/main/js/app/components/promotion-notification/__tests__/PromotionNotification-test.tsx index e686ef86c74..860a97fd810 100644 --- a/server/sonar-web/src/main/js/app/components/promotion-notification/__tests__/PromotionNotification-test.tsx +++ b/server/sonar-web/src/main/js/app/components/promotion-notification/__tests__/PromotionNotification-test.tsx @@ -50,9 +50,9 @@ it('should remove the toaster when click on dismiss', async () => { updateDismissedNotices }); wrapper.find('.toaster-actions ButtonLink').simulate('click'); - expect(dismissNotice).toBeCalled(); + expect(dismissNotice).toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(updateDismissedNotices).toBeCalled(); + expect(updateDismissedNotices).toHaveBeenCalled(); }); it('should remove the toaster and navigate to sonarlint when click on learn more', async () => { @@ -62,9 +62,9 @@ it('should remove the toaster and navigate to sonarlint when click on learn more updateDismissedNotices }); wrapper.find('.toaster-actions .button-primary').simulate('click'); - expect(dismissNotice).toBeCalled(); + expect(dismissNotice).toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(updateDismissedNotices).toBeCalled(); + expect(updateDismissedNotices).toHaveBeenCalled(); }); function shallowRender(props: Partial<PromotionNotificationProps> = {}) { diff --git a/server/sonar-web/src/main/js/app/components/search/__tests__/Search-test.tsx b/server/sonar-web/src/main/js/app/components/search/__tests__/Search-test.tsx index c1103428baa..cfd39892c41 100644 --- a/server/sonar-web/src/main/js/app/components/search/__tests__/Search-test.tsx +++ b/server/sonar-web/src/main/js/app/components/search/__tests__/Search-test.tsx @@ -69,7 +69,7 @@ it('opens selected project on enter', () => { }); keydown({ key: KeyboardKeys.Enter }); - expect(router.push).toBeCalledWith({ + expect(router.push).toHaveBeenCalledWith({ pathname: '/dashboard', search: queryToSearch({ id: selectedKey }) }); @@ -88,7 +88,7 @@ it('opens selected portfolio on enter', () => { }); keydown({ key: KeyboardKeys.Enter }); - expect(router.push).toBeCalledWith({ + expect(router.push).toHaveBeenCalledWith({ pathname: '/portfolio', search: queryToSearch({ id: selectedKey }) }); @@ -107,7 +107,7 @@ it('opens selected subportfolio on enter', () => { }); keydown({ key: KeyboardKeys.Enter }); - expect(router.push).toBeCalledWith({ + expect(router.push).toHaveBeenCalledWith({ pathname: '/portfolio', search: queryToSearch({ id: selectedKey }) }); diff --git a/server/sonar-web/src/main/js/app/components/search/__tests__/SearchShowMore-test.tsx b/server/sonar-web/src/main/js/app/components/search/__tests__/SearchShowMore-test.tsx index 21ff567fc28..71431b7d59c 100644 --- a/server/sonar-web/src/main/js/app/components/search/__tests__/SearchShowMore-test.tsx +++ b/server/sonar-web/src/main/js/app/components/search/__tests__/SearchShowMore-test.tsx @@ -37,14 +37,14 @@ it('should trigger showing more', () => { stopPropagation() {} } }); - expect(onMoreClick).toBeCalledWith('TRK'); + expect(onMoreClick).toHaveBeenCalledWith('TRK'); }); it('should select on mouse over', () => { const onSelect = jest.fn(); const wrapper = shallowRender({ onSelect }); wrapper.find('a').simulate('mouseenter', { currentTarget: { dataset: { qualifier: 'TRK' } } }); - expect(onSelect).toBeCalledWith('qualifier###TRK'); + expect(onSelect).toHaveBeenCalledWith('qualifier###TRK'); }); function shallowRender(props: Partial<SearchShowMore['props']> = {}) { diff --git a/server/sonar-web/src/main/js/app/utils/__tests__/NavigateWithParams-test.tsx b/server/sonar-web/src/main/js/app/utils/__tests__/NavigateWithParams-test.tsx index b4f47021d50..ab5c64abec4 100644 --- a/server/sonar-web/src/main/js/app/utils/__tests__/NavigateWithParams-test.tsx +++ b/server/sonar-web/src/main/js/app/utils/__tests__/NavigateWithParams-test.tsx @@ -32,7 +32,7 @@ it('should transform path parameters to search params', () => { renderNavigateWithParams(transformParams); - expect(transformParams).toBeCalled(); + expect(transformParams).toHaveBeenCalled(); expect(screen.getByText('/target?also=this&key=hello&subkey=test')).toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthorization-test.ts b/server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthorization-test.ts index 5fc4a3c8b3e..46d46be6202 100644 --- a/server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthorization-test.ts +++ b/server/sonar-web/src/main/js/app/utils/__tests__/handleRequiredAuthorization-test.ts @@ -47,7 +47,7 @@ afterAll(() => { it('should not render for anonymous user', () => { handleRequiredAuthorization(); - expect(replace).toBeCalledWith( + expect(replace).toHaveBeenCalledWith( '/sessions/new?return_to=%2Fpath%3Fid%3D12%23tag&authorizationError=true' ); }); diff --git a/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx b/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx index 217f18dbbbf..77336f98400 100644 --- a/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx +++ b/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx @@ -166,7 +166,7 @@ it('should handle a currentUser not logged in', () => { renderAccountApp(mockCurrentUser()); // Make sure we're redirected to the login screen - expect(replace).toBeCalledWith('/sessions/new?return_to=%2Faccount'); + expect(replace).toHaveBeenCalledWith('/sessions/new?return_to=%2Faccount'); locationMock.mockRestore(); }); @@ -241,7 +241,7 @@ describe('profile page', () => { await user.click(toggle); - expect(setKeyboardShortcutEnabled).toBeCalledWith(false); + expect(setKeyboardShortcutEnabled).toHaveBeenCalledWith(false); }); }); @@ -288,15 +288,20 @@ describe('security page', () => { const tokenTypeLabel = `users.tokens.${tokenTypeOption}`; const tokenTypeShortLabel = `users.tokens.${tokenTypeOption}.short`; + // eslint-disable-next-line jest/no-conditional-in-test if (tokenTypeOption === TokenType.Project) { await selectEvent.select(screen.getAllByRole('textbox')[1], [tokenTypeLabel]); + // eslint-disable-next-line jest/no-conditional-expect expect(generateButton).toBeDisabled(); + // eslint-disable-next-line jest/no-conditional-expect expect(screen.getAllByRole('textbox')).toHaveLength(4); await selectEvent.select(screen.getAllByRole('textbox')[2], ['Project Name 1']); - expect(generateButton).not.toBeDisabled(); + // eslint-disable-next-line jest/no-conditional-expect + expect(generateButton).toBeEnabled(); } else { await selectEvent.select(screen.getAllByRole('textbox')[1], [tokenTypeLabel]); - expect(generateButton).not.toBeDisabled(); + // eslint-disable-next-line jest/no-conditional-expect + expect(generateButton).toBeEnabled(); } await user.click(generateButton); @@ -307,10 +312,15 @@ describe('security page', () => { expect(screen.getByRole('button', { name: 'copy_to_clipboard' })).toBeInTheDocument(); const lastTokenCreated = tokenMock.getLastToken(); + // eslint-disable-next-line jest/no-conditional-in-test if (lastTokenCreated === undefined) { throw new Error("Couldn't find the latest generated token."); } - expect(screen.getByLabelText('users.new_token').textContent).toBe(lastTokenCreated.token); + // eslint-disable-next-line jest/no-conditional-in-test + expect(screen.getByLabelText('users.new_token')).toHaveTextContent( + // eslint-disable-next-line jest/no-conditional-in-test + lastTokenCreated.token ?? '' + ); expect(screen.getAllByRole('row')).toHaveLength(4); // 3 tokens + header @@ -319,7 +329,9 @@ describe('security page', () => { }); expect(await within(row).findByText(tokenTypeShortLabel)).toBeInTheDocument(); + // eslint-disable-next-line jest/no-conditional-in-test if (tokenTypeOption === TokenType.Project) { + // eslint-disable-next-line jest/no-conditional-expect expect(await within(row).findByText('Project Name 1')).toBeInTheDocument(); } @@ -520,7 +532,7 @@ describe('notifications page', () => { await user.keyboard('[ArrowDown][ArrowDown][ArrowUp][Enter]'); const addButton = screen.getByRole('button', { name: 'add_verb' }); - expect(addButton).not.toBeDisabled(); + expect(addButton).toBeEnabled(); await user.click(addButton); @@ -581,6 +593,9 @@ describe('projects page', () => { expect(within(project1).getAllByRole('link')).toHaveLength(6); const project2 = getProjectBlock('Project 2'); + + // FP + // eslint-disable-next-line jest-dom/prefer-in-document expect(within(project2).getAllByRole('link')).toHaveLength(1); }); @@ -621,6 +636,8 @@ describe('projects page', () => { renderAccountApp(mockLoggedInUser(), projectsPagePath); + // FP + // eslint-disable-next-line jest-dom/prefer-in-document expect(await screen.findAllByRole('heading', { name: /Project \d/ })).toHaveLength(1); const showMoreButton = await screen.findByRole('button', { name: 'show_more' }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx index 38a45948ac0..2fe746e08b0 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx @@ -50,16 +50,16 @@ describe('Search', () => { const component = shallow(<Search {...defaultProps} onFilterUpdate={searchSpy} />); const searchInput = component.find('SearchBox'); searchInput.prop<Function>('onChange')('some search query'); - expect(searchSpy).toBeCalledWith({ query: 'some search query' }); + expect(searchSpy).toHaveBeenCalledWith({ query: 'some search query' }); }); it('should reload', () => { const reloadSpy = jest.fn(); const component = shallow(<Search {...defaultProps} onReload={reloadSpy} />); const reloadButton = component.find('.js-reload'); - expect(reloadSpy).not.toBeCalled(); + expect(reloadSpy).not.toHaveBeenCalled(); click(reloadButton); - expect(reloadSpy).toBeCalled(); + expect(reloadSpy).toHaveBeenCalled(); }); }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx index df03a037f3d..a24f0c1d975 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx @@ -50,13 +50,13 @@ it('closes', () => { const onClose = jest.fn(); const wrapper = shallow(<ScannerContext onClose={onClose} task={task} />); click(wrapper.find('.js-modal-close')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); it('fetches scanner context on mount', async () => { const wrapper = shallow(<ScannerContext onClose={jest.fn()} task={task} />); expect(wrapper.state()).toEqual({}); - expect(getTask).toBeCalledWith('123', ['scannerContext']); + expect(getTask).toHaveBeenCalledWith('123', ['scannerContext']); await new Promise(setImmediate); expect(wrapper.state()).toEqual({ scannerContext: 'context' }); }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx index 64b762fb940..898ff042508 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx @@ -50,13 +50,13 @@ it('closes', () => { const onClose = jest.fn(); const wrapper = shallow(<Stacktrace onClose={onClose} task={task} />); click(wrapper.find('.js-modal-close')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); it('fetches scanner context on mount', async () => { const wrapper = shallow(<Stacktrace onClose={jest.fn()} task={task} />); expect(wrapper.state()).toEqual({ loading: true }); - expect(getTask).toBeCalledWith('123', ['stacktrace']); + expect(getTask).toHaveBeenCalledWith('123', ['stacktrace']); await new Promise(setImmediate); expect(wrapper.state()).toEqual({ loading: false, stacktrace: 'stacktrace' }); }); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx index 4a4086955a6..893593f5869 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx @@ -46,9 +46,9 @@ it('should not show cancel pending button', () => { it('should trigger cancelling pending', () => { const onCancelAllPending = jest.fn(); const result = shallowRender({ onCancelAllPending }); - expect(onCancelAllPending).not.toBeCalled(); + expect(onCancelAllPending).not.toHaveBeenCalled(); result.find('ConfirmButton').prop<Function>('onConfirm')(); - expect(onCancelAllPending).toBeCalled(); + expect(onCancelAllPending).toHaveBeenCalled(); }); function shallowRender(props: Partial<Props> = {}) { diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx index 4fb6a91cc1f..89146526c76 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx @@ -37,9 +37,9 @@ it('should render without the filter link', () => { it('should trigger filtering failures', () => { const onShowFailing = jest.fn(); const result = shallowRender({ onShowFailing }); - expect(onShowFailing).not.toBeCalled(); + expect(onShowFailing).not.toHaveBeenCalled(); click(result.find('ButtonLink')); - expect(onShowFailing).toBeCalled(); + expect(onShowFailing).toHaveBeenCalled(); }); function shallowRender(props: Partial<Props> = {}) { diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx index 7505563e52c..0dad618e70d 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx @@ -47,5 +47,5 @@ it('returns new worker count', async () => { submit(wrapper.find('form')); await new Promise(setImmediate); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/CodeApp-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/CodeApp-test.tsx index e0964d7c0c3..bd831db0458 100644 --- a/server/sonar-web/src/main/js/apps/code/components/__tests__/CodeApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/CodeApp-test.tsx @@ -98,7 +98,7 @@ it('should refresh branch status if issues are updated', async () => { await waitAndUpdate(wrapper); instance.handleIssueChange(mockIssue()); - expect(fetchBranchStatus).toBeCalledWith(branchLike, 'foo'); + expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, 'foo'); }); it('should load more behave correctly', async () => { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx index 2fe01a8770a..a0f3fbbae3c 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetails-test.tsx @@ -57,7 +57,7 @@ it('should render correctly', async () => { await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot('loaded'); - expect(getRuleDetails).toBeCalledWith( + expect(getRuleDetails).toHaveBeenCalledWith( expect.objectContaining({ actives: true, key: 'squid:S1337' @@ -72,7 +72,7 @@ it('should correctly handle prop changes', async () => { jest.clearAllMocks(); wrapper.setProps({ ruleKey }); - expect(getRuleDetails).toBeCalledWith( + expect(getRuleDetails).toHaveBeenCalledWith( expect.objectContaining({ actives: true, key: ruleKey @@ -119,7 +119,7 @@ it('should correctly handle activation', async () => { wrapper.instance().handleActivate(); await waitAndUpdate(wrapper); - expect(onActivate).toBeCalledWith( + expect(onActivate).toHaveBeenCalledWith( 'foo', 'squid:S1337', expect.objectContaining({ @@ -137,7 +137,7 @@ it('should correctly handle deactivation', async () => { wrapper.instance().handleDeactivate(); await waitAndUpdate(wrapper); - expect(onDeactivate).toBeCalledWith(selectedProfile.key, 'squid:S1337'); + expect(onDeactivate).toHaveBeenCalledWith(selectedProfile.key, 'squid:S1337'); }); it('should correctly handle deletion', async () => { @@ -147,8 +147,8 @@ it('should correctly handle deletion', async () => { wrapper.instance().handleDelete(); await waitAndUpdate(wrapper); - expect(deleteRule).toBeCalledWith(expect.objectContaining({ key: 'squid:S1337' })); - expect(onDelete).toBeCalledWith('squid:S1337'); + expect(deleteRule).toHaveBeenCalledWith(expect.objectContaining({ key: 'squid:S1337' })); + expect(onDelete).toHaveBeenCalledWith('squid:S1337'); }); function shallowRender(props: Partial<RuleDetails['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx index 16865c5ea2e..8845367de1e 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsIssues-test.tsx @@ -47,7 +47,7 @@ it('should fetch issues and render', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(getFacet).toBeCalledWith( + expect(getFacet).toHaveBeenCalledWith( { resolved: 'false', rules: 'foo' diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx index ef2493ea0a5..014faacb4e9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsMeta-test.tsx @@ -86,7 +86,7 @@ it('should edit tags', () => { .prop('overlay') as RuleDetailsTagsPopup; overlay.props.setTags(['foo', 'bar']); - expect(onTagsChange).toBeCalledWith(['foo', 'bar']); + expect(onTagsChange).toHaveBeenCalledWith(['foo', 'bar']); }); function shallowRender(props: Partial<RuleDetailsMeta['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx index 6b5e427b794..ca63ef23363 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleDetailsTagsPopup-test.tsx @@ -34,7 +34,7 @@ it('should render tags', () => { it('should search tags', async () => { const wrapper = shallowRender(); wrapper.prop<Function>('onSearch')('sys'); - expect(getRuleTags).toBeCalledWith({ ps: 11, q: 'sys' }); + expect(getRuleTags).toHaveBeenCalledWith({ ps: 11, q: 'sys' }); await new Promise(setImmediate); wrapper.update(); // should not contain system tags @@ -46,10 +46,10 @@ it('should select & unselect tags', () => { const wrapper = shallowRender({ setTags }); wrapper.prop<Function>('onSelect')('another'); - expect(setTags).lastCalledWith(['foo', 'another']); + expect(setTags).toHaveBeenLastCalledWith(['foo', 'another']); wrapper.prop<Function>('onUnselect')('foo'); - expect(setTags).lastCalledWith([]); + expect(setTags).toHaveBeenLastCalledWith([]); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx index f8ea100c9d4..3378a7b3c52 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx @@ -38,7 +38,7 @@ it('should open rule', () => { const onOpen = jest.fn(); const wrapper = shallowRender({ onOpen }); wrapper.find(Link).simulate('click', mockEvent({ button: 0 })); - expect(onOpen).toBeCalledWith('javascript:S1067'); + expect(onOpen).toHaveBeenCalledWith('javascript:S1067'); }); it('handle activation', () => { @@ -48,7 +48,7 @@ it('handle activation', () => { const wrapper = shallowRender({ onActivate, rule, selectedProfile: profile }); wrapper.instance().handleActivate('MAJOR'); - expect(onActivate).toBeCalledWith(profile.key, rule.key, { + expect(onActivate).toHaveBeenCalledWith(profile.key, rule.key, { severity: 'MAJOR', inherit: 'NONE' }); @@ -61,14 +61,14 @@ it('handle deactivation', async () => { const wrapper = shallowRender({ onDeactivate, rule, selectedProfile: profile }); wrapper.instance().handleDeactivate(); - expect(deactivateRule).toBeCalledWith( + expect(deactivateRule).toHaveBeenCalledWith( expect.objectContaining({ key: profile.key, rule: rule.key }) ); await waitAndUpdate(wrapper); - expect(onDeactivate).toBeCalledWith(profile.key, rule.key); + expect(onDeactivate).toHaveBeenCalledWith(profile.key, rule.key); }); describe('renderActions', () => { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/SimilarRulesFilter-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/SimilarRulesFilter-test.tsx index 83fd5740c77..c9f3b5fe8a1 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/SimilarRulesFilter-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/SimilarRulesFilter-test.tsx @@ -33,28 +33,28 @@ it('should filter by similar language', () => { const onFilterChange = jest.fn(); const wrapper = mountRenderAction('language', { onFilterChange }); click(wrapper); - expect(onFilterChange).toBeCalledWith({ languages: ['js'] }); + expect(onFilterChange).toHaveBeenCalledWith({ languages: ['js'] }); }); it('should filter by similar type', () => { const onFilterChange = jest.fn(); const wrapper = mountRenderAction('type', { onFilterChange }); click(wrapper); - expect(onFilterChange).toBeCalledWith({ types: ['CODE_SMELL'] }); + expect(onFilterChange).toHaveBeenCalledWith({ types: ['CODE_SMELL'] }); }); it('should filter by similar severity', () => { const onFilterChange = jest.fn(); const wrapper = mountRenderAction('severity', { onFilterChange }); click(wrapper); - expect(onFilterChange).toBeCalledWith({ severities: ['MAJOR'] }); + expect(onFilterChange).toHaveBeenCalledWith({ severities: ['MAJOR'] }); }); it('should filter by similar tag', () => { const onFilterChange = jest.fn(); const wrapper = mountRenderAction('tag', { onFilterChange }); click(wrapper); - expect(onFilterChange).toBeCalledWith({ tags: ['x'] }); + expect(onFilterChange).toHaveBeenCalledWith({ tags: ['x'] }); }); function mountRenderAction(actionName: string, props: Partial<SimilarRulesFilter['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/TagFacet-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/TagFacet-test.tsx index 36e12d1fd74..85c44c8fed1 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/TagFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/TagFacet-test.tsx @@ -37,7 +37,7 @@ it('should handle search', async () => { await wrapper.instance().handleSearch(query); - expect(getRuleTags).toBeCalledWith({ ps: 50, q: query }); + expect(getRuleTags).toHaveBeenCalledWith({ ps: 50, q: query }); }); describe('ListStyleFacet Renderers', () => { diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx index 61d1a6ab94e..802f3d49598 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/App-test.tsx @@ -113,7 +113,7 @@ it('should refresh branch status if issues are updated', async () => { await waitAndUpdate(wrapper); instance.handleIssueChange(mockIssue()); - expect(fetchBranchStatus).toBeCalledWith(branchLike, 'foo'); + expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, 'foo'); }); it('should render a warning message when user does not have access to all projects whithin a Portfolio', async () => { diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx index e1b81422281..4b2a4b71b2e 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureOverview-test.tsx @@ -63,7 +63,7 @@ it('should correctly enhance leaf components', async () => { const updateLoading = jest.fn(); const wrapper = shallowRender({ updateLoading }); - expect(updateLoading).toBeCalledWith({ bubbles: true }); + expect(updateLoading).toHaveBeenCalledWith({ bubbles: true }); expect(getComponentLeaves).toHaveBeenCalledWith( 'foo', [ diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx index 2bb5a708616..bedfb920a37 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/MeasureViewSelect-test.tsx @@ -40,7 +40,7 @@ it('should correctly trigger a selection change', () => { const handleViewChange = jest.fn(); const wrapper = shallowRender({ handleViewChange }); wrapper.instance().handleChange({ icon: <ListIcon />, label: 'List View', value: 'list' }); - expect(handleViewChange).toBeCalledWith('list'); + expect(handleViewChange).toHaveBeenCalledWith('list'); }); function shallowRender(props: Partial<MeasureViewSelect['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/FilesView-test.tsx b/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/FilesView-test.tsx index 1d10df5fa23..3a772b9fea6 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/FilesView-test.tsx +++ b/server/sonar-web/src/main/js/apps/component-measures/drilldown/__tests__/FilesView-test.tsx @@ -87,16 +87,16 @@ it('should correctly bind key events for file navigation', () => { }); keydown({ key: KeyboardKeys.DownArrow }); - expect(handleSelect).toBeCalledWith(FILES[0]); + expect(handleSelect).toHaveBeenCalledWith(FILES[0]); keydown({ key: KeyboardKeys.UpArrow }); - expect(handleSelect).toBeCalledWith(FILES[2]); + expect(handleSelect).toHaveBeenCalledWith(FILES[2]); keydown({ key: KeyboardKeys.RightArrow, ctrlKey: true }); - expect(handleOpen).not.toBeCalled(); + expect(handleOpen).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.RightArrow }); - expect(handleOpen).toBeCalled(); + expect(handleOpen).toHaveBeenCalled(); }); function shallowRender(props: Partial<FilesView['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/AzurePersonalAccessTokenForm-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/AzurePersonalAccessTokenForm-test.tsx index 234e50ef002..25e9a7c721c 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/AzurePersonalAccessTokenForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/AzurePersonalAccessTokenForm-test.tsx @@ -53,7 +53,7 @@ it('should correctly handle form interactions', () => { // Expect correct calls to be made when submitting. submit(wrapper.find('form')); - expect(onPersonalAccessTokenCreate).toBeCalled(); + expect(onPersonalAccessTokenCreate).toHaveBeenCalled(); // If validation fails, we toggle the submitting flag and call useEffect() // to set the `touched` flag to false again. Trigger a re-render, and mock diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectAccordion-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectAccordion-test.tsx index a99c243882f..f020eca9852 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectAccordion-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectAccordion-test.tsx @@ -74,7 +74,7 @@ it('should open when clicked', () => { .props() .onClick(); - expect(onOpen).toBeCalled(); + expect(onOpen).toHaveBeenCalled(); expect( wrapper @@ -104,7 +104,7 @@ it('should close when clicked', () => { .props() .onClick(); - expect(onOpen).not.toBeCalled(); + expect(onOpen).not.toHaveBeenCalled(); expect( wrapper @@ -124,7 +124,7 @@ it('should trigger selection when repo is clicked', () => { .props() .onCheck(mockEvent()); - expect(onSelectRepository).toBeCalledWith(repo); + expect(onSelectRepository).toHaveBeenCalledWith(repo); }); function shallowRender(overrides: Partial<AzureProjectAccordionProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectCreate-test.tsx index 21ae80c4011..32d096c993e 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/AzureProjectCreate-test.tsx @@ -54,14 +54,14 @@ it('should render correctly', () => { it('should correctly fetch binding info on mount', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(checkPersonalAccessTokenIsValid).toBeCalledWith('foo'); + expect(checkPersonalAccessTokenIsValid).toHaveBeenCalledWith('foo'); }); it('should correctly handle a valid PAT', async () => { (checkPersonalAccessTokenIsValid as jest.Mock).mockResolvedValueOnce({ status: true }); const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(checkPersonalAccessTokenIsValid).toBeCalled(); + expect(checkPersonalAccessTokenIsValid).toHaveBeenCalled(); expect(wrapper.state().patIsValid).toBe(true); }); @@ -69,7 +69,7 @@ it('should correctly handle an invalid PAT', async () => { (checkPersonalAccessTokenIsValid as jest.Mock).mockResolvedValueOnce({ status: false }); const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(checkPersonalAccessTokenIsValid).toBeCalled(); + expect(checkPersonalAccessTokenIsValid).toHaveBeenCalled(); expect(wrapper.state().patIsValid).toBe(false); }); @@ -77,12 +77,12 @@ it('should correctly handle setting a new PAT', async () => { const router = mockRouter(); const wrapper = shallowRender({ router }); wrapper.instance().handlePersonalAccessTokenCreate('token'); - expect(setAlmPersonalAccessToken).toBeCalledWith('foo', 'token'); + expect(setAlmPersonalAccessToken).toHaveBeenCalledWith('foo', 'token'); expect(wrapper.state().submittingToken).toBe(true); (checkPersonalAccessTokenIsValid as jest.Mock).mockResolvedValueOnce({ status: false }); await waitAndUpdate(wrapper); - expect(checkPersonalAccessTokenIsValid).toBeCalled(); + expect(checkPersonalAccessTokenIsValid).toHaveBeenCalled(); expect(wrapper.state().submittingToken).toBe(false); expect(wrapper.state().tokenValidationFailed).toBe(true); @@ -91,7 +91,7 @@ it('should correctly handle setting a new PAT', async () => { wrapper.instance().handlePersonalAccessTokenCreate('correct token'); await waitAndUpdate(wrapper); expect(wrapper.state().tokenValidationFailed).toBe(false); - expect(router.replace).toBeCalled(); + expect(router.replace).toHaveBeenCalled(); }); it('should correctly fetch projects and repositories on mount', async () => { @@ -103,9 +103,9 @@ it('should correctly fetch projects and repositories on mount', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getAzureProjects).toBeCalled(); - expect(getAzureRepositories).toBeCalledTimes(1); - expect(getAzureRepositories).toBeCalledWith('foo', project.name); + expect(getAzureProjects).toHaveBeenCalled(); + expect(getAzureRepositories).toHaveBeenCalledTimes(1); + expect(getAzureRepositories).toHaveBeenCalledWith('foo', project.name); }); it('should handle opening a project', async () => { @@ -132,7 +132,7 @@ it('should handle opening a project', async () => { wrapper.instance().handleOpenProject(projects[1].name); await waitAndUpdate(wrapper); - expect(getAzureRepositories).toBeCalledWith('foo', projects[1].name); + expect(getAzureRepositories).toHaveBeenCalledWith('foo', projects[1].name); expect(wrapper.state().repositories).toEqual({ [projects[0].name]: firstProjectRepos, @@ -152,7 +152,7 @@ it('should handle searching for repositories', async () => { wrapper.instance().handleSearchRepositories(query); expect(wrapper.state().searching).toBe(true); - expect(searchAzureRepositories).toBeCalledWith('foo', query); + expect(searchAzureRepositories).toHaveBeenCalledWith('foo', query); await waitAndUpdate(wrapper); expect(wrapper.state().searching).toBe(false); expect(wrapper.state().searchResults).toEqual(repositories); @@ -167,7 +167,7 @@ it('should handle searching for repositories', async () => { (searchAzureRepositories as jest.Mock).mockClear(); wrapper.instance().handleSearchRepositories(''); - expect(searchAzureRepositories).not.toBeCalled(); + expect(searchAzureRepositories).not.toHaveBeenCalled(); expect(wrapper.state().searchResults).toBeUndefined(); expect(wrapper.state().searchQuery).toBeUndefined(); }); @@ -184,10 +184,14 @@ it('should select and import a repository', async () => { wrapper.instance().handleImportRepository(); expect(wrapper.state().importing).toBe(true); - expect(importAzureRepository).toBeCalledWith('foo', repository.projectName, repository.name); + expect(importAzureRepository).toHaveBeenCalledWith( + 'foo', + repository.projectName, + repository.name + ); await waitAndUpdate(wrapper); - expect(onProjectCreate).toBeCalledWith('baz'); + expect(onProjectCreate).toHaveBeenCalledWith('baz'); expect(wrapper.state().importing).toBe(false); }); @@ -201,12 +205,12 @@ it('should handle no settings', () => { wrapper.instance().checkPersonalAccessToken(); wrapper.instance().handlePersonalAccessTokenCreate(''); - expect(getAzureProjects).not.toBeCalled(); - expect(getAzureRepositories).not.toBeCalled(); - expect(searchAzureRepositories).not.toBeCalled(); - expect(importAzureRepository).not.toBeCalled(); - expect(checkPersonalAccessTokenIsValid).not.toBeCalled(); - expect(setAlmPersonalAccessToken).not.toBeCalled(); + expect(getAzureProjects).not.toHaveBeenCalled(); + expect(getAzureRepositories).not.toHaveBeenCalled(); + expect(searchAzureRepositories).not.toHaveBeenCalled(); + expect(importAzureRepository).not.toHaveBeenCalled(); + expect(checkPersonalAccessTokenIsValid).not.toHaveBeenCalled(); + expect(setAlmPersonalAccessToken).not.toHaveBeenCalled(); }); function shallowRender(overrides: Partial<AzureProjectCreate['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketImportRepositoryForm-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketImportRepositoryForm-test.tsx index d0a0bdd8cc8..b8d015b06eb 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketImportRepositoryForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketImportRepositoryForm-test.tsx @@ -42,7 +42,7 @@ it('should correctly handle search', () => { const onSearch = jest.fn(); const wrapper = shallowRender({ onSearch }); change(wrapper.find(SearchBox), 'foo'); - expect(onSearch).toBeCalledWith('foo'); + expect(onSearch).toHaveBeenCalledWith('foo'); }); function shallowRender(props: Partial<BitbucketImportRepositoryFormProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectAccordion-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectAccordion-test.tsx index e6a512febd9..dc6edfc6c38 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectAccordion-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectAccordion-test.tsx @@ -54,7 +54,7 @@ it('should correctly handle selecting repos', () => { .at(0) .props() .onCheck(''); - expect(onSelectRepository).toBeCalledWith(repo); + expect(onSelectRepository).toHaveBeenCalledWith(repo); }); function shallowRender(props: Partial<BitbucketProjectAccordionProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx index fe84d7d8f45..30bf627a0c5 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/BitbucketProjectCreate-test.tsx @@ -79,12 +79,12 @@ it('should correctly fetch projects and repos', async () => { await wrapper.instance().handlePersonalAccessTokenCreated(); // Opens first project on mount. - expect(getBitbucketServerProjects).toBeCalledWith('foo'); + expect(getBitbucketServerProjects).toHaveBeenCalledWith('foo'); expect(wrapper.state().projects).toHaveLength(2); // Check repos got loaded. await waitAndUpdate(wrapper); - expect(getBitbucketServerRepositories).toBeCalledWith('foo', 'Project 1'); + expect(getBitbucketServerRepositories).toHaveBeenCalledWith('foo', 'Project 1'); expect(wrapper.state().projectRepositories).toEqual( expect.objectContaining({ project1: expect.objectContaining({ @@ -106,9 +106,9 @@ it('should correctly import a repo', async () => { instance.handleSelectRepository(repo); instance.handleImportRepository(); - expect(importBitbucketServerProject).toBeCalledWith('foo', repo.projectKey, repo.slug); + expect(importBitbucketServerProject).toHaveBeenCalledWith('foo', repo.projectKey, repo.slug); await waitAndUpdate(wrapper); - expect(onProjectCreate).toBeCalledWith('baz'); + expect(onProjectCreate).toHaveBeenCalledWith('baz'); }); it('should correctly handle search', async () => { @@ -117,12 +117,12 @@ it('should correctly handle search', async () => { // Don't trigger search on empty query. instance.handleSearch(''); - expect(searchForBitbucketServerRepositories).not.toBeCalled(); + expect(searchForBitbucketServerRepositories).not.toHaveBeenCalled(); expect(wrapper.state().searching).toBe(false); expect(wrapper.state().searchResults).toBeUndefined(); instance.handleSearch('bar'); - expect(searchForBitbucketServerRepositories).toBeCalledWith('foo', 'bar'); + expect(searchForBitbucketServerRepositories).toHaveBeenCalledWith('foo', 'bar'); expect(wrapper.state().searching).toBe(true); await waitAndUpdate(wrapper); expect(wrapper.state().searching).toBe(false); diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectModeSelection-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectModeSelection-test.tsx index 4be1b325d6a..3dbf2b4487c 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectModeSelection-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectModeSelection-test.tsx @@ -67,23 +67,23 @@ it('should correctly pass the selected mode up', () => { const almButton = 'button.create-project-mode-type-alm'; click(wrapper.find('button.create-project-mode-type-manual')); - expect(onSelectMode).toBeCalledWith(CreateProjectModes.Manual); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.Manual); onSelectMode.mockClear(); click(wrapper.find(almButton).at(0)); - expect(onSelectMode).toBeCalledWith(CreateProjectModes.AzureDevOps); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.AzureDevOps); onSelectMode.mockClear(); click(wrapper.find(almButton).at(1)); - expect(onSelectMode).toBeCalledWith(CreateProjectModes.BitbucketServer); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.BitbucketServer); onSelectMode.mockClear(); click(wrapper.find(almButton).at(2)); - expect(onSelectMode).toBeCalledWith(CreateProjectModes.GitHub); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitHub); onSelectMode.mockClear(); click(wrapper.find(almButton).at(3)); - expect(onSelectMode).toBeCalledWith(CreateProjectModes.GitLab); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.GitLab); onSelectMode.mockClear(); wrapper = shallowRender( @@ -92,7 +92,7 @@ it('should correctly pass the selected mode up', () => { ); click(wrapper.find(almButton).at(1)); - expect(onSelectMode).toBeCalledWith(CreateProjectModes.BitbucketCloud); + expect(onSelectMode).toHaveBeenCalledWith(CreateProjectModes.BitbucketCloud); onSelectMode.mockClear(); }); diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPage-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPage-test.tsx index d508cda2e7a..4098221e47a 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPage-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPage-test.tsx @@ -39,7 +39,7 @@ beforeEach(jest.clearAllMocks); it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot(); - expect(getAlmSettings).toBeCalled(); + expect(getAlmSettings).toHaveBeenCalled(); }); it.each([ diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreate-test.tsx index 63035a46352..58732686b45 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreate-test.tsx @@ -72,8 +72,8 @@ it('should redirect when no code', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getGithubClientId).toBeCalled(); - expect(window.location.replace).toBeCalled(); + expect(getGithubClientId).toHaveBeenCalled(); + expect(window.location.replace).toHaveBeenCalled(); }); it('should redirect when no code - github.com', async () => { @@ -82,8 +82,8 @@ it('should redirect when no code - github.com', async () => { }); await waitAndUpdate(wrapper); - expect(getGithubClientId).toBeCalled(); - expect(window.location.replace).toBeCalledWith( + expect(getGithubClientId).toHaveBeenCalled(); + expect(window.location.replace).toHaveBeenCalledWith( 'github.com/login/oauth/authorize?client_id=client-id-124&redirect_uri=http://localhost/projects/create?mode=github' ); }); @@ -94,7 +94,7 @@ it('should not redirect when invalid clientId', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().error).toBe(true); - expect(window.location.replace).not.toBeCalled(); + expect(window.location.replace).not.toHaveBeenCalled(); }); it('should fetch organizations when code', async () => { @@ -110,8 +110,8 @@ it('should fetch organizations when code', async () => { }); await waitAndUpdate(wrapper); - expect(replace).toBeCalled(); - expect(getGithubOrganizations).toBeCalled(); + expect(replace).toHaveBeenCalled(); + expect(getGithubOrganizations).toHaveBeenCalled(); expect(wrapper.state().organizations).toBe(organizations); }); @@ -133,7 +133,7 @@ it('should handle org selection', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().selectedOrganization).toBe(organizations[0]); - expect(getGithubRepositories).toBeCalled(); + expect(getGithubRepositories).toHaveBeenCalled(); expect(wrapper.state().repositories).toBe(repositories); }); @@ -158,7 +158,7 @@ it('should load more', async () => { await waitAndUpdate(wrapper); - expect(getGithubRepositories).toBeCalled(); + expect(getGithubRepositories).toHaveBeenCalled(); expect(wrapper.state().repositories).toEqual([...startRepos, ...repositories]); }); @@ -182,7 +182,7 @@ it('should handle search', async () => { await waitAndUpdate(wrapper); - expect(getGithubRepositories).toBeCalledWith({ + expect(getGithubRepositories).toHaveBeenCalledWith({ almSetting: 'a', organization: 'o1', page: 1, @@ -212,7 +212,7 @@ it('should handle importing', async () => { const wrapper = shallowRender({ onProjectCreate }); wrapper.instance().handleImportRepository(); - expect(importGithubRepository).not.toBeCalled(); + expect(importGithubRepository).not.toHaveBeenCalled(); const selectedOrganization = { key: 'org1', name: 'org1' }; const selectedRepository = mockGitHubRepository(); @@ -223,12 +223,12 @@ it('should handle importing', async () => { wrapper.instance().handleImportRepository(); await waitAndUpdate(wrapper); - expect(importGithubRepository).toBeCalledWith( + expect(importGithubRepository).toHaveBeenCalledWith( 'a', selectedOrganization.key, selectedRepository.key ); - expect(onProjectCreate).toBeCalledWith(project.key); + expect(onProjectCreate).toHaveBeenCalledWith(project.key); }); function shallowRender(props: Partial<GitHubProjectCreate['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreateRenderer-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreateRenderer-test.tsx index 380170f9a01..7de9d843efb 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreateRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitHubProjectCreateRenderer-test.tsx @@ -86,7 +86,7 @@ describe('callback', () => { it('should be called when org is selected', () => { const value = 'o1'; wrapper.find(Select).simulate('change', { value }); - expect(onSelectOrganization).toBeCalledWith(value); + expect(onSelectOrganization).toHaveBeenCalledWith(value); }); it('should be called when searchbox is changed', () => { @@ -95,7 +95,7 @@ describe('callback', () => { .find(SearchBox) .props() .onChange(value); - expect(onSearch).toBeCalledWith(value); + expect(onSearch).toHaveBeenCalledWith(value); }); it('should be called when repo is selected', () => { @@ -104,7 +104,7 @@ describe('callback', () => { .find(Radio) .props() .onCheck(value); - expect(onSelectRepository).toBeCalledWith(value); + expect(onSelectRepository).toHaveBeenCalledWith(value); }); }); diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectCreate-test.tsx index 71ab1ebed39..579810d0965 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectCreate-test.tsx @@ -79,7 +79,7 @@ it('should fetch more projects and preserve search', async () => { expect(wrapper.state().loadingMore).toBe(false); expect(wrapper.state().projects).toEqual(projects); - expect(getGitlabProjects).toBeCalledWith(expect.objectContaining({ query: 'query' })); + expect(getGitlabProjects).toHaveBeenCalledWith(expect.objectContaining({ query: 'query' })); }); it('should search for projects', async () => { @@ -120,7 +120,7 @@ it('should search for projects', async () => { expect(wrapper.state().searchQuery).toBe(query); expect(wrapper.state().projects).toEqual([projects[3], projects[4]]); - expect(getGitlabProjects).toBeCalledWith(expect.objectContaining({ query })); + expect(getGitlabProjects).toHaveBeenCalledWith(expect.objectContaining({ query })); }); it('should import', async () => { @@ -150,7 +150,7 @@ it('should import', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().importingGitlabProjectId).toBeUndefined(); - expect(onProjectCreate).toBeCalledWith(createdProjectkey); + expect(onProjectCreate).toHaveBeenCalledWith(createdProjectkey); }); it('should do nothing with missing settings', async () => { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectSelectionForm-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectSelectionForm-test.tsx index 816ef347b6b..a32c6712ef2 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectSelectionForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/GitlabProjectSelectionForm-test.tsx @@ -55,7 +55,7 @@ describe('appropriate callback', () => { .first() .simulate('click'); - expect(onImport).toBeCalled(); + expect(onImport).toHaveBeenCalled(); }); it('should be assigned to the list footer', () => { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/ManualProjectCreate-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/ManualProjectCreate-test.tsx index 1241a7036d3..933d45fa607 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/ManualProjectCreate-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/ManualProjectCreate-test.tsx @@ -133,7 +133,7 @@ it('should submit form input', async () => { await user.keyboard('test'); await user.click(screen.getByRole('button', { name: 'set_up' })); expect(createProject).toHaveBeenCalledWith({ name: 'test', project: 'test' }); - expect(onProjectCreate).toBeCalled(); + expect(onProjectCreate).toHaveBeenCalled(); }); it('should handle create failure', async () => { diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/PersonalAccessTokenForm-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/PersonalAccessTokenForm-test.tsx index 9f0f7ed7d72..e3760fef073 100644 --- a/server/sonar-web/src/main/js/apps/create/project/__tests__/PersonalAccessTokenForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/PersonalAccessTokenForm-test.tsx @@ -82,8 +82,8 @@ it('should correctly handle form interactions', async () => { // Expect correct calls to be made when submitting. submit(wrapper.find('form')); - expect(onPersonalAccessTokenCreated).toBeCalled(); - expect(setAlmPersonalAccessToken).toBeCalledWith('key', 'token', undefined); + expect(onPersonalAccessTokenCreated).toHaveBeenCalled(); + expect(setAlmPersonalAccessToken).toHaveBeenCalledWith('key', 'token', undefined); }); it('should correctly handle form for bitbucket interactions', async () => { @@ -106,8 +106,8 @@ it('should correctly handle form for bitbucket interactions', async () => { // Expect correct calls to be made when submitting. submit(wrapper.find('form')); - expect(onPersonalAccessTokenCreated).toBeCalled(); - expect(setAlmPersonalAccessToken).toBeCalledWith('key', 'token', 'username'); + expect(onPersonalAccessTokenCreated).toHaveBeenCalled(); + expect(setAlmPersonalAccessToken).toHaveBeenCalledWith('key', 'token', 'username'); }); it('should show error when issue', async () => { diff --git a/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts b/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts index 53fd2101f70..263144f12bc 100644 --- a/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts +++ b/server/sonar-web/src/main/js/apps/documentation/__tests__/pages-test.ts @@ -115,7 +115,7 @@ it('should not break the whole doc when one page cannot be parsed', () => { const pages = getPages(); expect(pages.length).toBe(2); expect(pages[0].content).toBe(''); - expect(console.error).toBeCalledTimes(1); + expect(console.error).toHaveBeenCalledTimes(1); console.error = originalConsoleError; }); diff --git a/server/sonar-web/src/main/js/apps/documentation/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/documentation/components/__tests__/App-test.tsx index bc3b3c3ef48..e19bb2e155e 100644 --- a/server/sonar-web/src/main/js/apps/documentation/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/documentation/components/__tests__/App-test.tsx @@ -95,14 +95,14 @@ beforeEach(() => { it('should render correctly for SonarQube', async () => { const wrapper = shallowRender(); expect(wrapper.find('DeferredSpinner').exists()).toBe(true); - expect(addSideBarClass).toBeCalled(); + expect(addSideBarClass).toHaveBeenCalled(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); expect(wrapper.find('ScreenPositionHelper').dive()).toMatchSnapshot(); wrapper.unmount(); - expect(removeSideBarClass).toBeCalled(); + expect(removeSideBarClass).toHaveBeenCalled(); }); it("should show a 404 if the page doesn't exist", async () => { diff --git a/server/sonar-web/src/main/js/apps/documentation/components/__tests__/SearchResults-test.tsx b/server/sonar-web/src/main/js/apps/documentation/components/__tests__/SearchResults-test.tsx index d01e6646c76..429d6b4ebaf 100644 --- a/server/sonar-web/src/main/js/apps/documentation/components/__tests__/SearchResults-test.tsx +++ b/server/sonar-web/src/main/js/apps/documentation/components/__tests__/SearchResults-test.tsx @@ -149,9 +149,9 @@ describe('search engine', () => { it('should trigger a search if query is set', () => { const wrapper = shallowRender({ query: undefined }); - expect(wrapper.instance().index.search).not.toBeCalled(); + expect(wrapper.instance().index.search).not.toHaveBeenCalled(); wrapper.setProps({ query: 'si:+mply text' }); - expect(wrapper.instance().index.search).toBeCalledWith('simply~1 simply* text~1 text*'); + expect(wrapper.instance().index.search).toHaveBeenCalledWith('simply~1 simply* text~1 text*'); }); }); @@ -217,7 +217,7 @@ describe('tokenContextPluginCallback', () => { it('should only register the plugin once', () => { tokenContextPlugin(mockLunrBuilder()); tokenContextPlugin(mockLunrBuilder()); - expect((lunr as any).Pipeline.registerFunction).toBeCalledTimes(1); + expect((lunr as any).Pipeline.registerFunction).toHaveBeenCalledTimes(1); }); }); diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx index c5236b58d9e..31fe6ef3cf1 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/App-test.tsx @@ -137,7 +137,7 @@ it('should search for groups', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); wrapper.find('SearchBox').prop<Function>('onChange')('foo'); - expect(searchUsersGroups).toBeCalledWith({ q: 'foo' }); + expect(searchUsersGroups).toHaveBeenCalledWith({ q: 'foo' }); expect(wrapper.state('query')).toBe('foo'); }); diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/EditMembers-test.tsx b/server/sonar-web/src/main/js/apps/groups/components/__tests__/EditMembers-test.tsx index 9c371847ab0..d074e82a795 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/EditMembers-test.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/EditMembers-test.tsx @@ -33,6 +33,6 @@ it('should edit members', () => { expect(wrapper).toMatchSnapshot(); wrapper.find('EditMembersModal').prop<Function>('onClose')(); - expect(onEdit).toBeCalled(); + expect(onEdit).toHaveBeenCalled(); expect(wrapper).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/Form-test.tsx b/server/sonar-web/src/main/js/apps/groups/components/__tests__/Form-test.tsx index 7446dd8525e..263d5ff0a5b 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/Form-test.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/Form-test.tsx @@ -38,12 +38,12 @@ it('should render form', async () => { change(wrapper.find('[name="name"]'), 'foo'); change(wrapper.find('[name="description"]'), 'bar'); submit(wrapper.find('form')); - expect(onSubmit).toBeCalledWith({ description: 'bar', name: 'foo' }); + expect(onSubmit).toHaveBeenCalledWith({ description: 'bar', name: 'foo' }); await new Promise(setImmediate); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); onClose.mockClear(); click(wrapper.find('ResetButtonLink')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/groups/components/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/groups/components/__tests__/Header-test.tsx index 924810137ab..69783e4e44b 100644 --- a/server/sonar-web/src/main/js/apps/groups/components/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/apps/groups/components/__tests__/Header-test.tsx @@ -31,5 +31,5 @@ it('should create new group', () => { expect(wrapper).toMatchSnapshot(); wrapper.find('Form').prop<Function>('onSubmit')({ name: 'foo', description: 'bar' }); - expect(onCreate).toBeCalledWith({ name: 'foo', description: 'bar' }); + expect(onCreate).toHaveBeenCalledWith({ name: 'foo', description: 'bar' }); }); diff --git a/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx b/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx index b0ec1e11e8d..0eb6484eac5 100644 --- a/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx @@ -50,7 +50,7 @@ it('should be able to bulk change', async () => { renderIssueApp(mockCurrentUser({ isLoggedIn: true })); // Check that the bulk button has correct behavior - expect(await screen.findByRole('button', { name: 'bulk_change' })).toHaveAttribute('disabled'); + expect(await screen.findByRole('button', { name: 'bulk_change' })).toBeDisabled(); await user.click(screen.getByRole('checkbox', { name: 'issues.select_all_issues' })); expect( screen.getByRole('button', { name: 'issues.bulk_change_X_issues.500' }) @@ -75,7 +75,7 @@ it('should be able to bulk change', async () => { await user.click(screen.getByRole('textbox', { name: 'issue.comment.formlink' })); await user.keyboard('New Comment'); - expect(screen.getByRole('button', { name: 'apply' })).toHaveAttribute('disabled'); + expect(screen.getByRole('button', { name: 'apply' })).toBeDisabled(); await selectEvent.select(screen.getByRole('textbox', { name: 'issue.set_type' }), [ 'issue.type.BUG' @@ -207,6 +207,9 @@ it('should open issue and navigate', async () => { // check for extended description const extendedDescriptions = screen.getAllByText('Extended Description'); + + // FP + // eslint-disable-next-line jest-dom/prefer-in-document expect(extendedDescriptions).toHaveLength(1); // Select the previous issue (with a simple rule) through keyboard shortcut diff --git a/server/sonar-web/src/main/js/apps/issues/components/__tests__/AssigneeSelect-test.tsx b/server/sonar-web/src/main/js/apps/issues/components/__tests__/AssigneeSelect-test.tsx index 122df7713b1..95e7b6473f3 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/__tests__/AssigneeSelect-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/__tests__/AssigneeSelect-test.tsx @@ -112,7 +112,7 @@ it('should handle assignee search', async () => { const wrapper = shallowRender({ onAssigneeSelect }); wrapper.instance().handleAssigneeSearch('a', jest.fn()); - expect(searchAssignees).not.toBeCalled(); + expect(searchAssignees).not.toHaveBeenCalled(); const result = await new Promise((resolve: (opts: AssigneeOption[]) => void) => { wrapper.instance().handleAssigneeSearch('someone', resolve); diff --git a/server/sonar-web/src/main/js/apps/issues/components/__tests__/BulkChangeModal-test.tsx b/server/sonar-web/src/main/js/apps/issues/components/__tests__/BulkChangeModal-test.tsx index 6e7899de8a8..fdaed62701b 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/__tests__/BulkChangeModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/__tests__/BulkChangeModal-test.tsx @@ -62,7 +62,7 @@ it('should properly handle the search for tags', async () => { await new Promise(resolve => { wrapper.instance().handleTagsSearch('query', resolve); }); - expect(searchIssueTags).toBeCalled(); + expect(searchIssueTags).toHaveBeenCalled(); }); it.each([ diff --git a/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesApp-test.tsx b/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesApp-test.tsx index 6514e96263f..d080b03bb50 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesApp-test.tsx @@ -134,8 +134,8 @@ it('should render a list of issue', async () => { expect(wrapper.state().referencedComponentsById).toEqual({ 'foo-uuid': referencedComponent }); expect(wrapper.state().referencedComponentsByKey).toEqual({ 'foo-key': referencedComponent }); - expect(addSideBarClass).toBeCalled(); - expect(addWhitePageClass).toBeCalled(); + expect(addSideBarClass).toHaveBeenCalled(); + expect(addWhitePageClass).toHaveBeenCalled(); }); it('should handle my issue change properly', () => { @@ -143,7 +143,7 @@ it('should handle my issue change properly', () => { const wrapper = shallowRender({ router: mockRouter({ push }) }); wrapper.instance().handleMyIssuesChange(true); - expect(push).toBeCalledWith({ + expect(push).toHaveBeenCalledWith({ pathname: '/issues', query: { id: 'foo', @@ -164,14 +164,14 @@ it('should not render for anonymous user', () => { currentUser: mockCurrentUser({ isLoggedIn: false }), location: mockLocation({ query: { myIssues: true.toString() } }) }); - expect(handleRequiredAuthentication).toBeCalled(); + expect(handleRequiredAuthentication).toHaveBeenCalled(); }); it('should handle reset properly', () => { const push = jest.fn(); const wrapper = shallowRender({ router: mockRouter({ push }) }); wrapper.instance().handleReset(); - expect(push).toBeCalledWith({ + expect(push).toHaveBeenCalledWith({ pathname: '/issues', query: { id: 'foo', @@ -193,16 +193,16 @@ it('should open standard facets for vulnerabilities and hotspots', () => { instance.handleFacetToggle('standards'); expect(wrapper.state('openFacets').standards).toEqual(false); - expect(fetchFacet).not.toBeCalled(); + expect(fetchFacet).not.toHaveBeenCalled(); instance.handleFacetToggle('standards'); expect(wrapper.state('openFacets').standards).toEqual(true); expect(wrapper.state('openFacets').sonarsourceSecurity).toEqual(true); - expect(fetchFacet).lastCalledWith('sonarsourceSecurity'); + expect(fetchFacet).toHaveBeenLastCalledWith('sonarsourceSecurity'); instance.handleFacetToggle('owaspTop10'); expect(wrapper.state('openFacets').owaspTop10).toEqual(true); - expect(fetchFacet).lastCalledWith('owaspTop10'); + expect(fetchFacet).toHaveBeenLastCalledWith('owaspTop10'); }); it('should correctly bind key events for issue navigation', async () => { @@ -211,7 +211,7 @@ it('should correctly bind key events for issue navigation', async () => { const wrapper = shallowRender({ router: mockRouter({ push }) }); await waitAndUpdate(wrapper); - expect(addEventListenerSpy).toBeCalledTimes(2); + expect(addEventListenerSpy).toHaveBeenCalledTimes(2); expect(wrapper.state('selected')).toBe(ISSUES[0].key); @@ -231,12 +231,12 @@ it('should correctly bind key events for issue navigation', async () => { expect(wrapper.state('selected')).toBe(ISSUES[3].key); keydown({ key: KeyboardKeys.RightArrow, ctrlKey: true }); - expect(push).not.toBeCalled(); + expect(push).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.RightArrow }); - expect(push).toBeCalledTimes(1); + expect(push).toHaveBeenCalledTimes(1); keydown({ key: KeyboardKeys.LeftArrow }); - expect(push).toBeCalledTimes(2); + expect(push).toHaveBeenCalledTimes(2); addEventListenerSpy.mockReset(); }); @@ -246,9 +246,9 @@ it('should correctly clean up on unmount', () => { const wrapper = shallowRender(); wrapper.unmount(); - expect(removeSideBarClass).toBeCalled(); - expect(removeWhitePageClass).toBeCalled(); - expect(removeEventListenerSpy).toBeCalledTimes(2); + expect(removeSideBarClass).toHaveBeenCalled(); + expect(removeWhitePageClass).toHaveBeenCalled(); + expect(removeEventListenerSpy).toHaveBeenCalledTimes(2); removeEventListenerSpy.mockReset(); }); @@ -312,7 +312,7 @@ it('should correctly handle filter changes', () => { sonarsourceSecurity: true, standards: true }); - expect(push).toBeCalled(); + expect(push).toHaveBeenCalled(); instance.handleFilterChange({ types: ['BUGS'] }); expect(instance.state.openFacets).toEqual({ types: true, @@ -413,11 +413,11 @@ it('should refresh branch status if issues are updated', async () => { const updatedIssue: Issue = { ...ISSUES[0], type: 'SECURITY_HOTSPOT' }; instance.handleIssueChange(updatedIssue); expect(wrapper.state().issues[0].type).toEqual(updatedIssue.type); - expect(fetchBranchStatus).toBeCalledWith(branchLike, component.key); + expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, component.key); fetchBranchStatus.mockClear(); instance.handleBulkChangeDone(); - expect(fetchBranchStatus).toBeCalled(); + expect(fetchBranchStatus).toHaveBeenCalled(); }); it('should update the open issue when it is changed', async () => { @@ -455,7 +455,7 @@ it('should handle createAfter query param with time', async () => { (searchIssues as jest.Mock).mockClear(); wrapper.instance().fetchIssues({}); - expect(searchIssues).toBeCalledWith( + expect(searchIssues).toHaveBeenCalledWith( expect.objectContaining({ createdAfter: '2020-10-21T17:21:00+0000' }) ); }); diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueBox-test.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueBox-test.tsx index 949ccf2cf87..cb3cc6b0aaa 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueBox-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/__tests__/ConciseIssueBox-test.tsx @@ -31,7 +31,7 @@ it('should render correctly', async () => { expect(wrapper).toMatchSnapshot(); click(wrapper.find('.concise-issue-box')); - expect(onClick).toBeCalledWith(issue.key); + expect(onClick).toHaveBeenCalledWith(issue.key); expect(shallowRender({ issue: mockIssue(true), selected: true })).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewer-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewer-test.tsx index 645a2b9974e..d0f0fba1570 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewer-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/CrossComponentSourceViewer-test.tsx @@ -71,7 +71,7 @@ it('Should fetch data', async () => { (getIssueFlowSnippets as jest.Mock).mockClear(); wrapper.setProps({ issue: mockIssue(true, { key: 'foo' }) }); - expect(getIssueFlowSnippets).toBeCalledWith('foo'); + expect(getIssueFlowSnippets).toHaveBeenCalledWith('foo'); }); it('Should handle no access rights', async () => { diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/SnippetViewer-test.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/SnippetViewer-test.tsx index 1a3c685d6f8..88b099b2ce7 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/SnippetViewer-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/__tests__/SnippetViewer-test.tsx @@ -68,7 +68,7 @@ it('should render additional child in line', () => { verticalBuffer: 5 }); - expect(renderAdditionalChildInLine).toBeCalledWith(sourceline); + expect(renderAdditionalChildInLine).toHaveBeenCalledWith(sourceline); }); it('should render correctly when at the top of the file', () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/AssigneeFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/AssigneeFacet-test.tsx index f3461980844..a9841ccf695 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/AssigneeFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/AssigneeFacet-test.tsx @@ -40,13 +40,13 @@ it('should call onChange', () => { const itemOnClick = wrapper.find('ListStyleFacet').prop<Function>('onItemClick'); itemOnClick(''); - expect(onChange).lastCalledWith({ assigned: false, assignees: [] }); + expect(onChange).toHaveBeenLastCalledWith({ assigned: false, assignees: [] }); itemOnClick('bar'); - expect(onChange).lastCalledWith({ assigned: true, assignees: ['bar'] }); + expect(onChange).toHaveBeenLastCalledWith({ assigned: true, assignees: ['bar'] }); itemOnClick('baz', true); - expect(onChange).lastCalledWith({ assigned: true, assignees: ['baz', 'foo'] }); + expect(onChange).toHaveBeenLastCalledWith({ assigned: true, assignees: ['baz', 'foo'] }); }); describe('test behavior', () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/PeriodFilter-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/PeriodFilter-test.tsx index 69dfee372f2..0bdcd8c7463 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/PeriodFilter-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/PeriodFilter-test.tsx @@ -43,7 +43,7 @@ it('should filter when clicked', async () => { await user.click(screen.getByText('issues.new_code')); - expect(onChange).toBeCalledWith({ + expect(onChange).toHaveBeenCalledWith({ createdAfter: undefined, createdAt: undefined, createdBefore: undefined, @@ -60,7 +60,7 @@ it('should be clearable', async () => { await user.click(screen.getByText('clear')); - expect(onChange).toBeCalledWith({ + expect(onChange).toHaveBeenCalledWith({ inNewCodePeriod: undefined }); }); diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ProjectFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ProjectFacet-test.tsx index e9c9ff87c88..45ce1c7f9a1 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ProjectFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ProjectFacet-test.tsx @@ -50,7 +50,7 @@ it('should callback to load search results', () => { { key: '2', name: 'seecond' } ]); - expect(loadSearchResultCount).toBeCalledWith('projects', { projects: ['1', '2'] }); + expect(loadSearchResultCount).toHaveBeenCalledWith('projects', { projects: ['1', '2'] }); }); it('should handle search for projects globally', async () => { @@ -59,8 +59,8 @@ it('should handle search for projects globally', async () => { await wrapper.instance().handleSearch(query); - expect(searchProjects).toBeCalled(); - expect(getTree).not.toBeCalled(); + expect(searchProjects).toHaveBeenCalled(); + expect(getTree).not.toHaveBeenCalled(); }); it('should handle search for projects in portfolio', async () => { @@ -71,8 +71,8 @@ it('should handle search for projects in portfolio', async () => { await wrapper.instance().handleSearch(query); - expect(searchProjects).not.toBeCalled(); - expect(getTree).toBeCalled(); + expect(searchProjects).not.toHaveBeenCalled(); + expect(getTree).toHaveBeenCalled(); }); describe("ListStyleFacet's renderers", () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/RuleFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/RuleFacet-test.tsx index 6d00092f625..75a3c8ac9c1 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/RuleFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/RuleFacet-test.tsx @@ -40,7 +40,9 @@ it('should handle search', async () => { await wrapper.instance().handleSearch(query); - expect(searchRules).toBeCalledWith(expect.objectContaining({ languages: 'js,java', q: query })); + expect(searchRules).toHaveBeenCalledWith( + expect.objectContaining({ languages: 'js,java', q: query }) + ); }); describe('ListStyleFacet Renderers', () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ScopeFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ScopeFacet-test.tsx index fce89b0a143..abc273c3101 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ScopeFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/ScopeFacet-test.tsx @@ -39,10 +39,10 @@ it('should correctly handle facet header clicks', () => { const wrapper = shallowRender({ onChange, onToggle }); wrapper.find(FacetHeader).props().onClear!(); - expect(onChange).toBeCalledWith({ scopes: [] }); + expect(onChange).toHaveBeenCalledWith({ scopes: [] }); wrapper.find(FacetHeader).props().onClick!(); - expect(onToggle).toBeCalledWith('scopes'); + expect(onToggle).toHaveBeenCalledWith('scopes'); }); it('should correctly handle facet item clicks', () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StandardFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StandardFacet-test.tsx index 587892576e5..fa4b3eaf027 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StandardFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StandardFacet-test.tsx @@ -70,21 +70,21 @@ jest.mock('../../../../helpers/security-standard', () => ({ it('should render closed', () => { expect(shallowRender()).toMatchSnapshot(); - expect(getStandards).not.toBeCalled(); + expect(getStandards).not.toHaveBeenCalled(); }); it('should toggle standards facet', () => { const onToggle = jest.fn(); const wrapper = shallowRender({ onToggle }); click(wrapper.children('FacetHeader')); - expect(onToggle).toBeCalledWith('standards'); + expect(onToggle).toHaveBeenCalledWith('standards'); }); it('should clear standards facet', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange }); wrapper.children('FacetHeader').prop<Function>('onClear')(); - expect(onChange).toBeCalledWith({ + expect(onChange).toHaveBeenCalledWith({ cwe: [], owaspTop10: [], 'owaspTop10-2021': [], @@ -112,7 +112,7 @@ it('should render sub-facets', () => { sonarsourceSecurityStats: { 'sql-injection': 12 } }) ).toMatchSnapshot(); - expect(getStandards).toBeCalled(); + expect(getStandards).toHaveBeenCalled(); }); it('should show sonarsource facet more button', () => { @@ -192,7 +192,7 @@ it('should select items', () => { .find(`FacetBox[property="${facet}"]`) .find(`FacetItem[value="${value}"]`) .prop<Function>('onClick')(value, multiple); - expect(onChange).lastCalledWith({ [facet]: expectedValue }); + expect(onChange).toHaveBeenLastCalledWith({ [facet]: expectedValue }); } }); @@ -200,11 +200,11 @@ it('should toggle sub-facets', () => { const onToggle = jest.fn(); const wrapper = shallowRender({ onToggle, open: true }); click(wrapper.find('FacetBox[property="owaspTop10"]').children('FacetHeader')); - expect(onToggle).lastCalledWith('owaspTop10'); + expect(onToggle).toHaveBeenLastCalledWith('owaspTop10'); click(wrapper.find('FacetBox[property="sansTop25"]').children('FacetHeader')); - expect(onToggle).lastCalledWith('sansTop25'); + expect(onToggle).toHaveBeenLastCalledWith('sansTop25'); click(wrapper.find('FacetBox[property="sonarsourceSecurity"]').children('FacetHeader')); - expect(onToggle).lastCalledWith('sonarsourceSecurity'); + expect(onToggle).toHaveBeenLastCalledWith('sonarsourceSecurity'); }); it('should display correct selection', () => { diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StatusFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StatusFacet-test.tsx index e9fa5f5c5a4..666f381a72c 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StatusFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StatusFacet-test.tsx @@ -30,14 +30,14 @@ it('should toggle status facet', () => { const onToggle = jest.fn(); const wrapper = shallowRender({ onToggle }); click(wrapper.children('FacetHeader')); - expect(onToggle).toBeCalledWith('statuses'); + expect(onToggle).toHaveBeenCalledWith('statuses'); }); it('should clear status facet', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange, statuses: ['CONFIRMED'] }); wrapper.children('FacetHeader').prop<Function>('onClear')(); - expect(onChange).toBeCalledWith({ statuses: [] }); + expect(onChange).toHaveBeenCalledWith({ statuses: [] }); }); it('should select a status', () => { @@ -52,7 +52,7 @@ it('should select a status', () => { .find(`FacetItemsList`) .find(`FacetItem[value="${status}"]`) .prop<Function>('onClick')(status, multiple); - expect(onChange).lastCalledWith({ statuses: expected }); + expect(onChange).toHaveBeenLastCalledWith({ statuses: expected }); wrapper.setProps({ statuses: expected }); } }); diff --git a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/TypeFacet-test.tsx b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/TypeFacet-test.tsx index 3790bb0a62e..3a778362f68 100644 --- a/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/TypeFacet-test.tsx +++ b/server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/TypeFacet-test.tsx @@ -30,14 +30,14 @@ it('should toggle type facet', () => { const onToggle = jest.fn(); const wrapper = shallowRender({ onToggle }); click(wrapper.children('FacetHeader')); - expect(onToggle).toBeCalledWith('types'); + expect(onToggle).toHaveBeenCalledWith('types'); }); it('should clear types facet', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange, types: ['BUGS'] }); wrapper.children('FacetHeader').prop<Function>('onClear')(); - expect(onChange).toBeCalledWith({ types: [] }); + expect(onChange).toHaveBeenCalledWith({ types: [] }); }); it('should select a type', () => { @@ -51,7 +51,7 @@ it('should select a type', () => { .find(`FacetItemsList`) .find(`FacetItem[value="${type}"]`) .prop<Function>('onClick')(type, multiple); - expect(onChange).lastCalledWith({ types: expected }); + expect(onChange).toHaveBeenLastCalledWith({ types: expected }); wrapper.setProps({ types: expected }); } }); diff --git a/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx index 98f1e8fe9fc..bd74666d3c9 100644 --- a/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/maintenance/components/__tests__/App-test.tsx @@ -95,12 +95,17 @@ describe('Maintenance', () => { const title = await screen.findByRole('heading', { name: heading }); expect(title).toBeInTheDocument(); + // eslint-disable-next-line jest/no-conditional-in-test if (body) { + // eslint-disable-next-line jest/no-conditional-expect expect(screen.getByText(body)).toBeInTheDocument(); } + // eslint-disable-next-line jest/no-conditional-in-test if (linkInfo) { const link = screen.getByRole('link', { name: linkInfo.name }); + // eslint-disable-next-line jest/no-conditional-expect expect(link).toBeInTheDocument(); + // eslint-disable-next-line jest/no-conditional-expect expect(link).toHaveAttribute('href', linkInfo.href); } } @@ -188,18 +193,26 @@ describe('Setup', () => { const title = await screen.findByRole('heading', { name: heading }); expect(title).toBeInTheDocument(); + // eslint-disable-next-line jest/no-conditional-in-test if (bodyText.length) { bodyText.forEach(text => { + // eslint-disable-next-line jest/no-conditional-expect expect(screen.getByText(text)).toBeInTheDocument(); }); } + // eslint-disable-next-line jest/no-conditional-in-test if (payload) { + // eslint-disable-next-line jest/no-conditional-expect expect(screen.getByText(payload.message)).toBeInTheDocument(); + // eslint-disable-next-line jest/no-conditional-expect expect(screen.getByText('background_tasks.table.started')).toBeInTheDocument(); } + // eslint-disable-next-line jest/no-conditional-in-test if (linkInfo) { const link = screen.getByRole('link', { name: linkInfo.name }); + // eslint-disable-next-line jest/no-conditional-expect expect(link).toBeInTheDocument(); + // eslint-disable-next-line jest/no-conditional-expect expect(link).toHaveAttribute('href', linkInfo.href); } } diff --git a/server/sonar-web/src/main/js/apps/marketplace/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/__tests__/App-test.tsx index 3f70f9d3676..98ad7ffbc8f 100644 --- a/server/sonar-web/src/main/js/apps/marketplace/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/marketplace/__tests__/App-test.tsx @@ -72,14 +72,14 @@ it('should handle accepting the risk', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getValue).toBeCalledWith({ key: SettingsKey.PluginRiskConsent }); + expect(getValue).toHaveBeenCalledWith({ key: SettingsKey.PluginRiskConsent }); wrapper.instance().acknowledgeRisk(); await new Promise(setImmediate); - expect(setSimpleSettingValue).toBeCalled(); - expect(getValue).toBeCalledWith({ key: SettingsKey.PluginRiskConsent }); + expect(setSimpleSettingValue).toHaveBeenCalled(); + expect(getValue).toHaveBeenCalledWith({ key: SettingsKey.PluginRiskConsent }); expect(wrapper.state().riskConsent).toBe(RiskConsent.Accepted); }); @@ -87,16 +87,16 @@ it('should fetch plugin info', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getInstalledPluginsWithUpdates).toBeCalled(); - expect(getAvailablePlugins).toBeCalled(); + expect(getInstalledPluginsWithUpdates).toHaveBeenCalled(); + expect(getAvailablePlugins).toHaveBeenCalled(); wrapper.setProps({ location: mockLocation({ query: { filter: 'updates' } }) }); await waitAndUpdate(wrapper); - expect(getPluginUpdates).toBeCalled(); + expect(getPluginUpdates).toHaveBeenCalled(); wrapper.setProps({ location: mockLocation({ query: { filter: 'installed' } }) }); await waitAndUpdate(wrapper); - expect(getInstalledPlugins).toBeCalled(); + expect(getInstalledPlugins).toHaveBeenCalled(); }); function shallowRender(props: Partial<App['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx index 11d5e0b9054..fba029f57fa 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx @@ -203,8 +203,8 @@ describe('project overview', () => { it("should correctly load a project's status", async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getQualityGateProjectStatus).toBeCalled(); - expect(getMeasuresWithPeriodAndMetrics).toBeCalled(); + expect(getQualityGateProjectStatus).toHaveBeenCalled(); + expect(getMeasuresWithPeriodAndMetrics).toHaveBeenCalled(); // Check the conditions got correctly enhanced with measure meta data. const { qgStatuses } = wrapper.state(); @@ -270,9 +270,9 @@ describe('application overview', () => { it("should correctly load an application's status", async () => { const wrapper = shallowRender({ component }); await waitAndUpdate(wrapper); - expect(getApplicationQualityGate).toBeCalled(); - expect(getApplicationLeak).toBeCalled(); - expect(getMeasuresWithPeriodAndMetrics).toBeCalled(); + expect(getApplicationQualityGate).toHaveBeenCalled(); + expect(getApplicationLeak).toHaveBeenCalled(); + expect(getMeasuresWithPeriodAndMetrics).toHaveBeenCalled(); // Check the conditions got correctly enhanced with measure meta data. const { qgStatuses } = wrapper.state(); @@ -339,8 +339,8 @@ describe('application overview', () => { it("should correctly load a component's history", async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getProjectActivity).toBeCalled(); - expect(getAllTimeMachineData).toBeCalled(); + expect(getProjectActivity).toHaveBeenCalled(); + expect(getAllTimeMachineData).toHaveBeenCalled(); const { measuresHistory } = wrapper.state(); expect(measuresHistory).toHaveLength(6); @@ -370,11 +370,15 @@ it.each([ it('should correctly handle graph type storage', () => { const wrapper = shallowRender(); - expect(getActivityGraph).toBeCalledWith(BRANCH_OVERVIEW_ACTIVITY_GRAPH, 'foo'); + expect(getActivityGraph).toHaveBeenCalledWith(BRANCH_OVERVIEW_ACTIVITY_GRAPH, 'foo'); expect(wrapper.state().graph).toBe(GraphType.coverage); wrapper.instance().handleGraphChange(GraphType.issues); - expect(saveActivityGraph).toBeCalledWith(BRANCH_OVERVIEW_ACTIVITY_GRAPH, 'foo', GraphType.issues); + expect(saveActivityGraph).toHaveBeenCalledWith( + BRANCH_OVERVIEW_ACTIVITY_GRAPH, + 'foo', + GraphType.issues + ); expect(wrapper.state().graph).toBe(GraphType.issues); }); diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/PullRequestOverview-test.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/PullRequestOverview-test.tsx index bc9d0207ff9..952f8c37802 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/PullRequestOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/PullRequestOverview-test.tsx @@ -73,8 +73,8 @@ it('should render correctly for a passed QG', async () => { expect(wrapper.find('QualityGateConditions').exists()).toBe(false); - expect(getMeasuresWithMetrics).toBeCalled(); - expect(fetchBranchStatus).toBeCalled(); + expect(getMeasuresWithMetrics).toHaveBeenCalled(); + expect(fetchBranchStatus).toHaveBeenCalled(); }); it('should render correctly if conditions are ignored', async () => { @@ -107,7 +107,7 @@ it('should render correctly for a failed QG', async () => { it('should correctly fetch all required metrics for a passing QG', async () => { const wrapper = shallowRender({ conditions: [] }); await waitAndUpdate(wrapper); - expect(getMeasuresWithMetrics).toBeCalledWith('my-project', PR_METRICS, expect.any(Object)); + expect(getMeasuresWithMetrics).toHaveBeenCalledWith('my-project', PR_METRICS, expect.any(Object)); }); it('should correctly fetch all required metrics for a failing QG', async () => { @@ -115,7 +115,7 @@ it('should correctly fetch all required metrics for a failing QG', async () => { conditions: [mockQualityGateStatusCondition({ level: 'ERROR', metric: 'foo' })] }); await waitAndUpdate(wrapper); - expect(getMeasuresWithMetrics).toBeCalledWith( + expect(getMeasuresWithMetrics).toHaveBeenCalledWith( 'my-project', [...PR_METRICS, 'foo'], expect.any(Object) diff --git a/server/sonar-web/src/main/js/apps/permissions/global/components/__tests__/AllHoldersList-test.tsx b/server/sonar-web/src/main/js/apps/permissions/global/components/__tests__/AllHoldersList-test.tsx index e68aac57038..08278fe5912 100644 --- a/server/sonar-web/src/main/js/apps/permissions/global/components/__tests__/AllHoldersList-test.tsx +++ b/server/sonar-web/src/main/js/apps/permissions/global/components/__tests__/AllHoldersList-test.tsx @@ -54,10 +54,10 @@ it('should correctly toggle user permissions', () => { const instance = wrapper.instance(); instance.handleToggleUser(user, grantPermission); - expect(grantPermissionToUser).toBeCalledWith(user.login, grantPermission); + expect(grantPermissionToUser).toHaveBeenCalledWith(user.login, grantPermission); instance.handleToggleUser(user, revokePermission); - expect(revokePermissionFromUser).toBeCalledWith(user.login, revokePermission); + expect(revokePermissionFromUser).toHaveBeenCalledWith(user.login, revokePermission); }); it('should correctly toggle group permissions', () => { @@ -70,10 +70,10 @@ it('should correctly toggle group permissions', () => { const instance = wrapper.instance(); instance.handleToggleGroup(group, grantPermission); - expect(grantPermissionToGroup).toBeCalledWith(group.name, grantPermission); + expect(grantPermissionToGroup).toHaveBeenCalledWith(group.name, grantPermission); instance.handleToggleGroup(group, revokePermission); - expect(revokePermissionFromGroup).toBeCalledWith(group.name, revokePermission); + expect(revokePermissionFromGroup).toHaveBeenCalledWith(group.name, revokePermission); }); function shallowRender(props: Partial<AllHoldersList['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx index c0ca44e0f9a..7d0397e728e 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysesList-test.tsx @@ -83,7 +83,7 @@ it('should correctly update the selected date', () => { const updateQuery = jest.fn(); const wrapper = shallowRender({ updateQuery }); wrapper.instance().updateSelectedDate(selectedDate); - expect(updateQuery).toBeCalledWith({ selectedDate }); + expect(updateQuery).toHaveBeenCalledWith({ selectedDate }); }); it('should correctly reset scroll if filters change', () => { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx index 7abfc29b774..45bdc5c08b6 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/__tests__/ProjectActivityAnalysis-test.tsx @@ -109,12 +109,12 @@ it('should be clickable', () => { const updateSelectedDate = jest.fn(); const wrapper = shallowRender({ analysis: mockParsedAnalysis({ date }), updateSelectedDate }); click(wrapper); - expect(updateSelectedDate).toBeCalledWith(date); + expect(updateSelectedDate).toHaveBeenCalledWith(date); }); it('should trigger a scroll to itself if selected', () => { mountRender({ parentScrollContainer: document.createElement('ul'), selected: true }); - expect(scrollToElement).toBeCalled(); + expect(scrollToElement).toHaveBeenCalled(); }); function shallowRender(props: Partial<ProjectActivityAnalysisProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx index f0133209832..984a48a2e6b 100644 --- a/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectActivity/components/forms/__tests__/RemoveEventForm-test.tsx @@ -31,14 +31,14 @@ it('should correctly confirm', () => { const onConfirm = jest.fn(); const wrapper = shallowRender({ onConfirm }); wrapper.find(ConfirmModal).prop('onConfirm')(); - expect(onConfirm).toBeCalledWith('foo', 'bar'); + expect(onConfirm).toHaveBeenCalledWith('foo', 'bar'); }); it('should correctly cancel', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); wrapper.find(ConfirmModal).prop('onClose')(); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); function shallowRender(props: Partial<RemoveEventFormProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx index 17d935e0480..1d011ee0d6e 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchAnalysisList-test.tsx @@ -80,7 +80,7 @@ it('should render correctly', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getProjectActivity).toBeCalled(); + expect(getProjectActivity).toHaveBeenCalled(); expect(wrapper.state().analyses).toHaveLength(4); }); @@ -89,7 +89,7 @@ it('should reload analyses after range change', () => { wrapper.instance().handleRangeChange({ value: 30 }); - expect(getProjectActivity).toBeCalledWith({ + expect(getProjectActivity).toHaveBeenCalledWith({ branch: 'master', project: 'project1', from: toShortNotSoISOString(subDays(new Date(), 30)) diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchList-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchList-test.tsx index 1d29ed3549b..f714c6f23d6 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchList-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchList-test.tsx @@ -56,7 +56,7 @@ it('should handle reset', () => { wrapper.instance().resetToDefault('master'); - expect(resetNewCodePeriod).toBeCalledWith({ + expect(resetNewCodePeriod).toHaveBeenCalledWith({ project: component.key, branch: 'master' }); diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchListRow-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchListRow-test.tsx index f0ae5029cc7..253441842a6 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchListRow-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/BranchListRow-test.tsx @@ -70,7 +70,7 @@ it('should callback to open modal when clicked', () => { .first() .simulate('click'); - expect(openEditModal).toBeCalledWith(branch); + expect(openEditModal).toHaveBeenCalledWith(branch); }); it('should callback to reset when clicked', () => { @@ -86,7 +86,7 @@ it('should callback to reset when clicked', () => { .at(1) .simulate('click'); - expect(resetToDefault).toBeCalledWith(branchName); + expect(resetToDefault).toHaveBeenCalledWith(branchName); }); function shallowRender(props: Partial<BranchListRowProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx index 1bf9474e8d3..7216b07cb1a 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchLikeTabs-test.tsx @@ -126,7 +126,7 @@ it('should correctly propagate an update of purge settings', () => { .props() .onUpdatePurgeSetting(); - expect(onBranchesChange).toBeCalled(); + expect(onBranchesChange).toHaveBeenCalled(); }); function shallowRender(props: Partial<BranchLikeTabs['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx index 9b3aa83041a..7d0cef9078a 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/BranchPurgeSetting-test.tsx @@ -55,7 +55,7 @@ it('should correctly call the webservice if the user changes the value', async ( expect(excludeBranchFromPurge).toHaveBeenCalled(); expect(wrapper.state().excludedFromPurge).toBe(true); await waitAndUpdate(wrapper); - expect(onUpdatePurgeSetting).toBeCalled(); + expect(onUpdatePurgeSetting).toHaveBeenCalled(); }); function shallowRender(props?: Partial<BranchPurgeSetting['props']>) { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx index 603d6673b63..a7f1c58ea07 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx @@ -53,8 +53,8 @@ it('deletes branch', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); - expect(onDelete).toBeCalled(); - expect(deleteBranch).toBeCalledWith({ branch: 'feature/foo', project: 'foo' }); + expect(onDelete).toHaveBeenCalled(); + expect(deleteBranch).toHaveBeenCalledWith({ branch: 'feature/foo', project: 'foo' }); }); it('deletes pull request', async () => { @@ -67,8 +67,8 @@ it('deletes pull request', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); - expect(onDelete).toBeCalled(); - expect(deletePullRequest).toBeCalledWith({ project: 'foo', pullRequest: '1001' }); + expect(onDelete).toHaveBeenCalled(); + expect(deletePullRequest).toHaveBeenCalledWith({ project: 'foo', pullRequest: '1001' }); }); it('cancels', () => { @@ -78,7 +78,7 @@ it('cancels', () => { click(wrapper.find('ResetButtonLink')); return doAsync().then(() => { - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); }); @@ -91,8 +91,8 @@ it('stops loading on WS error', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); - expect(onDelete).not.toBeCalled(); - expect(deleteBranch).toBeCalledWith({ branch: 'feature/foo', project: 'foo' }); + expect(onDelete).not.toHaveBeenCalled(); + expect(deleteBranch).toHaveBeenCalledWith({ branch: 'feature/foo', project: 'foo' }); }); function shallowRender( diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/RenameBranchModal-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/RenameBranchModal-test.tsx index e2ebc6830c9..e0b7c585b98 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/RenameBranchModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/RenameBranchModal-test.tsx @@ -49,8 +49,8 @@ it('renames branch', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); - expect(onRename).toBeCalled(); - expect(renameBranch).toBeCalledWith('foo', 'dev'); + expect(onRename).toHaveBeenCalled(); + expect(renameBranch).toHaveBeenCalledWith('foo', 'dev'); }); it('cancels', () => { @@ -60,7 +60,7 @@ it('cancels', () => { click(wrapper.find('ResetButtonLink')); return doAsync().then(() => { - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); }); @@ -73,7 +73,7 @@ it('stops loading on WS error', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); - expect(onRename).not.toBeCalled(); + expect(onRename).not.toHaveBeenCalled(); }); function shallowRender(onRename: () => void = jest.fn(), onClose: () => void = jest.fn()) { diff --git a/server/sonar-web/src/main/js/apps/projectDeletion/__tests__/Form-test.tsx b/server/sonar-web/src/main/js/apps/projectDeletion/__tests__/Form-test.tsx index cdedbe7df04..5f23662c5e6 100644 --- a/server/sonar-web/src/main/js/apps/projectDeletion/__tests__/Form-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectDeletion/__tests__/Form-test.tsx @@ -49,9 +49,9 @@ it('should delete project', async () => { const router = mockRouter(); const form = shallow(<Form component={component} router={router} />); form.prop<Function>('onConfirm')(); - expect(deleteProject).toBeCalledWith('foo'); + expect(deleteProject).toHaveBeenCalledWith('foo'); await new Promise(setImmediate); - expect(router.replace).toBeCalledWith('/'); + expect(router.replace).toHaveBeenCalledWith('/'); }); it('should delete portfolio', async () => { @@ -59,11 +59,11 @@ it('should delete portfolio', async () => { const router = mockRouter(); const form = shallow(<Form component={component} router={router} />); form.prop<Function>('onConfirm')(); - expect(deletePortfolio).toBeCalledWith('foo'); - expect(deleteProject).not.toBeCalled(); - expect(deleteApplication).not.toBeCalled(); + expect(deletePortfolio).toHaveBeenCalledWith('foo'); + expect(deleteProject).not.toHaveBeenCalled(); + expect(deleteApplication).not.toHaveBeenCalled(); await new Promise(setImmediate); - expect(router.replace).toBeCalledWith('/portfolios'); + expect(router.replace).toHaveBeenCalledWith('/portfolios'); }); it('should delete application', async () => { @@ -71,9 +71,9 @@ it('should delete application', async () => { const router = mockRouter(); const form = shallow(<Form component={component} router={router} />); form.prop<Function>('onConfirm')(); - expect(deleteApplication).toBeCalledWith('foo'); - expect(deleteProject).not.toBeCalled(); - expect(deletePortfolio).not.toBeCalled(); + expect(deleteApplication).toHaveBeenCalledWith('foo'); + expect(deleteProject).not.toHaveBeenCalled(); + expect(deletePortfolio).not.toHaveBeenCalled(); await new Promise(setImmediate); - expect(router.replace).toBeCalledWith('/'); + expect(router.replace).toHaveBeenCalledWith('/'); }); diff --git a/server/sonar-web/src/main/js/apps/projectKey/__tests__/Key-test.tsx b/server/sonar-web/src/main/js/apps/projectKey/__tests__/Key-test.tsx index bc9ba0fa64f..d7273ccb654 100644 --- a/server/sonar-web/src/main/js/apps/projectKey/__tests__/Key-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectKey/__tests__/Key-test.tsx @@ -36,8 +36,8 @@ it('should render and change key', async () => { wrapper.find('UpdateForm').prop<Function>('onKeyChange')('bar'); await new Promise(setImmediate); - expect(changeKey).toBeCalledWith({ from: 'foo', to: 'bar' }); - expect(withRouterProps.router.replace).toBeCalledWith({ + expect(changeKey).toHaveBeenCalledWith({ from: 'foo', to: 'bar' }); + expect(withRouterProps.router.replace).toHaveBeenCalledWith({ pathname: '/project/key', query: { id: 'bar' } }); diff --git a/server/sonar-web/src/main/js/apps/projectKey/__tests__/UpdateForm-test.tsx b/server/sonar-web/src/main/js/apps/projectKey/__tests__/UpdateForm-test.tsx index 330b0c77326..d34022f1cda 100644 --- a/server/sonar-web/src/main/js/apps/projectKey/__tests__/UpdateForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectKey/__tests__/UpdateForm-test.tsx @@ -30,6 +30,7 @@ it('should render', () => { expect(getForm(shallowRender())).toMatchSnapshot('form'); }); +// eslint-disable-next-line jest/expect-expect it('should correctly update the form', () => { const component = mockComponent(); const wrapper = shallowRender({ component }); @@ -49,6 +50,7 @@ it('should correctly update the form', () => { expectButtonDisabled(wrapper, SubmitButton).toBe(true); }); +// eslint-disable-next-line jest/expect-expect it('should correctly reset the form', () => { const component = mockComponent(); const wrapper = shallowRender({ component }); @@ -66,6 +68,7 @@ function expectButtonDisabled( wrapper: ShallowWrapper, button: React.ComponentType<{ disabled?: boolean }> ) { + // eslint-disable-next-line jest/valid-expect return expect( getForm(wrapper) .find(button) @@ -74,6 +77,7 @@ function expectButtonDisabled( } function expectProjectKeyInputValue(wrapper: ShallowWrapper) { + // eslint-disable-next-line jest/valid-expect return expect( getForm(wrapper) .find(ProjectKeyInput) diff --git a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/App-test.tsx index 6eabdd1a432..ac1ca9b97ee 100644 --- a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/App-test.tsx @@ -40,16 +40,16 @@ it('should fetch links and render', async () => { const wrapper = shallow(<App component={mockComponent({ key: 'comp' })} />); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(getProjectLinks).toBeCalledWith('comp'); + expect(getProjectLinks).toHaveBeenCalledWith('comp'); }); it('should fetch links when component changes', async () => { const wrapper = shallow(<App component={mockComponent({ key: 'comp' })} />); await waitAndUpdate(wrapper); - expect(getProjectLinks).lastCalledWith('comp'); + expect(getProjectLinks).toHaveBeenLastCalledWith('comp'); wrapper.setProps({ component: { key: 'another' } }); - expect(getProjectLinks).lastCalledWith('another'); + expect(getProjectLinks).toHaveBeenLastCalledWith('another'); }); it('should create link', async () => { @@ -59,7 +59,7 @@ it('should create link', async () => { wrapper.find('Header').prop<Function>('onCreate')('bar', 'http://example.com/bar'); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(createLink).toBeCalledWith({ + expect(createLink).toHaveBeenCalledWith({ name: 'bar', projectKey: 'comp', url: 'http://example.com/bar' @@ -73,5 +73,5 @@ it('should delete link', async () => { wrapper.find('Table').prop<Function>('onDelete')('foo'); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(deleteLink).toBeCalledWith('foo'); + expect(deleteLink).toHaveBeenCalledWith('foo'); }); diff --git a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/CreationModal-test.tsx b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/CreationModal-test.tsx index 64bea4bbfd1..d9241ed4b02 100644 --- a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/CreationModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/CreationModal-test.tsx @@ -33,5 +33,5 @@ it('should create link', () => { expect(form).toMatchSnapshot(); submit(wrapper); - expect(onSubmit).toBeCalledWith('foo', 'http://example.com/foo'); + expect(onSubmit).toHaveBeenCalledWith('foo', 'http://example.com/foo'); }); diff --git a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/Header-test.tsx index 125f4c2c07e..1112213136a 100644 --- a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/Header-test.tsx @@ -33,7 +33,7 @@ it('should open creation modal', () => { expect(wrapper.find('CreationModal').exists()).toBe(true); wrapper.find('CreationModal').prop<Function>('onSubmit')('foo', 'http://example.com/foo'); - expect(onCreate).toBeCalledWith('foo', 'http://example.com/foo'); + expect(onCreate).toHaveBeenCalledWith('foo', 'http://example.com/foo'); wrapper.find('CreationModal').prop<Function>('onClose')(); wrapper.update(); diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateApp-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateApp-test.tsx index 525826ad426..ca4e06e3f0f 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateApp-test.tsx @@ -78,15 +78,15 @@ it('renders correctly', async () => { it('correctly checks user permissions', () => { shallowRender({ component: mockComponent({ configuration: { showQualityGates: false } }) }); - expect(handleRequiredAuthorization).toBeCalled(); + expect(handleRequiredAuthorization).toHaveBeenCalled(); }); it('correctly loads Quality Gate data', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(fetchQualityGates).toBeCalled(); - expect(getGateForProject).toBeCalledWith({ project: 'foo' }); + expect(fetchQualityGates).toHaveBeenCalled(); + expect(getGateForProject).toHaveBeenCalledWith({ project: 'foo' }); expect(wrapper.state().allQualityGates).toHaveLength(4); expect(wrapper.state().currentQualityGate?.id).toBe('gate2'); @@ -100,7 +100,7 @@ it('correctly fallbacks to the default Quality Gate', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(searchProjects).toBeCalled(); + expect(searchProjects).toHaveBeenCalled(); expect(wrapper.state().currentQualityGate?.id).toBe('gate3'); expect(wrapper.state().selectedQualityGateId).toBe(USE_SYSTEM_DEFAULT); @@ -116,7 +116,7 @@ it('correctly detects if the default Quality Gate was explicitly selected', asyn const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(searchProjects).toBeCalled(); + expect(searchProjects).toHaveBeenCalled(); expect(wrapper.state().currentQualityGate?.id).toBe('gate3'); expect(wrapper.state().selectedQualityGateId).toBe('gate3'); diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateAppRenderer-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateAppRenderer-test.tsx index bbcf0ae7e0e..5833f2e2006 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateAppRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/ProjectQualityGateAppRenderer-test.tsx @@ -95,7 +95,7 @@ it('should correctly handle form submission', () => { const onSubmit = jest.fn(); const wrapper = shallowRender({ onSubmit }); submit(wrapper.find('form')); - expect(onSubmit).toBeCalled(); + expect(onSubmit).toHaveBeenCalled(); }); function shallowRender(props: Partial<ProjectQualityGateAppRendererProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProjectQualityProfilesApp-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProjectQualityProfilesApp-test.tsx index ffc9eb0f6a0..61780787bd0 100644 --- a/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProjectQualityProfilesApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectQualityProfiles/__tests__/ProjectQualityProfilesApp-test.tsx @@ -88,15 +88,15 @@ it('correctly checks permissions', () => { component: mockComponent({ configuration: { showQualityProfiles: false } }) }); expect(wrapper.type()).toBeNull(); - expect(handleRequiredAuthorization).toBeCalled(); + expect(handleRequiredAuthorization).toHaveBeenCalled(); }); it('correctly fetches and treats profile data', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(searchQualityProfiles).toBeCalled(); - expect(getProfileProjects).toBeCalledTimes(10); + expect(searchQualityProfiles).toHaveBeenCalled(); + expect(getProfileProjects).toHaveBeenCalledTimes(10); expect(wrapper.state().projectProfiles).toEqual([ expect.objectContaining({ @@ -161,7 +161,7 @@ it('correctly sets a profile', async () => { (dissociateProject as jest.Mock).mockClear(); instance.handleSetProfile(undefined, 'ts_default'); // It won't call the WS. - expect(dissociateProject).not.toBeCalled(); + expect(dissociateProject).not.toHaveBeenCalled(); // Associate a default profile that was already inherited. instance.handleSetProfile('ts_default', 'ts_default'); diff --git a/server/sonar-web/src/main/js/apps/projects/__tests__/utils-test.ts b/server/sonar-web/src/main/js/apps/projects/__tests__/utils-test.ts index 62a21954818..95d48eedcf6 100644 --- a/server/sonar-web/src/main/js/apps/projects/__tests__/utils-test.ts +++ b/server/sonar-web/src/main/js/apps/projects/__tests__/utils-test.ts @@ -86,7 +86,7 @@ describe('formatDuration', () => { describe('fetchProjects', () => { it('correctly converts the passed arguments to the desired query format', async () => { await utils.fetchProjects({}, true); - expect(searchProjects).toBeCalledWith({ + expect(searchProjects).toHaveBeenCalledWith({ f: 'analysisDate,leakPeriodDate', facets: utils.FACETS.join(), filter: 'isFavorite', @@ -95,7 +95,7 @@ describe('fetchProjects', () => { }); await utils.fetchProjects({ view: 'leak' }, false, 3); - expect(searchProjects).toBeCalledWith({ + expect(searchProjects).toHaveBeenCalledWith({ f: 'analysisDate,leakPeriodDate', facets: utils.LEAK_FACETS.join(), p: 3, 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 4d2e70ff7cc..d421dcd7250 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 @@ -76,7 +76,7 @@ it('renders', () => { it('fetches projects', () => { shallowRender(); - expect(fetchProjects).lastCalledWith( + expect(fetchProjects).toHaveBeenLastCalledWith( { coverage: undefined, duplications: undefined, @@ -105,15 +105,15 @@ it('changes sort', () => { const push = jest.fn(); const wrapper = shallowRender({}, push); wrapper.find('PageHeader').prop<Function>('onSortChange')('size', false); - expect(push).lastCalledWith({ pathname: '/projects', query: { sort: 'size' } }); - expect(save).lastCalledWith(LS_PROJECTS_SORT, 'size'); + expect(push).toHaveBeenLastCalledWith({ pathname: '/projects', query: { sort: 'size' } }); + expect(save).toHaveBeenLastCalledWith(LS_PROJECTS_SORT, 'size'); }); it('changes perspective to leak', () => { const push = jest.fn(); const wrapper = shallowRender({}, push); wrapper.find('PageHeader').prop<Function>('onPerspectiveChange')({ view: 'leak' }); - expect(push).lastCalledWith({ + expect(push).toHaveBeenLastCalledWith({ pathname: '/projects', query: { view: 'leak' } }); @@ -128,7 +128,7 @@ it('updates sorting when changing perspective from leak', () => { wrapper.find('PageHeader').prop<Function>('onPerspectiveChange')({ view: undefined }); - expect(push).lastCalledWith({ + expect(push).toHaveBeenLastCalledWith({ pathname: '/projects', query: { sort: 'coverage', view: undefined } }); diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ApplicationCreation-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ApplicationCreation-test.tsx index 163991f0357..5b18c72b5f1 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ApplicationCreation-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ApplicationCreation-test.tsx @@ -50,7 +50,7 @@ it('should show form and callback when submitted - admin', async () => { await openAndSubmitForm(wrapper); - expect(routerPush).toBeCalledWith({ + expect(routerPush).toHaveBeenCalledWith({ pathname: '/project/admin/extension/developer-server/application-console', search: queryToSearch({ id: 'new app' @@ -67,7 +67,7 @@ it('should show form and callback when submitted - user', async () => { await openAndSubmitForm(wrapper); - expect(routerPush).toBeCalledWith({ + expect(routerPush).toHaveBeenCalledWith({ pathname: '/dashboard', search: queryToSearch({ id: 'new app' @@ -84,7 +84,7 @@ async function openAndSubmitForm(wrapper: ShallowWrapper) { await creationForm .props() .onCreate({ key: 'new app', qualifier: ComponentQualifier.Application }); - expect(getComponentNavigation).toBeCalled(); + expect(getComponentNavigation).toHaveBeenCalled(); expect(wrapper.find(CreateApplicationForm).exists()).toBe(false); } diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ClearAll-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ClearAll-test.tsx index 65994228854..6f54f7b0e82 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ClearAll-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ClearAll-test.tsx @@ -30,5 +30,5 @@ it('clears all', () => { const onClearAll = jest.fn(); const wrapper = shallow(<ClearAll onClearAll={onClearAll} />); click(wrapper.find('Button')); - expect(onClearAll).toBeCalled(); + expect(onClearAll).toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/FavoriteFilter-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/FavoriteFilter-test.tsx index d319f497c22..e73d336070b 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/FavoriteFilter-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/FavoriteFilter-test.tsx @@ -40,8 +40,8 @@ beforeEach(() => { it('renders for logged in user', () => { renderFavoriteFilter(); - expect(screen.queryByText('my_favorites')).toBeInTheDocument(); - expect(screen.queryByText('all')).toBeInTheDocument(); + expect(screen.getByText('my_favorites')).toBeInTheDocument(); + expect(screen.getByText('all')).toBeInTheDocument(); }); it.each([ diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx index c397641c7b7..99527aabf64 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/PageSidebar-test.tsx @@ -82,7 +82,7 @@ it('should allow to clear all filters', async () => { await user.click(clearAllButton); - expect(onClearAll).toBeCalled(); + expect(onClearAll).toHaveBeenCalled(); expect(screen.getByRole('heading', { level: 2, name: 'filters' })).toHaveFocus(); }); diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx index 8ead3e7f67d..dcec3a7f924 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectCreationMenu-test.tsx @@ -43,13 +43,13 @@ it('should render correctly', () => { it('should fetch alm bindings on mount', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getAlmSettings).toBeCalled(); + expect(getAlmSettings).toHaveBeenCalled(); }); it('should not fetch alm bindings if user cannot create projects', async () => { const wrapper = shallowRender({ currentUser: mockLoggedInUser({ permissions: { global: [] } }) }); await waitAndUpdate(wrapper); - expect(getAlmSettings).not.toBeCalled(); + expect(getAlmSettings).not.toHaveBeenCalled(); }); it('should filter alm bindings appropriately', async () => { diff --git a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectsSortingSelect-test.tsx b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectsSortingSelect-test.tsx index f22439481bb..59265f71882 100644 --- a/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectsSortingSelect-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/components/__tests__/ProjectsSortingSelect-test.tsx @@ -71,14 +71,14 @@ it('changes sorting', () => { onChange }).instance() as ProjectsSortingSelect; instance.handleSortChange({ label: 'size', value: 'size' }); - expect(onChange).toBeCalledWith('size', true); + expect(onChange).toHaveBeenCalledWith('size', true); }); it('reverses sorting', () => { const onChange = jest.fn(); const wrapper = shallowRender({ selectedSort: '-size', onChange }); click(wrapper.find('ButtonIcon')); - expect(onChange).toBeCalledWith('size', false); + expect(onChange).toHaveBeenCalledWith('size', false); const node = document.createElement('div'); node.focus = jest.fn(); @@ -86,7 +86,7 @@ it('reverses sorting', () => { click(wrapper.find('ButtonIcon')); - expect(node.focus).toBeCalled(); + expect(node.focus).toHaveBeenCalled(); }); function shallowRender(overrides: Partial<ProjectsSortingSelect['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/Filter-test.tsx b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/Filter-test.tsx index c2f55eed29f..55e27e8b196 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/Filter-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/Filter-test.tsx @@ -67,13 +67,13 @@ it('should handle click when value is single', () => { // select wrapper.instance().handleClick(mockEvent({ currentTarget: { dataset: { key: 'option2' } } })); - expect(onQueryChange).toBeCalledWith({ foo: 'option2' }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: 'option2' }); onQueryChange.mockClear(); // deselect wrapper.instance().handleClick(mockEvent({ currentTarget: { dataset: { key: 'option1' } } })); - expect(onQueryChange).toBeCalledWith({ foo: null }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: null }); }); it('should handle click when value is array', () => { @@ -82,13 +82,13 @@ it('should handle click when value is array', () => { // select one wrapper.instance().handleClick(mockEvent({ currentTarget: { dataset: { key: 'option2' } } })); - expect(onQueryChange).toBeCalledWith({ foo: 'option2' }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: 'option2' }); onQueryChange.mockClear(); // select other wrapper.instance().handleClick(mockEvent({ currentTarget: { dataset: { key: 'option3' } } })); - expect(onQueryChange).toBeCalledWith({ foo: 'option3' }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: 'option3' }); onQueryChange.mockClear(); @@ -96,7 +96,7 @@ it('should handle click when value is array', () => { wrapper .instance() .handleClick(mockEvent({ ctrlKey: true, currentTarget: { dataset: { key: 'option3' } } })); - expect(onQueryChange).toBeCalledWith({ foo: 'option1,option2,option3' }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: 'option1,option2,option3' }); onQueryChange.mockClear(); @@ -104,7 +104,7 @@ it('should handle click when value is array', () => { wrapper .instance() .handleClick(mockEvent({ metaKey: true, currentTarget: { dataset: { key: 'option2' } } })); - expect(onQueryChange).toBeCalledWith({ foo: 'option1' }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: 'option1' }); }); it('should handle click when value is array with one value', () => { @@ -115,13 +115,13 @@ it('should handle click when value is array with one value', () => { wrapper .instance() .handleClick(mockEvent({ ctrlKey: true, currentTarget: { dataset: { key: 'option1' } } })); - expect(onQueryChange).toBeCalledWith({ foo: null }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: null }); onQueryChange.mockClear(); // deselect one wrapper.instance().handleClick(mockEvent({ currentTarget: { dataset: { key: 'option1' } } })); - expect(onQueryChange).toBeCalledWith({ foo: null }); + expect(onQueryChange).toHaveBeenCalledWith({ foo: null }); }); function shallowRender(overrides: Partial<Filter['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchFilterContainer-test.tsx b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchFilterContainer-test.tsx index ef41a2f23f3..892d8127912 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchFilterContainer-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchFilterContainer-test.tsx @@ -26,5 +26,5 @@ it('searches', () => { const wrapper = shallow(<SearchFilterContainer onQueryChange={onQueryChange} query={{}} />); expect(wrapper).toMatchSnapshot(); wrapper.find('SearchBox').prop<Function>('onChange')('foo'); - expect(onQueryChange).toBeCalledWith({ search: 'foo' }); + expect(onQueryChange).toHaveBeenCalledWith({ search: 'foo' }); }); diff --git a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx index bb2c4c8e841..5f72037d3a5 100644 --- a/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx +++ b/server/sonar-web/src/main/js/apps/projects/filters/__tests__/SearchableFilterFooter-test.tsx @@ -52,5 +52,5 @@ it('should properly handle a change of the facet value', () => { /> ); wrapper.find(Select).simulate('change', { value: 'js' }); - expect(onQueryChange).toBeCalledWith({ languages: 'java,js' }); + expect(onQueryChange).toHaveBeenCalledWith({ languages: 'java,js' }); }); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/BulkApplyTemplateModal-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/BulkApplyTemplateModal-test.tsx index c99ee490c31..82cefd7049a 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/BulkApplyTemplateModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/BulkApplyTemplateModal-test.tsx @@ -39,7 +39,7 @@ beforeEach(() => { it('fetches permission templates on component mount', () => { shallow(render()); - expect(getPermissionTemplates).toBeCalled(); + expect(getPermissionTemplates).toHaveBeenCalled(); }); it('bulk applies template to all results', async () => { @@ -58,7 +58,7 @@ it('bulk applies template to all results', async () => { expect(wrapper).toMatchSnapshot(); click(wrapper.find('SubmitButton')); - expect(bulkApplyTemplate).toBeCalledWith({ + expect(bulkApplyTemplate).toHaveBeenCalledWith({ analyzedBefore: '2017-04-08T00:00:00+0000', onProvisionedOnly: true, q: 'bla', @@ -89,7 +89,7 @@ it('bulk applies template to selected results', async () => { click(wrapper.find('SubmitButton')); expect(wrapper).toMatchSnapshot(); await new Promise(setImmediate); - expect(bulkApplyTemplate).toBeCalledWith({ + expect(bulkApplyTemplate).toHaveBeenCalledWith({ projects: 'proj1,proj2', qualifiers: 'VW', templateId: 'foo' @@ -103,7 +103,7 @@ it('closes', () => { const onClose = jest.fn(); const wrapper = shallow(render({ onClose })); click(wrapper.find('ResetButtonLink')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); function render(props?: { [P in keyof Props]?: Props[P] }) { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ChangeDefaultVisibilityForm-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ChangeDefaultVisibilityForm-test.tsx index 2142c8ea864..1b0f82333ae 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ChangeDefaultVisibilityForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ChangeDefaultVisibilityForm-test.tsx @@ -27,7 +27,7 @@ it('closes', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); click(wrapper.find('.js-modal-close')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); it('changes visibility', () => { @@ -43,7 +43,7 @@ it('changes visibility', () => { expect(wrapper).toMatchSnapshot(); click(wrapper.find('.js-confirm')); - expect(onConfirm).toBeCalledWith('private'); + expect(onConfirm).toHaveBeenCalledWith('private'); }); function shallowRender(props: Partial<ChangeDefaultVisibilityForm['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/CreateProjectForm-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/CreateProjectForm-test.tsx index adbe7b98c00..34923e19f20 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/CreateProjectForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/CreateProjectForm-test.tsx @@ -53,7 +53,7 @@ it('creates project', async () => { expect(wrapper).toMatchSnapshot(); submit(wrapper.find('form')); - expect(createProject).toBeCalledWith({ + expect(createProject).toHaveBeenCalledWith({ name: 'name', project: 'key', visibility: 'private' diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/DeleteModal-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/DeleteModal-test.tsx index 950fca9ecf5..56ce100aa29 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/DeleteModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/DeleteModal-test.tsx @@ -42,7 +42,7 @@ it('deletes all projects', async () => { click(wrapper.find('SubmitButton')); expect(wrapper).toMatchSnapshot(); - expect(bulkDeleteProjects).toBeCalledWith({ + expect(bulkDeleteProjects).toHaveBeenCalledWith({ analyzedBefore: '2017-04-08T00:00:00+0000', onProvisionedOnly: undefined, q: 'bla', @@ -50,7 +50,7 @@ it('deletes all projects', async () => { }); await new Promise(setImmediate); - expect(onConfirm).toBeCalled(); + expect(onConfirm).toHaveBeenCalled(); }); it('deletes selected projects', async () => { @@ -61,17 +61,17 @@ it('deletes selected projects', async () => { click(wrapper.find('SubmitButton')); expect(wrapper).toMatchSnapshot(); - expect(bulkDeleteProjects).toBeCalledWith({ projects: 'proj1,proj2' }); + expect(bulkDeleteProjects).toHaveBeenCalledWith({ projects: 'proj1,proj2' }); await new Promise(setImmediate); - expect(onConfirm).toBeCalled(); + expect(onConfirm).toHaveBeenCalled(); }); it('closes', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); click(wrapper.find('ResetButtonLink')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); function shallowRender(props?: { [P in keyof Props]?: Props[P] }) { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx index fb55e6dee3b..e75d1f6192a 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Header-test.tsx @@ -37,7 +37,7 @@ it('creates project', () => { const onProjectCreate = jest.fn(); const wrapper = shallowRender({ onProjectCreate }); click(wrapper.find('#create-project')); - expect(onProjectCreate).toBeCalledWith(); + expect(onProjectCreate).toHaveBeenCalledWith(); }); it('changes default visibility', () => { @@ -49,7 +49,7 @@ it('changes default visibility', () => { const modalWrapper = wrapper.find('ChangeDefaultVisibilityForm'); expect(modalWrapper).toMatchSnapshot(); modalWrapper.prop<Function>('onConfirm')('private'); - expect(onChangeDefaultProjectVisibility).toBeCalledWith('private'); + expect(onChangeDefaultProjectVisibility).toHaveBeenCalledWith('private'); modalWrapper.prop<Function>('onClose')(); wrapper.update(); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx index 0c39eeebfc6..941d42cad6f 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx @@ -74,7 +74,7 @@ describe('Bulk Apply', () => { await user.click(screen.getByRole('checkbox', { name: 'check_all' })); - expect(bulkApplyButton).not.toBeDisabled(); + expect(bulkApplyButton).toBeEnabled(); await user.click(bulkApplyButton); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-test.tsx index acde1180943..f429ee2b454 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-test.tsx @@ -57,15 +57,15 @@ beforeEach(() => { it('fetches all projects on mount', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getComponents).lastCalledWith({ ...defaultSearchParameters, qualifiers: 'TRK' }); - expect(getValue).toBeCalled(); + expect(getComponents).toHaveBeenLastCalledWith({ ...defaultSearchParameters, qualifiers: 'TRK' }); + expect(getValue).toHaveBeenCalled(); expect(wrapper.state().defaultProjectVisibility).toBe('public'); }); it('selects provisioned', () => { const wrapper = shallowRender(); wrapper.find('withAppStateContext(Search)').prop<Function>('onProvisionedChanged')(true); - expect(getComponents).lastCalledWith({ + expect(getComponents).toHaveBeenLastCalledWith({ ...defaultSearchParameters, onProvisionedOnly: true, qualifiers: 'TRK' @@ -76,13 +76,17 @@ it('changes qualifier and resets provisioned', () => { const wrapper = shallowRender(); wrapper.setState({ provisioned: true }); wrapper.find('withAppStateContext(Search)').prop<Function>('onQualifierChanged')('VW'); - expect(getComponents).lastCalledWith({ ...defaultSearchParameters, qualifiers: 'VW' }); + expect(getComponents).toHaveBeenLastCalledWith({ ...defaultSearchParameters, qualifiers: 'VW' }); }); it('searches', () => { const wrapper = shallowRender(); wrapper.find('withAppStateContext(Search)').prop<Function>('onSearch')('foo'); - expect(getComponents).lastCalledWith({ ...defaultSearchParameters, q: 'foo', qualifiers: 'TRK' }); + expect(getComponents).toHaveBeenLastCalledWith({ + ...defaultSearchParameters, + q: 'foo', + qualifiers: 'TRK' + }); }); it('should handle date filtering', () => { @@ -105,7 +109,7 @@ it('should handle default project visibility change', async () => { expect(wrapper.state().defaultProjectVisibility).toBe('public'); wrapper.instance().handleDefaultProjectVisibilityChange('private'); - expect(changeProjectDefaultVisibility).toBeCalledWith('private'); + expect(changeProjectDefaultVisibility).toHaveBeenCalledWith('private'); await waitAndUpdate(wrapper); expect(wrapper.state().defaultProjectVisibility).toBe('private'); }); @@ -113,7 +117,11 @@ it('should handle default project visibility change', async () => { it('loads more', () => { const wrapper = shallowRender(); wrapper.find('ListFooter').prop<Function>('loadMore')(); - expect(getComponents).lastCalledWith({ ...defaultSearchParameters, p: 2, qualifiers: 'TRK' }); + expect(getComponents).toHaveBeenLastCalledWith({ + ...defaultSearchParameters, + p: 2, + qualifiers: 'TRK' + }); }); it('selects and deselects projects', async () => { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRow-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRow-test.tsx index 3a350b136fc..49d9a68c23d 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRow-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRow-test.tsx @@ -43,7 +43,7 @@ it('checks project', () => { const onProjectCheck = jest.fn(); const wrapper = shallowRender({ onProjectCheck }); wrapper.find('Checkbox').prop<Function>('onCheck')(false); - expect(onProjectCheck).toBeCalledWith(project, false); + expect(onProjectCheck).toHaveBeenCalledWith(project, false); }); function shallowRender(props?: any) { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRowActions-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRowActions-test.tsx index 8a8b3f2e706..fbd7d650ca0 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRowActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectRowActions-test.tsx @@ -52,7 +52,7 @@ describe('restore access', () => { wrapper.instance().handleDropdownOpen(); await waitAndUpdate(wrapper); - expect(getComponentNavigation).toBeCalledWith({ component: 'foo' }); + expect(getComponentNavigation).toHaveBeenCalledWith({ component: 'foo' }); expect(wrapper.find('.js-restore-access').exists()).toBe(true); }); @@ -79,7 +79,7 @@ describe('restore access', () => { wrapper.instance().handleDropdownOpen(); await waitAndUpdate(wrapper); - expect(getComponentNavigation).toBeCalledWith({ component: 'foo' }); + expect(getComponentNavigation).toHaveBeenCalledWith({ component: 'foo' }); expect(wrapper.find('.js-restore-access').exists()).toBe(true); }); }); diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Projects-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Projects-test.tsx index 05a484f1e86..c68940fd71e 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Projects-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Projects-test.tsx @@ -40,13 +40,13 @@ it('selects and deselects project', () => { .find('ProjectRow') .first() .prop<Function>('onProjectCheck')(projects[0], true); - expect(onProjectSelected).toBeCalledWith('a'); + expect(onProjectSelected).toHaveBeenCalledWith('a'); wrapper .find('ProjectRow') .first() .prop<Function>('onProjectCheck')(projects[0], false); - expect(onProjectDeselected).toBeCalledWith('a'); + expect(onProjectDeselected).toHaveBeenCalledWith('a'); }); function shallowRender(props?: any) { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx index cefcf3afdef..55aae869581 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/Search-test.tsx @@ -53,7 +53,7 @@ it('updates qualifier', () => { wrapper.find('Select[name="projects-qualifier"]').simulate('change', { value: 'VW' }); - expect(onQualifierChanged).toBeCalledWith('VW'); + expect(onQualifierChanged).toHaveBeenCalledWith('VW'); }); it('renders optionrenderer and singlevaluerenderer', () => { @@ -74,7 +74,7 @@ it('selects provisioned', () => { const onProvisionedChanged = jest.fn(); const wrapper = shallowRender({ onProvisionedChanged }); wrapper.find('Checkbox[id="projects-provisioned"]').prop<Function>('onCheck')(true); - expect(onProvisionedChanged).toBeCalledWith(true); + expect(onProvisionedChanged).toHaveBeenCalledWith(true); }); it('does not render provisioned filter for portfolios', () => { @@ -89,17 +89,17 @@ it('updates analysis date', () => { const wrapper = shallowRender({ onDateChanged }); wrapper.find('DateInput').prop<Function>('onChange')('2017-04-08T00:00:00.000Z'); - expect(onDateChanged).toBeCalledWith('2017-04-08T00:00:00.000Z'); + expect(onDateChanged).toHaveBeenCalledWith('2017-04-08T00:00:00.000Z'); wrapper.find('DateInput').prop<Function>('onChange')(undefined); - expect(onDateChanged).toBeCalledWith(undefined); + expect(onDateChanged).toHaveBeenCalledWith(undefined); }); it('searches', () => { const onSearch = jest.fn(); const wrapper = shallowRender({ onSearch }); wrapper.find('SearchBox').prop<Function>('onChange')('foo'); - expect(onSearch).toBeCalledWith('foo'); + expect(onSearch).toHaveBeenCalledWith('foo'); }); it('checks all or none projects', () => { @@ -108,10 +108,10 @@ it('checks all or none projects', () => { const wrapper = shallowRender({ onAllDeselected, onAllSelected }); wrapper.find('Checkbox[id="projects-selection"]').prop<Function>('onCheck')(true); - expect(onAllSelected).toBeCalled(); + expect(onAllSelected).toHaveBeenCalled(); wrapper.find('Checkbox[id="projects-selection"]').prop<Function>('onCheck')(false); - expect(onAllDeselected).toBeCalled(); + expect(onAllDeselected).toHaveBeenCalled(); }); it('deletes projects', () => { @@ -120,7 +120,7 @@ it('deletes projects', () => { click(wrapper.find('.js-delete')); expect(wrapper.find('DeleteModal')).toMatchSnapshot(); wrapper.find('DeleteModal').prop<Function>('onConfirm')(); - expect(onDeleteProjects).toBeCalled(); + expect(onDeleteProjects).toHaveBeenCalled(); }); it('bulk applies permission template', () => { diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/App-it.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/App-it.tsx index a6aedcef3fb..76c998fc6b3 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/App-it.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/App-it.tsx @@ -319,6 +319,9 @@ describe('The Project section', () => { const reloadButton = screen.getByRole('button', { name: 'reload' }); expect(reloadButton).toBeInTheDocument(); await user.click(reloadButton); + + // FP + // eslint-disable-next-line jest-dom/prefer-in-document expect(screen.getAllByRole('checkbox')).toHaveLength(1); // change tabs to show deselected projects @@ -345,6 +348,9 @@ describe('The Project section', () => { expect(searchInput).toBeInTheDocument(); await user.click(searchInput); await user.keyboard('test2{Enter}'); + + // FP + // eslint-disable-next-line jest-dom/prefer-in-document expect(screen.getAllByRole('checkbox')).toHaveLength(1); }); @@ -424,6 +430,9 @@ describe('The Permissions section', () => { name: 'cancel' }); await user.click(cancelButton); + + // FP + // eslint-disable-next-line jest-dom/prefer-in-document expect(screen.getAllByRole('listitem')).toHaveLength(1); // Delete the user permission diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.tsx index 2f7b0d73951..0c41ffa2862 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogSearch-test.tsx @@ -49,7 +49,7 @@ it('should reset', () => { onReset={onReset} /> ); - expect(onReset).not.toBeCalled(); + expect(onReset).not.toHaveBeenCalled(); click(output.find('Button')); - expect(onReset).toBeCalled(); + expect(onReset).toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/DeleteProfileForm-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/DeleteProfileForm-test.tsx index 567a1a1d0fc..8ebdea4c89f 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/DeleteProfileForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/DeleteProfileForm-test.tsx @@ -39,7 +39,7 @@ it('should correctly submit the form', () => { if (formOnSubmit) { formOnSubmit(mockEvent()); } - expect(onDelete).toBeCalled(); + expect(onDelete).toHaveBeenCalled(); }); function shallowRender(props: Partial<DeleteProfileFormProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx index 6f657c9da7f..6c72b8a87a7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx @@ -114,11 +114,11 @@ describe('copy a profile', () => { .find(ProfileModalForm) .props() .onSubmit(name); - expect(copyProfile).toBeCalledWith(PROFILE.key, name); + expect(copyProfile).toHaveBeenCalledWith(PROFILE.key, name); await waitAndUpdate(wrapper); - expect(updateProfiles).toBeCalled(); - expect(push).toBeCalledWith({ + expect(updateProfiles).toHaveBeenCalled(); + expect(push).toHaveBeenCalledWith({ pathname: '/profiles/show', search: queryToSearch({ name, language: 'js' }) }); @@ -141,10 +141,10 @@ describe('copy a profile', () => { wrapper.instance().handleProfileCopy(name); await waitAndUpdate(wrapper); - expect(updateProfiles).not.toBeCalled(); + expect(updateProfiles).not.toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(push).not.toBeCalled(); + expect(push).not.toHaveBeenCalled(); expect(wrapper.state().openModal).toBe(ProfileActionModals.Copy); }); }); @@ -168,9 +168,9 @@ describe('extend a profile', () => { .find(ProfileModalForm) .props() .onSubmit(name); - expect(createQualityProfile).toBeCalledWith({ language: profile.language, name }); + expect(createQualityProfile).toHaveBeenCalledWith({ language: profile.language, name }); await waitAndUpdate(wrapper); - expect(changeProfileParent).toBeCalledWith( + expect(changeProfileParent).toHaveBeenCalledWith( expect.objectContaining({ key: 'newProfile' }), @@ -178,10 +178,10 @@ describe('extend a profile', () => { ); await waitAndUpdate(wrapper); - expect(updateProfiles).toBeCalled(); + expect(updateProfiles).toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(push).toBeCalledWith({ + expect(push).toHaveBeenCalledWith({ pathname: '/profiles/show', search: queryToSearch({ name, language: 'js' }) }); @@ -204,9 +204,9 @@ describe('extend a profile', () => { wrapper.instance().handleProfileExtend(name); await waitAndUpdate(wrapper); - expect(updateProfiles).not.toBeCalled(); - expect(changeProfileParent).not.toBeCalled(); - expect(push).not.toBeCalled(); + expect(updateProfiles).not.toHaveBeenCalled(); + expect(changeProfileParent).not.toHaveBeenCalled(); + expect(push).not.toHaveBeenCalled(); expect(wrapper.state().openModal).toBe(ProfileActionModals.Extend); }); }); @@ -229,11 +229,11 @@ describe('rename a profile', () => { .find(ProfileModalForm) .props() .onSubmit(name); - expect(renameProfile).toBeCalledWith(PROFILE.key, name); + expect(renameProfile).toHaveBeenCalledWith(PROFILE.key, name); await waitAndUpdate(wrapper); - expect(updateProfiles).toBeCalled(); - expect(push).toBeCalledWith({ + expect(updateProfiles).toHaveBeenCalled(); + expect(push).toHaveBeenCalledWith({ pathname: '/profiles/show', search: queryToSearch({ name, language: 'js' }) }); @@ -256,10 +256,10 @@ describe('rename a profile', () => { wrapper.instance().handleProfileRename(name); await waitAndUpdate(wrapper); - expect(updateProfiles).not.toBeCalled(); + expect(updateProfiles).not.toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(push).not.toBeCalled(); + expect(push).not.toHaveBeenCalled(); expect(wrapper.state().openModal).toBe(ProfileActionModals.Rename); }); }); @@ -282,11 +282,11 @@ describe('delete a profile', () => { .find(DeleteProfileForm) .props() .onDelete(); - expect(deleteProfile).toBeCalledWith(profile); + expect(deleteProfile).toHaveBeenCalledWith(profile); await waitAndUpdate(wrapper); - expect(updateProfiles).toBeCalled(); - expect(replace).toBeCalledWith(PROFILE_PATH); + expect(updateProfiles).toHaveBeenCalled(); + expect(replace).toHaveBeenCalledWith(PROFILE_PATH); expect(wrapper.find(ProfileModalForm).exists()).toBe(false); }); @@ -305,10 +305,10 @@ describe('delete a profile', () => { wrapper.instance().handleProfileDelete(); await waitAndUpdate(wrapper); - expect(updateProfiles).not.toBeCalled(); + expect(updateProfiles).not.toHaveBeenCalled(); await waitAndUpdate(wrapper); - expect(replace).not.toBeCalled(); + expect(replace).not.toHaveBeenCalled(); expect(wrapper.state().openModal).toBe(ProfileActionModals.Delete); }); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileModalForm-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileModalForm-test.tsx index d33c6e4fee8..c34378f48fd 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileModalForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileModalForm-test.tsx @@ -41,7 +41,7 @@ it('should correctly submit the form', () => { if (formOnSubmit) { formOnSubmit(mockEvent()); } - expect(onSubmit).not.toBeCalled(); + expect(onSubmit).not.toHaveBeenCalled(); // Input a new name. change(wrapper.find('#profile-name'), 'new name'); @@ -51,7 +51,7 @@ it('should correctly submit the form', () => { if (formOnSubmit) { formOnSubmit(mockEvent()); } - expect(onSubmit).toBeCalledWith('new name'); + expect(onSubmit).toHaveBeenCalledWith('new name'); }); function shallowRender(props: Partial<ProfileModalFormProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/QualityProfilesApp-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/QualityProfilesApp-test.tsx index b8acc4ca54e..f1d6fb52311 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/QualityProfilesApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/QualityProfilesApp-test.tsx @@ -37,8 +37,8 @@ it('should render correctly', async () => { const wrapper = shallowRender(); expect(wrapper).toMatchSnapshot('loading'); - expect(getExporters).toBeCalled(); - expect(searchQualityProfiles).toBeCalled(); + expect(getExporters).toHaveBeenCalled(); + expect(searchQualityProfiles).toHaveBeenCalled(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot('full'); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx index a0387409885..5b8dee2a8d7 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissions-test.tsx @@ -49,8 +49,8 @@ it('should update correctly', () => { wrapper.setProps({ profile: { key: 'otherKey', name: 'new profile', language: 'js' } }); - expect(searchGroups).toBeCalledTimes(2); - expect(searchUsers).toBeCalledTimes(2); + expect(searchGroups).toHaveBeenCalledTimes(2); + expect(searchUsers).toHaveBeenCalledTimes(2); }); it('opens add users form', async () => { @@ -107,12 +107,12 @@ it('removes group', () => { it('fetches users and groups on mount', () => { mount(<ProfilePermissions profile={{ key: 'sonar-way', name: 'Sonar way', language: 'js' }} />); - expect(searchUsers).toBeCalledWith({ + expect(searchUsers).toHaveBeenCalledWith({ language: 'js', qualityProfile: 'Sonar way', selected: 'selected' }); - expect(searchGroups).toBeCalledWith({ + expect(searchGroups).toHaveBeenCalledWith({ language: 'js', qualityProfile: 'Sonar way', selected: 'selected' diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsForm-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsForm-test.tsx index 0a1943966cb..2d278d412f3 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsForm-test.tsx @@ -49,7 +49,7 @@ it('correctly adds users', async () => { submit(wrapper.find('form')); expect(wrapper).toMatchSnapshot(); - expect(addUser).toBeCalledWith( + expect(addUser).toHaveBeenCalledWith( expect.objectContaining({ language: PROFILE.language, qualityProfile: PROFILE.name, @@ -58,7 +58,7 @@ it('correctly adds users', async () => { ); await waitAndUpdate(wrapper); - expect(onUserAdd).toBeCalledWith(user); + expect(onUserAdd).toHaveBeenCalledWith(user); }); it('correctly adds groups', async () => { @@ -71,7 +71,7 @@ it('correctly adds groups', async () => { submit(wrapper.find('form')); expect(wrapper).toMatchSnapshot(); - expect(addGroup).toBeCalledWith( + expect(addGroup).toHaveBeenCalledWith( expect.objectContaining({ language: PROFILE.language, qualityProfile: PROFILE.name, @@ -80,7 +80,7 @@ it('correctly adds groups', async () => { ); await waitAndUpdate(wrapper); - expect(onGroupAdd).toBeCalledWith(group); + expect(onGroupAdd).toHaveBeenCalledWith(group); }); function shallowRender(props: Partial<ProfilePermissionsForm['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsFormSelect-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsFormSelect-test.tsx index 53b417a2680..43e0ced05fe 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsFormSelect-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsFormSelect-test.tsx @@ -51,8 +51,8 @@ it('should handle search', async () => { const results = await new Promise(resolve => { wrapper.instance().handleSearch(query, resolve); }); - expect(searchUsers).toBeCalledWith(expect.objectContaining({ q: query })); - expect(searchGroups).toBeCalledWith(expect.objectContaining({ q: query })); + expect(searchUsers).toHaveBeenCalledWith(expect.objectContaining({ q: query })); + expect(searchGroups).toHaveBeenCalledWith(expect.objectContaining({ q: query })); expect(results).toHaveLength(2); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx index 6b108548ffe..a0d843eed8f 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsGroup-test.tsx @@ -54,12 +54,12 @@ it('removes user', async () => { expect(wrapper.find('SimpleModal').exists()).toBe(true); wrapper.find('SimpleModal').prop<Function>('onSubmit')(); - expect(removeGroup).toBeCalledWith({ + expect(removeGroup).toHaveBeenCalledWith({ group: 'lambda', language: 'js', qualityProfile: 'Sonar way' }); await new Promise(setImmediate); - expect(onDelete).toBeCalledWith(group); + expect(onDelete).toHaveBeenCalledWith(group); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx index 8d64406ab6c..2de87095b8d 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfilePermissionsUser-test.tsx @@ -53,12 +53,12 @@ it('removes user', async () => { expect(wrapper.find('SimpleModal').exists()).toBe(true); wrapper.find('SimpleModal').prop<Function>('onSubmit')(); - expect(removeUser).toBeCalledWith({ + expect(removeUser).toHaveBeenCalledWith({ language: 'js', login: 'luke', qualityProfile: 'Sonar way' }); await new Promise(setImmediate); - expect(onDelete).toBeCalledWith(user); + expect(onDelete).toHaveBeenCalledWith(user); }); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx index b754c6629e4..b22b3c6b1d5 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-test.tsx @@ -85,13 +85,13 @@ it('should load data correctly', async () => { expect(wrapper.state().loading).toBe(true); expect(wrapper.state().loadingMeasure).toBe(true); - expect(getStandards).toBeCalled(); - expect(getSecurityHotspots).toBeCalledWith( + expect(getStandards).toHaveBeenCalled(); + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ branch: branch.name }) ); - expect(getMeasures).toBeCalledWith( + expect(getMeasures).toHaveBeenCalledWith( expect.objectContaining({ branch: branch.name }) @@ -119,7 +119,7 @@ it('should handle category request', () => { location: mockLocation({ query: { [SecurityStandard.OWASP_TOP10]: 'a1' } }) }); - expect(getSecurityHotspots).toBeCalledWith( + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ [SecurityStandard.OWASP_TOP10]: 'a1' }) ); }); @@ -132,7 +132,7 @@ it('should handle cwe request', () => { location: mockLocation({ query: { [SecurityStandard.CWE]: '1004' } }) }); - expect(getSecurityHotspots).toBeCalledWith( + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ [SecurityStandard.CWE]: '1004' }) ); }); @@ -147,7 +147,7 @@ it('should handle file request', () => { location: mockLocation({ query: { files: filepath } }) }); - expect(getSecurityHotspots).toBeCalledWith(expect.objectContaining({ files: filepath })); + expect(getSecurityHotspots).toHaveBeenCalledWith(expect.objectContaining({ files: filepath })); }); it('should load data correctly when hotspot key list is forced', async () => { @@ -169,7 +169,7 @@ it('should load data correctly when hotspot key list is forced', async () => { }); await waitAndUpdate(wrapper); - expect(getSecurityHotspotList).toBeCalledWith(hotspotKeys, { + expect(getSecurityHotspotList).toHaveBeenCalledWith(hotspotKeys, { projectKey: 'my-project', branch: 'branch-6.7' }); @@ -247,7 +247,7 @@ it('should handle loading more', async () => { wrapper.instance().handleLoadMore(); expect(wrapper.state().loadingMore).toBe(true); - expect(getSecurityHotspots).toBeCalledTimes(2); + expect(getSecurityHotspots).toHaveBeenCalledTimes(2); await waitAndUpdate(wrapper); @@ -302,7 +302,7 @@ it('should handle hotspot update', async () => { wrapper.state().hotspots.findIndex(h => h.key === wrapper.state().selectedHotspot?.key) ).toBe(selectedHotspotIndex); - expect(getMeasures).toBeCalled(); + expect(getMeasures).toHaveBeenCalled(); (getSecurityHotspots as jest.Mock).mockResolvedValueOnce({ hotspots, @@ -318,7 +318,7 @@ it('should handle hotspot update', async () => { .find(SecurityHotspotsAppRenderer) .props() .onUpdateHotspot(key); - expect(fetchBranchStatusMock).toBeCalledWith(branchLike, componentKey); + expect(fetchBranchStatusMock).toHaveBeenCalledWith(branchLike, componentKey); }); it('should handle status filter change', async () => { @@ -331,19 +331,19 @@ it('should handle status filter change', async () => { const wrapper = shallowRender(); - expect(getSecurityHotspots).toBeCalledWith( + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ status: HotspotStatus.TO_REVIEW, resolution: undefined }) ); await waitAndUpdate(wrapper); - expect(getMeasures).toBeCalledTimes(1); + expect(getMeasures).toHaveBeenCalledTimes(1); // Set filter to SAFE: wrapper.instance().handleChangeFilters({ status: HotspotStatusFilter.SAFE }); - expect(getMeasures).toBeCalledTimes(1); + expect(getMeasures).toHaveBeenCalledTimes(1); - expect(getSecurityHotspots).toBeCalledWith( + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ status: HotspotStatus.REVIEWED, resolution: HotspotResolution.SAFE }) ); @@ -354,7 +354,7 @@ it('should handle status filter change', async () => { // Set filter to FIXED (use the other method to check this one): wrapper.instance().handleChangeStatusFilter(HotspotStatusFilter.FIXED); - expect(getSecurityHotspots).toBeCalledWith( + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ status: HotspotStatus.REVIEWED, resolution: HotspotResolution.FIXED }) ); @@ -373,18 +373,20 @@ it('should handle leakPeriod filter change', async () => { const wrapper = shallowRender(); - expect(getSecurityHotspots).toBeCalledWith( + expect(getSecurityHotspots).toHaveBeenCalledWith( expect.objectContaining({ status: HotspotStatus.TO_REVIEW, resolution: undefined }) ); await waitAndUpdate(wrapper); - expect(getMeasures).toBeCalledTimes(1); + expect(getMeasures).toHaveBeenCalledTimes(1); wrapper.instance().handleChangeFilters({ inNewCodePeriod: true }); - expect(getMeasures).toBeCalledTimes(2); - expect(getSecurityHotspots).toBeCalledWith(expect.objectContaining({ inNewCodePeriod: true })); + expect(getMeasures).toHaveBeenCalledTimes(2); + expect(getSecurityHotspots).toHaveBeenCalledWith( + expect.objectContaining({ inNewCodePeriod: true }) + ); }); it('should handle hotspot click', () => { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx index d0c82bf5a59..e0e592c6f63 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsAppRenderer-test.tsx @@ -113,7 +113,7 @@ describe('side effect', () => { it('should trigger scrolling', () => { shallowRender({ selectedHotspot: mockRawHotspot() }); - expect(scrollToElement).toBeCalledWith( + expect(scrollToElement).toHaveBeenCalledWith( fakeElement, expect.objectContaining({ parent: fakeParent }) ); @@ -121,7 +121,7 @@ describe('side effect', () => { it('should not trigger scrolling if no selected hotspot', () => { shallowRender(); - expect(scrollToElement).not.toBeCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); }); it('should not trigger scrolling if no parent', () => { @@ -129,7 +129,7 @@ describe('side effect', () => { mockUseRef.mockReset(); mockUseRef.mockImplementationOnce(() => ({ current: null })); shallowRender({ selectedHotspot: mockRawHotspot() }); - expect(scrollToElement).not.toBeCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); }); }); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx index 7f7126af081..acaa4c993f6 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/FilterBar-test.tsx @@ -65,7 +65,7 @@ it('should trigger onChange for status', () => { .props(); onChange({ value: HotspotStatusFilter.SAFE }); - expect(onChangeFilters).toBeCalledWith({ status: HotspotStatusFilter.SAFE }); + expect(onChangeFilters).toHaveBeenCalledWith({ status: HotspotStatusFilter.SAFE }); }); it('should trigger onChange for self-assigned toggle', () => { @@ -75,7 +75,7 @@ it('should trigger onChange for self-assigned toggle', () => { const { onCheck } = wrapper.find(ButtonToggle).props(); onCheck(AssigneeFilterOption.ALL); - expect(onChangeFilters).toBeCalledWith({ assignedToMe: false }); + expect(onChangeFilters).toHaveBeenCalledWith({ assignedToMe: false }); }); it('should trigger onChange for leak period', () => { @@ -88,7 +88,7 @@ it('should trigger onChange for leak period', () => { .props(); onChange({ value: true }); - expect(onChangeFilters).toBeCalledWith({ inNewCodePeriod: true }); + expect(onChangeFilters).toHaveBeenCalledWith({ inNewCodePeriod: true }); }); function shallowRender(props: Partial<FilterBarProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx index 293b318af5b..d06f2f67b8b 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotCategory-test.tsx @@ -56,12 +56,12 @@ it('should handle collapse and expand', () => { wrapper.find('.hotspot-category-header').simulate('click'); - expect(onToggleExpand).toBeCalledWith(categoryKey, false); + expect(onToggleExpand).toHaveBeenCalledWith(categoryKey, false); wrapper.setProps({ expanded: false }); wrapper.find('.hotspot-category-header').simulate('click'); - expect(onToggleExpand).toBeCalledWith(categoryKey, true); + expect(onToggleExpand).toHaveBeenCalledWith(categoryKey, true); }); function shallowRender(props: Partial<HotspotCategoryProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx index 96d2c23adf2..250b80f1520 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotListItem-test.tsx @@ -34,7 +34,7 @@ it('should handle click', () => { wrapper.simulate('click'); - expect(onClick).toBeCalledWith(hotspot); + expect(onClick).toHaveBeenCalledWith(hotspot); }); it('should handle click on the title', () => { @@ -44,7 +44,7 @@ it('should handle click on the title', () => { wrapper.find('div.cursor-pointer').simulate('click'); - expect(onLocationClick).toBeCalledWith(); + expect(onLocationClick).toHaveBeenCalledWith(); }); function shallowRender(props: Partial<HotspotListItemProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx index cf4d2ae0e47..ef7dce2d793 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotOpenInIdeButton-test.tsx @@ -46,7 +46,7 @@ describe('HotspotOpenInIdeButton', () => { wrapper.find(Button).simulate('click'); await new Promise(setImmediate); - expect(sonarlint.openHotspot).toBeCalledWith(port, projectKey, hotspotKey); + expect(sonarlint.openHotspot).toHaveBeenCalledWith(port, projectKey, hotspotKey); }); it('should gracefully handle zero IDE detected', async () => { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx index 8d9f1082065..8c05746529b 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotPrimaryLocationBox-test.tsx @@ -58,7 +58,7 @@ it('should handle click', () => { wrapper.find(ButtonLink).simulate('click'); - expect(onCommentClick).toBeCalled(); + expect(onCommentClick).toHaveBeenCalled(); }); it('should scroll on load if no secondary locations selected', () => { @@ -69,7 +69,7 @@ it('should scroll on load if no secondary locations selected', () => { const scroll = jest.fn(); shallowRender({ scroll }); - expect(scroll).toBeCalled(); + expect(scroll).toHaveBeenCalled(); }); it('should not scroll on load if a secondary location is selected', () => { @@ -80,7 +80,7 @@ it('should not scroll on load if a secondary location is selected', () => { const scroll = jest.fn(); shallowRender({ scroll, secondaryLocationSelected: true }); - expect(scroll).not.toBeCalled(); + expect(scroll).not.toHaveBeenCalled(); }); it('should not scroll on load if node is not defined', () => { @@ -90,7 +90,7 @@ it('should not scroll on load if node is not defined', () => { const scroll = jest.fn(); shallowRender({ scroll }); - expect(scroll).not.toBeCalled(); + expect(scroll).not.toHaveBeenCalled(); }); function shallowRender(props: Partial<HotspotPrimaryLocationBoxProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx index 0d3cc378388..86b9fefe76d 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistory-test.tsx @@ -64,7 +64,7 @@ it('should correctly handle comment updating', () => { .at(0) .props() .onRequestClose(); - expect(setEditedCommentKey).toBeCalledWith(''); + expect(setEditedCommentKey).toHaveBeenCalledWith(''); const editOnClick = wrapper .find(EditButton) @@ -140,7 +140,7 @@ it('should correctly handle comment deleting', () => { } deleteButtonOnClick(); - expect(onDeleteComment).toBeCalledWith('comment-1'); + expect(onDeleteComment).toHaveBeenCalledWith('comment-1'); resolve(); }); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx index 5f0e61cae10..64ed9acdec8 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotReviewHistoryAndComments-test.tsx @@ -88,7 +88,7 @@ it('should delete comment', async () => { await waitAndUpdate(wrapper); expect(deleteSecurityHotspotComment).toHaveBeenCalledWith('me1'); - expect(wrapper.instance().props.onCommentUpdate).toBeCalledTimes(1); + expect(wrapper.instance().props.onCommentUpdate).toHaveBeenCalledTimes(1); }); it('should edit comment', async () => { @@ -98,7 +98,7 @@ it('should edit comment', async () => { await waitAndUpdate(wrapper); expect(editSecurityHotspotComment).toHaveBeenCalledWith('me1', 'new'); - expect(wrapper.instance().props.onCommentUpdate).toBeCalledTimes(1); + expect(wrapper.instance().props.onCommentUpdate).toHaveBeenCalledTimes(1); }); it('should correctly toggle the show full history state', () => { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx index d984d488ec4..a0207becc7d 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx @@ -73,7 +73,7 @@ it('should load sources on mount', async () => { await waitAndUpdate(wrapper); - expect(getSources).toBeCalledWith( + expect(getSources).toHaveBeenCalledWith( expect.objectContaining({ key: hotspot.component.key, branch: branch.name, @@ -108,7 +108,7 @@ it('should not load sources on mount when the hotspot is not associated to any l await waitAndUpdate(wrapper); - expect(getSources).not.toBeCalled(); + expect(getSources).not.toHaveBeenCalled(); expect(wrapper.state().lastLine).toBeUndefined(); expect(wrapper.state().sourceLines).toHaveLength(0); }); @@ -126,7 +126,7 @@ it('should handle end-of-file on mount', async () => { await waitAndUpdate(wrapper); - expect(getSources).toBeCalled(); + expect(getSources).toHaveBeenCalled(); expect(wrapper.state().lastLine).toBe(14); expect(wrapper.state().sourceLines).toHaveLength(10); }); @@ -158,7 +158,7 @@ describe('Expansion', () => { await waitAndUpdate(wrapper); - expect(getSources).toBeCalledWith( + expect(getSources).toHaveBeenCalledWith( expect.objectContaining({ branch: branch.name }) diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx index 98aec410c5c..c062d19dda4 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainerRenderer-test.tsx @@ -88,7 +88,7 @@ describe('scrolling', () => { scrollHandler(targetElement); jest.runAllTimers(); - expect(scrollToElement).toBeCalled(); + expect(scrollToElement).toHaveBeenCalled(); }); it('should not scroll if parent is undefined', () => { @@ -103,7 +103,7 @@ describe('scrolling', () => { scrollHandler(targetElement); jest.runAllTimers(); - expect(scrollToElement).not.toBeCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); }); }); @@ -133,23 +133,23 @@ describe('expand', () => { .mockReturnValueOnce({ height: 112 } as DOMRect); await animateExpansion(ref, onExpandBlock, 'up'); - expect(onExpandBlock).toBeCalledWith('up'); + expect(onExpandBlock).toHaveBeenCalledWith('up'); - expect(snippet.style.maxHeight).toBe('42px'); - expect(table.style.marginTop).toBe('-57px'); + expect(snippet).toHaveStyle({ maxHeight: '42px' }); + expect(table).toHaveStyle({ marginTop: '-57px' }); jest.advanceTimersByTime(100); - expect(snippet.style.maxHeight).toBe('99px'); - expect(table.style.marginTop).toBe('0px'); + expect(snippet).toHaveStyle({ maxHeight: '99px' }); + expect(table).toHaveStyle({ marginTop: '0px' }); - expect(scrollableNode.scrollTo).not.toBeCalled(); + expect(scrollableNode.scrollTo).not.toHaveBeenCalled(); jest.runAllTimers(); await animateExpansion(ref, onExpandBlock, 'down'); - expect(onExpandBlock).toBeCalledWith('down'); - expect(snippet.style.maxHeight).toBe('112px'); + expect(onExpandBlock).toHaveBeenCalledWith('down'); + expect(snippet).toHaveStyle({ maxHeight: '112px' }); jest.useRealTimers(); }); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx index 416f0d9e5fa..47b69bf671c 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewer-test.tsx @@ -127,11 +127,11 @@ it('should correctly propagate a request to switch the status filter', () => { const wrapper = shallowRender({ onSwitchStatusFilter }); wrapper.instance().handleSwitchFilterToStatusOfUpdatedHotspot(); - expect(onSwitchStatusFilter).not.toBeCalled(); + expect(onSwitchStatusFilter).not.toHaveBeenCalled(); wrapper.setState({ lastStatusChangedTo: HotspotStatusOption.FIXED }); wrapper.instance().handleSwitchFilterToStatusOfUpdatedHotspot(); - expect(onSwitchStatusFilter).toBeCalledWith(HotspotStatusOption.FIXED); + expect(onSwitchStatusFilter).toHaveBeenCalledWith(HotspotStatusOption.FIXED); }); it('should correctly close the success modal', () => { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx index 6f9a84946b9..80edf167c92 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotViewerTabs-test.tsx @@ -178,11 +178,11 @@ it('should navigate when up and down key are pressed', () => { <HotspotViewerTabs codeTabContent={<div>CodeTabContent</div>} hotspot={mockHotspot()} /> ); - expect(window.addEventListener).toBeCalled(); + expect(window.addEventListener).toHaveBeenCalled(); wrapper.unmount(); - expect(window.removeEventListener).toBeCalled(); + expect(window.removeEventListener).toHaveBeenCalled(); }); function shallowRender(props?: Partial<HotspotViewerTabs['props']>) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx index c659d52582d..cb412eb9dd6 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelection-test.tsx @@ -67,7 +67,7 @@ it('should handle keydown', () => { // press enter to select the highlighted user wrapper.instance().handleKeyDown(mockKeyboardEvent(KeyboardKeys.Enter)); - expect(onSelect).toBeCalledWith(suggestedUsers[1]); + expect(onSelect).toHaveBeenCalledWith(suggestedUsers[1]); }); it('should handle search', async () => { @@ -80,11 +80,11 @@ it('should handle search', async () => { expect(wrapper.state().suggestedUsers.length).toBe(1); wrapper.instance().handleSearch('j'); - expect(searchUsers).not.toBeCalled(); + expect(searchUsers).not.toHaveBeenCalled(); wrapper.instance().handleSearch('jo'); expect(wrapper.state().loading).toBe(true); - expect(searchUsers).toBeCalledWith({ q: 'jo' }); + expect(searchUsers).toHaveBeenCalledWith({ q: 'jo' }); await waitAndUpdate(wrapper); @@ -94,7 +94,7 @@ it('should handle search', async () => { jest.clearAllMocks(); wrapper.instance().handleSearch(''); - expect(searchUsers).not.toBeCalled(); + expect(searchUsers).not.toHaveBeenCalled(); expect(wrapper.state().suggestedUsers.length).toBe(1); }); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx index f686f2fc639..044572d300b 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/assignee/__tests__/AssigneeSelectionRenderer-test.tsx @@ -51,7 +51,7 @@ it('should call onSelect when clicked', () => { .at(0) .simulate('click'); - expect(onSelect).toBeCalledWith(user); + expect(onSelect).toHaveBeenCalledWith(user); }); function shallowRender(props?: Partial<HotspotAssigneeSelectRendererProps>) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx index d684caae1a3..3274b16a9c9 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/status/__tests__/Status-test.tsx @@ -50,7 +50,7 @@ it('should properly deal with comment/status/submit events', async () => { await user.click(screen.getByRole('button', { name: 'hotspots.status.change_status' })); - expect(setSecurityHotspotStatus).toBeCalledWith(hotspot.key, { + expect(setSecurityHotspotStatus).toHaveBeenCalledWith(hotspot.key, { status: HotspotStatus.REVIEWED, resolution: HotspotResolution.SAFE, comment diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/AllCategoriesList-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/AllCategoriesList-test.tsx index a45a2368eca..bcf8ac67203 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/AllCategoriesList-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/AllCategoriesList-test.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { screen } from '@testing-library/dom'; +import { screen } from '@testing-library/react'; import * as React from 'react'; import { mockComponent } from '../../../../helpers/mocks/component'; import { renderComponent } from '../../../../helpers/testReactTestingUtils'; @@ -69,7 +69,7 @@ it('should render correctly', () => { expect(screen.getByText('CAT_2_NAME')).toBeInTheDocument(); expect(screen.queryByText('CAT_3_NAME')).not.toBeInTheDocument(); expect(screen.queryByText('CAT_4_NAME')).not.toBeInTheDocument(); - expect(screen.getByText('CAT_2_NAME').className).toBe('active'); + expect(screen.getByText('CAT_2_NAME')).toHaveClass('active', { exact: true }); }); it('should correctly for project', () => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/CategoryDefinitionsList-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/CategoryDefinitionsList-test.tsx index 105a5569df4..9f5dedb2a4a 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/CategoryDefinitionsList-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/CategoryDefinitionsList-test.tsx @@ -45,7 +45,7 @@ it('should load settings values', async () => { await waitAndUpdate(wrapper); - expect(getValues).toBeCalledWith({ keys: ['yes', 'yesagain'], component: undefined }); + expect(getValues).toHaveBeenCalledWith({ keys: ['yes', 'yesagain'], component: undefined }); expect(wrapper.state().settings).toEqual([ { definition: definitions[0], settingValue: settings[0] }, @@ -63,13 +63,13 @@ it('should reload on category change', async () => { await waitAndUpdate(wrapper); - expect(getValues).toBeCalledWith({ keys: ['yes', 'yesagain'], component: 'comp-key' }); + expect(getValues).toHaveBeenCalledWith({ keys: ['yes', 'yesagain'], component: 'comp-key' }); wrapper.setProps({ category: 'other' }); await waitAndUpdate(wrapper); - expect(getValues).toBeCalledWith({ keys: ['nope'], component: 'comp-key' }); + expect(getValues).toHaveBeenCalledWith({ keys: ['nope'], component: 'comp-key' }); }); function shallowRender(props: Partial<CategoryDefinitionsList['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/Definition-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/Definition-test.tsx index 65af2b65543..8a64edf7ed5 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/Definition-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/Definition-test.tsx @@ -103,7 +103,7 @@ describe('handleSave', () => { wrapper.instance().handleSave(); expect(wrapper.state().loading).toBe(false); - expect(setSettingValue).not.toBeCalled(); + expect(setSettingValue).not.toHaveBeenCalled(); }); it('should handle an empty value', () => { @@ -115,7 +115,7 @@ describe('handleSave', () => { expect(wrapper.state().loading).toBe(false); expect(wrapper.state().validationMessage).toBe('settings.state.value_cant_be_empty'); - expect(setSettingValue).not.toBeCalled(); + expect(setSettingValue).not.toHaveBeenCalled(); }); it('should save and update setting value', async () => { @@ -132,8 +132,8 @@ describe('handleSave', () => { await waitAndUpdate(wrapper); - expect(setSettingValue).toBeCalledWith(definition, 'new value', undefined); - expect(getValue).toBeCalledWith({ key: definition.key, component: undefined }); + expect(setSettingValue).toHaveBeenCalledWith(definition, 'new value', undefined); + expect(getValue).toHaveBeenCalledWith({ key: definition.key, component: undefined }); expect(wrapper.state().changedValue).toBeUndefined(); expect(wrapper.state().loading).toBe(false); expect(wrapper.state().success).toBe(true); @@ -156,8 +156,8 @@ it('should reset and update setting value', async () => { await waitAndUpdate(wrapper); - expect(resetSettingValue).toBeCalledWith({ keys: definition.key, component: undefined }); - expect(getValue).toBeCalledWith({ key: definition.key, component: undefined }); + expect(resetSettingValue).toHaveBeenCalledWith({ keys: definition.key, component: undefined }); + expect(getValue).toHaveBeenCalledWith({ key: definition.key, component: undefined }); expect(wrapper.state().changedValue).toBeUndefined(); expect(wrapper.state().loading).toBe(false); expect(wrapper.state().success).toBe(true); diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodePeriod-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodePeriod-test.tsx index 20db3e86533..fe71d9b74da 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodePeriod-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodePeriod-test.tsx @@ -107,8 +107,8 @@ it('should submit correctly', async () => { wrapper.find('form').simulate('submit', { preventDefault }); - expect(preventDefault).toBeCalledTimes(1); - expect(setNewCodePeriod).toBeCalledWith({ type: 'PREVIOUS_VERSION', value: undefined }); + expect(preventDefault).toHaveBeenCalledTimes(1); + expect(setNewCodePeriod).toHaveBeenCalledWith({ type: 'PREVIOUS_VERSION', value: undefined }); await waitAndUpdate(wrapper); expect(wrapper.state('currentSetting')).toEqual(wrapper.state('selected')); }); @@ -125,8 +125,8 @@ it('should submit correctly with days', async () => { wrapper.find('form').simulate('submit', { preventDefault }); - expect(preventDefault).toBeCalledTimes(1); - expect(setNewCodePeriod).toBeCalledWith({ type: 'NUMBER_OF_DAYS', value: '66' }); + expect(preventDefault).toHaveBeenCalledTimes(1); + expect(setNewCodePeriod).toHaveBeenCalledWith({ type: 'NUMBER_OF_DAYS', value: '66' }); await waitAndUpdate(wrapper); expect(wrapper.state('currentSetting')).toEqual(wrapper.state('selected')); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsApp-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsApp-test.tsx index 005d1e1a961..e9193b069b8 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsApp-test.tsx @@ -44,18 +44,18 @@ jest.mock('../../../../api/settings', () => ({ it('should render default view correctly', async () => { const wrapper = shallowRender(); - expect(addSideBarClass).toBeCalled(); - expect(addWhitePageClass).toBeCalled(); + expect(addSideBarClass).toHaveBeenCalled(); + expect(addWhitePageClass).toHaveBeenCalled(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(getDefinitions).toBeCalledWith(undefined); + expect(getDefinitions).toHaveBeenCalledWith(undefined); wrapper.unmount(); - expect(removeSideBarClass).toBeCalled(); - expect(removeWhitePageClass).toBeCalled(); + expect(removeSideBarClass).toHaveBeenCalled(); + expect(removeWhitePageClass).toHaveBeenCalled(); }); it('should fetch definitions for component', async () => { @@ -63,7 +63,7 @@ it('should fetch definitions for component', async () => { const wrapper = shallowRender({ component: mockComponent({ key }) }); await waitAndUpdate(wrapper); - expect(getDefinitions).toBeCalledWith(key); + expect(getDefinitions).toHaveBeenCalledWith(key); }); function shallowRender(props: Partial<SettingsApp['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearch-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearch-test.tsx index ba04565ca31..fd69cd348b9 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearch-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearch-test.tsx @@ -59,7 +59,7 @@ describe('instance', () => { await waitAndUpdate(wrapper); expect(wrapper.state().searchQuery).toBe('query'); - expect(wrapper.instance().index.search).toBeCalled(); + expect(wrapper.instance().index.search).toHaveBeenCalled(); expect(wrapper.state().showResults).toBe(true); expect(wrapper.state().results).toHaveLength(2); }); @@ -70,7 +70,7 @@ describe('instance', () => { await waitAndUpdate(wrapper); expect(wrapper.state().searchQuery).toBe(''); - expect(wrapper.instance().index.search).toBeCalled(); + expect(wrapper.instance().index.search).toHaveBeenCalled(); expect(wrapper.state().showResults).toBe(false); }); @@ -100,12 +100,12 @@ describe('instance', () => { it('should handle "enter" keyboard event', () => { wrapper.setState({ selectedResult: undefined }); wrapper.instance().handleKeyDown(mockEvent({ nativeEvent: { key: KeyboardKeys.Enter } })); - expect(router.push).not.toBeCalled(); + expect(router.push).not.toHaveBeenCalled(); wrapper.setState({ selectedResult: 'foo' }); wrapper.instance().handleKeyDown(mockEvent({ nativeEvent: { key: KeyboardKeys.Enter } })); - expect(router.push).toBeCalledWith({ + expect(router.push).toHaveBeenCalledWith({ hash: '#foo', pathname: '/admin/settings', search: queryToSearch({ category: 'foo category' }) diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearchRenderer-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearchRenderer-test.tsx index 3750b4f176f..ee55b011216 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearchRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SettingsSearchRenderer-test.tsx @@ -67,7 +67,7 @@ it('should scroll to selected element', () => { shallowRender(); - expect(scrollToElement).toBeCalled(); + expect(scrollToElement).toHaveBeenCalled(); }); function shallowRender(overrides: Partial<SettingsSearchRendererProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SubCategoryDefinitionsList-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SubCategoryDefinitionsList-test.tsx index 78925da7276..035ce8d6479 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/SubCategoryDefinitionsList-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/SubCategoryDefinitionsList-test.tsx @@ -44,11 +44,11 @@ it('should scroll if hash is defined and updated', async () => { wrapper.find('h2').forEach(node => mount(node.getElement())); - expect(window.HTMLElement.prototype.scrollIntoView).toBeCalled(); + expect(window.HTMLElement.prototype.scrollIntoView).toHaveBeenCalled(); wrapper.setProps({ location: mockLocation({ hash: '#email' }) }); - expect(window.HTMLElement.prototype.scrollIntoView).toBeCalled(); + expect(window.HTMLElement.prototype.scrollIntoView).toHaveBeenCalled(); }); function shallowRender(props: Partial<SubCategoryDefinitionsListProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormField-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormField-test.tsx index b55e0bf93d2..ae49847d64f 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormField-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormField-test.tsx @@ -44,13 +44,13 @@ it('should call onFieldChange', () => { shallowRender({ onFieldChange: onInputChange }) .find('input') .simulate('change', { currentTarget: { value: '' } }); - expect(onInputChange).toBeCalled(); + expect(onInputChange).toHaveBeenCalled(); const onTextAreaChange = jest.fn(); shallowRender({ isTextArea: true, onFieldChange: onTextAreaChange }) .find('textarea') .simulate('change', { currentTarget: { value: '' } }); - expect(onTextAreaChange).toBeCalled(); + expect(onTextAreaChange).toHaveBeenCalled(); }); it('should correctly toggle visibility for secret fields', () => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormRenderer-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormRenderer-test.tsx index 86b36dcb232..ace1308a6f2 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormRenderer-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmBindingDefinitionFormRenderer-test.tsx @@ -61,7 +61,7 @@ it('should submit properly', () => { wrapper.find('form').simulate('submit', event); - expect(event.preventDefault).toBeCalled(); + expect(event.preventDefault).toHaveBeenCalled(); expect(onSubmit).toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx index 29f7f5b790d..a9c0596dbea 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx @@ -61,13 +61,13 @@ it('should validate existing configurations', async () => { await waitAndUpdate(wrapper); - expect(validateAlmSettings).toBeCalledTimes(6); - expect(validateAlmSettings).toBeCalledWith('a1'); - expect(validateAlmSettings).toBeCalledWith('b1'); - expect(validateAlmSettings).toBeCalledWith('bc1'); - expect(validateAlmSettings).toBeCalledWith('gh1'); - expect(validateAlmSettings).toBeCalledWith('gh2'); - expect(validateAlmSettings).toBeCalledWith('gl1'); + expect(validateAlmSettings).toHaveBeenCalledTimes(6); + expect(validateAlmSettings).toHaveBeenCalledWith('a1'); + expect(validateAlmSettings).toHaveBeenCalledWith('b1'); + expect(validateAlmSettings).toHaveBeenCalledWith('bc1'); + expect(validateAlmSettings).toHaveBeenCalledWith('gh1'); + expect(validateAlmSettings).toHaveBeenCalledWith('gh2'); + expect(validateAlmSettings).toHaveBeenCalledWith('gl1'); }); it('should handle alm selection', async () => { @@ -81,7 +81,7 @@ it('should handle alm selection', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().currentAlmTab).toBe(AlmKeys.GitHub); - expect(router.push).toBeCalled(); + expect(router.push).toHaveBeenCalled(); }); it('should handle delete', async () => { @@ -170,7 +170,7 @@ it('should fetch settings', async () => { await wrapper.instance().fetchPullRequestDecorationSetting(); - expect(getAlmDefinitions).toBeCalled(); + expect(getAlmDefinitions).toHaveBeenCalled(); expect(wrapper.state().definitions).toEqual(definitions); expect(wrapper.state().loadingAlmDefinitions).toBe(false); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx index 0bd51989159..1eb00212855 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForBoolean-test.tsx @@ -53,7 +53,7 @@ it('should call onChange', () => { toggle.prop<Function>('onChange')(false); - expect(onChange).toBeCalledWith(false); + expect(onChange).toHaveBeenCalledWith(false); }); function shallowRender(props: Partial<DefaultSpecializedInputProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForJSON-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForJSON-test.tsx index 9f809ccc0c1..96a22f95547 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForJSON-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForJSON-test.tsx @@ -33,14 +33,14 @@ it('should call onChange', () => { const wrapper = shallowRender({ onChange }); change(wrapper.find('textarea'), '{"a": 1}'); - expect(onChange).toBeCalledWith('{"a": 1}'); + expect(onChange).toHaveBeenCalledWith('{"a": 1}'); }); it('should handle formatting for invalid JSON', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange, value: '{"a": 1b}' }); wrapper.instance().format(); - expect(onChange).not.toBeCalled(); + expect(onChange).not.toHaveBeenCalled(); expect(wrapper.state().formatError).toBe(true); expect(wrapper).toMatchSnapshot(); @@ -50,7 +50,7 @@ it('should handle formatting for valid JSON', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange, value: '{"a": 1}' }); wrapper.instance().format(); - expect(onChange).toBeCalledWith(`{ + expect(onChange).toHaveBeenCalledWith(`{ "a": 1 }`); @@ -61,7 +61,7 @@ it('should handle ignore formatting if empty', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange, value: '' }); wrapper.instance().format(); - expect(onChange).not.toBeCalled(); + expect(onChange).not.toHaveBeenCalled(); expect(wrapper.state().formatError).toBe(false); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSecured-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSecured-test.tsx index 98f47863dbd..2fd6b39d91f 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSecured-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSecured-test.tsx @@ -48,7 +48,7 @@ it('should set value', () => { click(input.find('Button')); change(input.find(InputForString), 'secret'); - expect(onChange).toBeCalledWith('secret'); + expect(onChange).toHaveBeenCalledWith('secret'); }); it('should show input when empty, and enable handle typing', () => { diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx index 63172dd9079..c2d7bcb0c66 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForSingleSelectList-test.tsx @@ -45,7 +45,7 @@ it('should call onChange', () => { expect(select.prop('onChange')).toBeDefined(); select.prop<Function>('onChange')({ value: 'baz', label: 'baz' }); - expect(onChange).toBeCalledWith('baz'); + expect(onChange).toHaveBeenCalledWith('baz'); }); function shallowRender(props: Partial<DefaultSpecializedInputProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx index b228b5b854d..637d733b563 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/InputForText-test.tsx @@ -40,7 +40,7 @@ it('should call onChange', () => { expect(textarea.prop('onChange')).toBeDefined(); change(textarea, 'qux'); - expect(onChange).toBeCalledWith('qux'); + expect(onChange).toHaveBeenCalledWith('qux'); }); function shallowRender(props: Partial<DefaultSpecializedInputProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.tsx index 50ad48b98bd..4140dc30331 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/MultiValueInput-test.tsx @@ -65,7 +65,7 @@ it('should remove value', () => { const onChange = jest.fn(); const multiValueInput = shallowRender({ onChange, value: ['foo', 'bar', 'baz'] }); click(multiValueInput.find('.js-remove-value').at(1)); - expect(onChange).toBeCalledWith(['foo', 'baz']); + expect(onChange).toHaveBeenCalledWith(['foo', 'baz']); }); it('should change existing value', () => { @@ -75,7 +75,7 @@ it('should change existing value', () => { .find(PrimitiveInput) .at(1) .prop('onChange')('qux'); - expect(onChange).toBeCalledWith(['foo', 'qux', 'baz']); + expect(onChange).toHaveBeenCalledWith(['foo', 'qux', 'baz']); }); it('should add new value', () => { @@ -85,7 +85,7 @@ it('should add new value', () => { .find(PrimitiveInput) .at(1) .prop('onChange')('bar'); - expect(onChange).toBeCalledWith(['foo', 'bar']); + expect(onChange).toHaveBeenCalledWith(['foo', 'bar']); }); function shallowRender(props: Partial<DefaultSpecializedInputProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx index dbb912412f3..2052638b7e0 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/inputs/__tests__/SimpleInput-test.tsx @@ -41,7 +41,7 @@ it('should call onChange', () => { expect(input.prop('onChange')).toBeDefined(); change(input, 'qux'); - expect(onChange).toBeCalledWith('qux'); + expect(onChange).toHaveBeenCalledWith('qux'); }); it('should handle enter', () => { @@ -49,7 +49,7 @@ it('should handle enter', () => { shallowRender({ onSave }) .instance() .handleKeyDown(mockEvent({ nativeEvent: { key: KeyboardKeys.Enter } })); - expect(onSave).toBeCalled(); + expect(onSave).toHaveBeenCalled(); }); it('should handle esc', () => { @@ -57,7 +57,7 @@ it('should handle esc', () => { shallowRender({ onCancel }) .instance() .handleKeyDown(mockEvent({ nativeEvent: { key: KeyboardKeys.Escape } })); - expect(onCancel).toBeCalled(); + expect(onCancel).toHaveBeenCalled(); }); it('should ignore other keys', () => { @@ -66,8 +66,8 @@ it('should ignore other keys', () => { shallowRender({ onCancel, onSave }) .instance() .handleKeyDown(mockEvent({ nativeEvent: { key: KeyboardKeys.LeftArrow } })); - expect(onSave).not.toBeCalled(); - expect(onCancel).not.toBeCalled(); + expect(onSave).not.toHaveBeenCalled(); + expect(onCancel).not.toHaveBeenCalled(); }); function shallowRender(overrides: Partial<SimpleInputProps> = {}) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/AlmSpecificForm-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/AlmSpecificForm-test.tsx index 23185bb1ed6..4e89001515b 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/AlmSpecificForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/AlmSpecificForm-test.tsx @@ -29,7 +29,7 @@ it.each([ [AlmKeys.BitbucketCloud], [AlmKeys.GitHub], [AlmKeys.GitLab] -])('it should render correctly for %s', alm => { +])('should render correctly for %s', alm => { expect(shallowRender(alm)).toMatchSnapshot(); }); @@ -41,7 +41,7 @@ it.each([ [AlmKeys.GitHub, [mockAlmSettingsInstance({ url: 'http://example.com/api/v3' })]], [AlmKeys.GitHub, [mockAlmSettingsInstance({ url: 'http://api.github.com' })]] ])( - 'it should render correctly for %s if an instance URL is provided', + 'should render correctly for %s if an instance URL is provided', (alm: AlmKeys, instances: AlmSettingsInstance[]) => { expect(shallowRender(alm, { instances })).toMatchSnapshot(); } diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx index 793ee25b46b..614b259dec9 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-test.tsx @@ -96,7 +96,7 @@ it('should handle reset', async () => { wrapper.instance().handleReset(); await waitAndUpdate(wrapper); - expect(deleteProjectAlmBinding).toBeCalledWith(PROJECT_KEY); + expect(deleteProjectAlmBinding).toHaveBeenCalledWith(PROJECT_KEY); expect(wrapper.state().formData).toEqual({ key: '', repository: '', slug: '', monorepo: false }); expect(wrapper.state().isChanged).toBe(false); }); @@ -124,7 +124,7 @@ describe('handleSubmit', () => { wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); - expect(setProjectGithubBinding).toBeCalledWith({ + expect(setProjectGithubBinding).toHaveBeenCalledWith({ almSetting: githubKey, project: PROJECT_KEY, repository, @@ -148,7 +148,7 @@ describe('handleSubmit', () => { wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); - expect(setProjectAzureBinding).toBeCalledWith({ + expect(setProjectAzureBinding).toHaveBeenCalledWith({ almSetting: azureKey, project: PROJECT_KEY, projectName: slug, @@ -169,7 +169,7 @@ describe('handleSubmit', () => { wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); - expect(setProjectBitbucketBinding).toBeCalledWith({ + expect(setProjectBitbucketBinding).toHaveBeenCalledWith({ almSetting: bitbucketKey, project: PROJECT_KEY, repository, @@ -192,7 +192,7 @@ describe('handleSubmit', () => { wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); - expect(setProjectGitlabBinding).toBeCalledWith({ + expect(setProjectGitlabBinding).toHaveBeenCalledWith({ almSetting: gitlabKey, project: PROJECT_KEY, repository, @@ -210,13 +210,13 @@ describe('handleSubmit', () => { wrapper.setState({ formData: { key: bitbucketKey, repository, monorepo }, instances: [] }); wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); - expect(setProjectBitbucketCloudBinding).not.toBeCalled(); + expect(setProjectBitbucketCloudBinding).not.toHaveBeenCalled(); wrapper.setState({ formData: { key: bitbucketKey, repository, monorepo }, instances }); wrapper.instance().handleSubmit(); await waitAndUpdate(wrapper); - expect(setProjectBitbucketCloudBinding).toBeCalledWith({ + expect(setProjectBitbucketCloudBinding).toHaveBeenCalledWith({ almSetting: bitbucketKey, project: PROJECT_KEY, repository, diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap index bb8f74738d6..b7413c7b625 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/__snapshots__/AlmSpecificForm-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`it should render correctly for azure 1`] = ` +exports[`should render correctly for azure 1`] = ` <Fragment> <div className="settings-definition" @@ -99,7 +99,7 @@ exports[`it should render correctly for azure 1`] = ` </Fragment> `; -exports[`it should render correctly for bitbucket 1`] = ` +exports[`should render correctly for bitbucket 1`] = ` <Fragment> <div className="settings-definition" @@ -202,7 +202,7 @@ exports[`it should render correctly for bitbucket 1`] = ` </Fragment> `; -exports[`it should render correctly for bitbucket if an instance URL is provided 1`] = ` +exports[`should render correctly for bitbucket if an instance URL is provided 1`] = ` <Fragment> <div className="settings-definition" @@ -305,7 +305,7 @@ exports[`it should render correctly for bitbucket if an instance URL is provided </Fragment> `; -exports[`it should render correctly for bitbucketcloud 1`] = ` +exports[`should render correctly for bitbucketcloud 1`] = ` <Fragment> <div className="settings-definition" @@ -358,7 +358,7 @@ exports[`it should render correctly for bitbucketcloud 1`] = ` </Fragment> `; -exports[`it should render correctly for github 1`] = ` +exports[`should render correctly for github 1`] = ` <Fragment> <div className="settings-definition" @@ -450,7 +450,7 @@ exports[`it should render correctly for github 1`] = ` </Fragment> `; -exports[`it should render correctly for github if an instance URL is provided 1`] = ` +exports[`should render correctly for github if an instance URL is provided 1`] = ` <Fragment> <div className="settings-definition" @@ -542,7 +542,7 @@ exports[`it should render correctly for github if an instance URL is provided 1` </Fragment> `; -exports[`it should render correctly for github if an instance URL is provided 2`] = ` +exports[`should render correctly for github if an instance URL is provided 2`] = ` <Fragment> <div className="settings-definition" @@ -634,7 +634,7 @@ exports[`it should render correctly for github if an instance URL is provided 2` </Fragment> `; -exports[`it should render correctly for gitlab 1`] = ` +exports[`should render correctly for gitlab 1`] = ` <Fragment> <div className="settings-definition" diff --git a/server/sonar-web/src/main/js/apps/settings/encryption/__tests__/EncryptionApp-test.tsx b/server/sonar-web/src/main/js/apps/settings/encryption/__tests__/EncryptionApp-test.tsx index ce52292f730..0707d96e493 100644 --- a/server/sonar-web/src/main/js/apps/settings/encryption/__tests__/EncryptionApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/encryption/__tests__/EncryptionApp-test.tsx @@ -41,7 +41,7 @@ it('should correctly check a key', async () => { const wrapper = shallowRender(); wrapper.instance().checkSecretKey(); await waitAndUpdate(wrapper); - expect(checkSecretKey).toBeCalled(); + expect(checkSecretKey).toHaveBeenCalled(); expect(wrapper.state().secretKeyAvailable).toBe(true); }); @@ -49,7 +49,7 @@ it('should correctly generate a key', async () => { const wrapper = shallowRender(); wrapper.instance().generateSecretKey(); await waitAndUpdate(wrapper); - expect(generateSecretKey).toBeCalled(); + expect(generateSecretKey).toHaveBeenCalled(); expect(wrapper.state().secretKey).toBe('secret'); expect(wrapper.state().secretKeyAvailable).toBe(false); }); diff --git a/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx index e231ef41d7d..e2425dc52c7 100644 --- a/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/__tests__/App-test.tsx @@ -52,7 +52,7 @@ it('should fetch system info', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getSystemInfo).toBeCalled(); + expect(getSystemInfo).toHaveBeenCalled(); expect(wrapper.state().sysInfoData).toBe(sysInfoData); }); @@ -62,7 +62,7 @@ it('should toggle cards and update the URL', () => { // Open wrapper.instance().toggleSysInfoCards('foo'); - expect(replace).toBeCalledWith( + expect(replace).toHaveBeenCalledWith( expect.objectContaining({ query: { expand: 'foo' } }) @@ -72,7 +72,7 @@ it('should toggle cards and update the URL', () => { replace.mockClear(); wrapper.setProps({ location: mockLocation({ query: { expand: 'foo,bar' } }) }); wrapper.instance().toggleSysInfoCards('foo'); - expect(replace).toBeCalledWith( + expect(replace).toHaveBeenCalledWith( expect.objectContaining({ query: { expand: 'bar' } }) diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/DeactivateForm-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/DeactivateForm-test.tsx index ac27a479063..dc49f44876a 100644 --- a/server/sonar-web/src/main/js/apps/users/components/__tests__/DeactivateForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/DeactivateForm-test.tsx @@ -29,15 +29,15 @@ jest.mock('../../../../api/users', () => ({ deactivateUser: jest.fn().mockResolvedValue({}) })); -it.each([true, false])('should deactivate user with anonymize set to %s', anonymize => { +it('should deactivate user with anonymize set to true', () => { const user = mockUser() as UserActive; renderDeactivateForm(user); - if (anonymize) { - screen.getByRole('checkbox').click(); - expect(screen.getByRole('alert')).toBeInTheDocument(); - } + + screen.getByRole('checkbox').click(); + expect(screen.getByRole('alert')).toBeInTheDocument(); + screen.getByRole('button', { name: 'users.deactivate' }).click(); - expect(deactivateUser).toBeCalledWith({ login: user.login, anonymize }); + expect(deactivateUser).toHaveBeenCalledWith({ login: user.login, anonymize: true }); }); function renderDeactivateForm(user: UserActive) { diff --git a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx index 66ed4cf7927..df36a221be6 100644 --- a/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/__tests__/UserForm-test.tsx @@ -83,7 +83,7 @@ it('should correctly create a new user', () => { submit(wrapper.dive().find('form')); - expect(createUser).toBeCalledWith({ + expect(createUser).toHaveBeenCalledWith({ email, login, name, @@ -101,7 +101,7 @@ it('should correctly update a local user', () => { submit(wrapper.find('form')); - expect(updateUser).toBeCalledWith({ + expect(updateUser).toHaveBeenCalledWith({ email, login, name, @@ -120,7 +120,7 @@ it('should correctly update a non-local user', () => { submit(wrapper.find('form')); - expect(updateUser).toBeCalledWith( + expect(updateUser).toHaveBeenCalledWith( expect.not.objectContaining({ email, name diff --git a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/WebApiApp-test.tsx b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/WebApiApp-test.tsx index faa0f6ce70e..ea897b894ae 100644 --- a/server/sonar-web/src/main/js/apps/web-api/components/__tests__/WebApiApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/web-api/components/__tests__/WebApiApp-test.tsx @@ -49,15 +49,15 @@ it('should render correctly', async () => { const wrapper = shallowRender(); - expect(addSideBarClass).toBeCalled(); - expect(fetchWebApi).toBeCalled(); + expect(addSideBarClass).toHaveBeenCalled(); + expect(fetchWebApi).toHaveBeenCalled(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); expect(wrapper.find('ScreenPositionHelper').dive()).toMatchSnapshot(); wrapper.unmount(); - expect(removeSideBarClass).toBeCalled(); + expect(removeSideBarClass).toHaveBeenCalled(); }); function shallowRender(props: Partial<WebApiApp['props']> = {}) { diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx index 96d3cd899cc..2c8fb34c2d4 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/App-test.tsx @@ -90,7 +90,7 @@ it('should correctly handle webhook creation', async () => { const webhook = { name: 'baz', url: 'http://baz' }; const wrapper = shallow(<App />); (wrapper.instance() as App).handleCreate({ ...webhook }); - expect(createWebhook).lastCalledWith({ + expect(createWebhook).toHaveBeenLastCalledWith({ ...webhook, project: undefined }); @@ -107,7 +107,7 @@ it('should correctly handle webhook creation', async () => { it('should correctly handle webhook deletion', async () => { const wrapper = shallow(<App />); (wrapper.instance() as App).handleDelete('2'); - expect(deleteWebhook).lastCalledWith({ webhook: '2' }); + expect(deleteWebhook).toHaveBeenLastCalledWith({ webhook: '2' }); await new Promise(setImmediate); wrapper.update(); @@ -118,7 +118,7 @@ it('should correctly handle webhook update', async () => { const newValues = { webhook: '1', name: 'Cfoo', url: 'http://cfoo' }; const wrapper = shallow(<App />); (wrapper.instance() as App).handleUpdate(newValues); - expect(updateWebhook).lastCalledWith(newValues); + expect(updateWebhook).toHaveBeenLastCalledWith(newValues); await new Promise(setImmediate); wrapper.update(); diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/DeliveriesForm-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/DeliveriesForm-test.tsx index 518c33726d8..46bbe4cbb54 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/DeliveriesForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/DeliveriesForm-test.tsx @@ -61,12 +61,15 @@ it('should render correctly', async () => { expect(wrapper).toMatchSnapshot(); await new Promise(setImmediate); - expect(searchDeliveries as jest.Mock<any>).lastCalledWith({ webhook: webhook.key, ps: 10 }); + expect(searchDeliveries as jest.Mock<any>).toHaveBeenLastCalledWith({ + webhook: webhook.key, + ps: 10 + }); wrapper.update(); expect(wrapper).toMatchSnapshot(); wrapper.find('ListFooter').prop<Function>('loadMore')(); - expect(searchDeliveries).lastCalledWith({ webhook: webhook.key, p: 2, ps: 10 }); + expect(searchDeliveries).toHaveBeenLastCalledWith({ webhook: webhook.key, p: 2, ps: 10 }); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/LatestDeliveryForm-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/LatestDeliveryForm-test.tsx index 86f0c16a19e..8e1a9b5af14 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/LatestDeliveryForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/LatestDeliveryForm-test.tsx @@ -49,7 +49,7 @@ it('should render correctly', async () => { expect(wrapper).toMatchSnapshot(); await new Promise(setImmediate); - expect(getDelivery).lastCalledWith({ deliveryId: delivery.id }); + expect(getDelivery).toHaveBeenLastCalledWith({ deliveryId: delivery.id }); wrapper.update(); expect(wrapper).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx index be890a9507f..443f48fb5d6 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/PageActions-test.tsx @@ -43,7 +43,7 @@ it('should display the create form', () => { name: 'foo', url: 'http://foo.bar' }); - expect(onCreate).lastCalledWith({ name: 'foo', url: 'http://foo.bar' }); + expect(onCreate).toHaveBeenLastCalledWith({ name: 'foo', url: 'http://foo.bar' }); }); function getWrapper(props = {}) { diff --git a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx index fd19dd7a1bb..f82ec5b3b32 100644 --- a/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx +++ b/server/sonar-web/src/main/js/apps/webhooks/components/__tests__/WebhookActions-test.tsx @@ -49,7 +49,11 @@ it('should display the update webhook form', () => { name: webhook.name, url: webhook.url }); - expect(onUpdate).lastCalledWith({ webhook: webhook.key, name: webhook.name, url: webhook.url }); + expect(onUpdate).toHaveBeenLastCalledWith({ + webhook: webhook.key, + name: webhook.name, + url: webhook.url + }); }); it('should display the delete webhook form', () => { @@ -58,7 +62,7 @@ it('should display the delete webhook form', () => { click(wrapper.find('.js-webhook-delete')); expect(wrapper.find('DeleteWebhookForm').exists()).toBe(true); wrapper.find('DeleteWebhookForm').prop<Function>('onSubmit')(); - expect(onDelete).lastCalledWith(webhook.key); + expect(onDelete).toHaveBeenLastCalledWith(webhook.key); }); it('should display the deliveries form', () => { diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx index 265b0a4abdc..9ad5f0ba05e 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx @@ -312,10 +312,10 @@ it('should show issue indicator', async () => { ).toBeInTheDocument(); await user.click(firstIssueBox); - expect(onIssueSelect).toBeCalledWith('first-issue'); + expect(onIssueSelect).toHaveBeenCalledWith('first-issue'); await user.click(secondIssueBox); - expect(onIssueSelect).toBeCalledWith('second-issue'); + expect(onIssueSelect).toHaveBeenCalledWith('second-issue'); }); it('should show coverage information', async () => { diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-test.tsx index 48c0f9c3bcf..e59897ea35e 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-test.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-test.tsx @@ -76,8 +76,8 @@ it('should load sources before', async () => { wrapper.instance().loadSourcesBefore(); expect(wrapper.state().loadingSourcesBefore).toBe(true); - expect(defaultLoadIssues).toBeCalledTimes(1); - expect(getSources).toBeCalledTimes(2); + expect(defaultLoadIssues).toHaveBeenCalledTimes(1); + expect(getSources).toHaveBeenCalledTimes(2); await waitAndUpdate(wrapper); expect(wrapper.state().loadingSourcesBefore).toBe(false); @@ -103,8 +103,8 @@ it('should load sources after', async () => { wrapper.instance().loadSourcesAfter(); expect(wrapper.state().loadingSourcesAfter).toBe(true); - expect(defaultLoadIssues).toBeCalledTimes(1); - expect(getSources).toBeCalledTimes(2); + expect(defaultLoadIssues).toHaveBeenCalledTimes(1); + expect(getSources).toHaveBeenCalledTimes(2); await waitAndUpdate(wrapper); diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx index 5d1ecb223e9..5d36ff80d13 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx @@ -52,13 +52,13 @@ it('handles the opening and closing of issues', () => { const instance = wrapper.instance(); instance.handleIssuesIndicatorClick(); - expect(onIssuesClose).toBeCalledWith(line); - expect(onIssueUnselect).toBeCalled(); + expect(onIssuesClose).toHaveBeenCalledWith(line); + expect(onIssueUnselect).toHaveBeenCalled(); wrapper.setProps({ openIssues: false }); instance.handleIssuesIndicatorClick(); - expect(onIssuesOpen).toBeCalledWith(line); - expect(onIssueSelect).toBeCalledWith(issue.key); + expect(onIssuesOpen).toHaveBeenCalledWith(line); + expect(onIssueSelect).toHaveBeenCalledWith(issue.key); }); function shallowRender(props: Partial<Line['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/a11y/__tests__/A11ySkipTarget-test.tsx b/server/sonar-web/src/main/js/components/a11y/__tests__/A11ySkipTarget-test.tsx index 55083e63a02..8a8591a4278 100644 --- a/server/sonar-web/src/main/js/components/a11y/__tests__/A11ySkipTarget-test.tsx +++ b/server/sonar-web/src/main/js/components/a11y/__tests__/A11ySkipTarget-test.tsx @@ -35,7 +35,7 @@ it('should render correctly, and (un)register the link when (un)mounted', () => ); expect(wrapper).toMatchSnapshot(); - expect(addA11ySkipLink).toBeCalledWith(link); + expect(addA11ySkipLink).toHaveBeenCalledWith(link); wrapper.unmount(); - expect(removeA11ySkipLink).toBeCalledWith(link); + expect(removeA11ySkipLink).toHaveBeenCalledWith(link); }); diff --git a/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphsLegendItem-test.tsx b/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphsLegendItem-test.tsx index 5bf1c4cf09b..b527754561d 100644 --- a/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphsLegendItem-test.tsx +++ b/server/sonar-web/src/main/js/components/activity-graph/__tests__/GraphsLegendItem-test.tsx @@ -41,7 +41,7 @@ it('should correctly handle clicks', () => { const removeMetric = jest.fn(); const wrapper = shallowRender({ removeMetric }); click(wrapper.find(ClearButton)); - expect(removeMetric).toBeCalledWith('bugs'); + expect(removeMetric).toHaveBeenCalledWith('bugs'); }); function shallowRender(props: Partial<GraphsLegendItem['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/AdvancedTimeline-test.tsx b/server/sonar-web/src/main/js/components/charts/__tests__/AdvancedTimeline-test.tsx index 41e66d703b4..d9f5beea736 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/AdvancedTimeline-test.tsx +++ b/server/sonar-web/src/main/js/components/charts/__tests__/AdvancedTimeline-test.tsx @@ -133,7 +133,7 @@ it('should update timeline when width changes', () => { expect(wrapper.state().xScale).toEqual(expect.any(Function)); expect(wrapper.state().selectedDateXPos).not.toBe(selectedDateXPos); expect(wrapper.state().selectedDateXPos).toEqual(expect.any(Number)); - expect(updateTooltip).toBeCalled(); + expect(updateTooltip).toHaveBeenCalled(); }); it('should update tootlips when selected date changes', () => { @@ -148,7 +148,7 @@ it('should update tootlips when selected date changes', () => { expect(wrapper.state().selectedDate).toBe(selectedDate); expect(wrapper.state().selectedDateXPos).not.toBe(selectedDateXPos); expect(wrapper.state().selectedDateXPos).toEqual(expect.any(Number)); - expect(updateTooltip).toBeCalled(); + expect(updateTooltip).toHaveBeenCalled(); }); it('should handle scroll correcly', () => { @@ -176,8 +176,8 @@ it('should handle scroll correcly', () => { }) } as any) as SVGElement } as any) as React.WheelEvent<SVGElement>); - expect(preventDefault).toBeCalled(); - expect(updateZoom).toBeCalledWith(new Date('2019-10-01T06:24:00.000Z'), undefined); + expect(preventDefault).toHaveBeenCalled(); + expect(updateZoom).toHaveBeenCalledWith(new Date('2019-10-01T06:24:00.000Z'), undefined); updateZoom = jest.fn(); preventDefault = jest.fn(); @@ -204,8 +204,8 @@ it('should handle scroll correcly', () => { }) } as any) as SVGElement } as any) as React.WheelEvent<SVGElement>); - expect(preventDefault).toBeCalled(); - expect(updateZoom).toBeCalledWith(undefined, new Date('2019-10-02T20:48:00.000Z')); + expect(preventDefault).toHaveBeenCalled(); + expect(updateZoom).toHaveBeenCalledWith(undefined, new Date('2019-10-02T20:48:00.000Z')); }); it('should handle mouse out correcly', () => { @@ -235,12 +235,12 @@ it('should handle click correcly', () => { wrapper.setState({ selectedDate: new Date() }); wrapper.instance().handleClick(); - expect(updateSelectedDate).toBeCalledWith(wrapper.state().selectedDate); + expect(updateSelectedDate).toHaveBeenCalledWith(wrapper.state().selectedDate); wrapper.setProps({ updateSelectedDate: undefined }); updateSelectedDate.mockClear(); wrapper.instance().handleClick(); - expect(updateSelectedDate).not.toBeCalled(); + expect(updateSelectedDate).not.toHaveBeenCalled(); }); function shallowRender(props?: Partial<AdvancedTimeline['props']>) { diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/BubbleChart-test.tsx b/server/sonar-web/src/main/js/components/charts/__tests__/BubbleChart-test.tsx index d6f5b7577c2..2ce6a4bc653 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/BubbleChart-test.tsx +++ b/server/sonar-web/src/main/js/components/charts/__tests__/BubbleChart-test.tsx @@ -83,7 +83,7 @@ it('should render bubbles with click handlers', () => { click(bubble.dive().find('a')); expect(bubble.dive()).toMatchSnapshot(); }); - expect(onBubbleClick).toBeCalledTimes(2); + expect(onBubbleClick).toHaveBeenCalledTimes(2); expect(onBubbleClick).toHaveBeenLastCalledWith(mockComponentMeasureEnhanced()); }); @@ -128,8 +128,8 @@ it('should correctly handle zooming', () => { const stopPropagation = jest.fn(); const preventDefault = jest.fn(); resetZoomClick(mockEvent({ stopPropagation, preventDefault })); - expect(stopPropagation).toBeCalled(); - expect(preventDefault).toBeCalled(); + expect(stopPropagation).toHaveBeenCalled(); + expect(preventDefault).toHaveBeenCalled(); expect(call).toHaveBeenCalledWith(zoomBehavior); resolve(); diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/ColorRatingsLegend-test.tsx b/server/sonar-web/src/main/js/components/charts/__tests__/ColorRatingsLegend-test.tsx index 37b179cfa6b..741f8b4b7fd 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/ColorRatingsLegend-test.tsx +++ b/server/sonar-web/src/main/js/components/charts/__tests__/ColorRatingsLegend-test.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { screen } from '@testing-library/dom'; +import { screen } from '@testing-library/react'; import * as React from 'react'; import { renderComponent } from '../../../helpers/testReactTestingUtils'; import ColorRatingsLegend, { ColorRatingsLegendProps } from '../ColorRatingsLegend'; @@ -36,7 +36,7 @@ it('should react when a rating is clicked', () => { renderColorRatingsLegend({ onRatingClick }); screen.getByRole('checkbox', { name: 'D' }).click(); - expect(onRatingClick).toBeCalledWith(4); + expect(onRatingClick).toHaveBeenCalledWith(4); }); function renderColorRatingsLegend(props: Partial<ColorRatingsLegendProps> = {}) { diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/ZoomTimeLine-test.tsx b/server/sonar-web/src/main/js/components/charts/__tests__/ZoomTimeLine-test.tsx index 6fb49958b94..458c565546f 100644 --- a/server/sonar-web/src/main/js/components/charts/__tests__/ZoomTimeLine-test.tsx +++ b/server/sonar-web/src/main/js/components/charts/__tests__/ZoomTimeLine-test.tsx @@ -89,7 +89,7 @@ it('should handle zoom update correctly', () => { .range([0, 150]), [3, 50] ); - expect(updateZoom).toBeCalledWith( + expect(updateZoom).toHaveBeenCalledWith( new Date('1970-08-08T03:21:36.001Z'), new Date('1980-01-01T08:00:00.001Z') ); @@ -104,7 +104,7 @@ it('should handle zoom update correctly', () => { .range([0, 150]), [-1, 151] ); - expect(updateZoom).toBeCalledWith(undefined, undefined); + expect(updateZoom).toHaveBeenCalledWith(undefined, undefined); }); function shallowRender(props: Partial<ZoomTimeLine['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx index bd8f9d4a99a..23efe791c4c 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/AnalysisWarningsModal-test.tsx @@ -50,14 +50,14 @@ it('should render correctly', () => { it('should not fetch task warnings if it does not have to', () => { shallowRender(); - expect(getTask).not.toBeCalled(); + expect(getTask).not.toHaveBeenCalled(); }); it('should fetch task warnings if it has to', async () => { const wrapper = shallowRender({ taskId: 'abcd1234', warnings: undefined }); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(getTask).toBeCalledWith('abcd1234', ['warnings']); + expect(getTask).toHaveBeenCalledWith('abcd1234', ['warnings']); }); it('should correctly handle dismissing warnings', async () => { @@ -79,23 +79,23 @@ it('should correctly handle dismissing warnings', async () => { await waitAndUpdate(wrapper); - expect(dismissAnalysisWarning).toBeCalledWith('foo', 'bar'); - expect(onWarningDismiss).toBeCalled(); + expect(dismissAnalysisWarning).toHaveBeenCalledWith('foo', 'bar'); + expect(onWarningDismiss).toHaveBeenCalled(); }); it('should correctly handle updates', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getTask).not.toBeCalled(); + expect(getTask).not.toHaveBeenCalled(); wrapper.setProps({ taskId: '1', warnings: undefined }); await waitAndUpdate(wrapper); - expect(getTask).toBeCalled(); + expect(getTask).toHaveBeenCalled(); (getTask as jest.Mock).mockClear(); wrapper.setProps({ taskId: undefined, warnings: [mockTaskWarning()] }); - expect(getTask).not.toBeCalled(); + expect(getTask).not.toHaveBeenCalled(); }); function shallowRender(props: Partial<AnalysisWarningsModal['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/common/__tests__/FormattingTips-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/FormattingTips-test.tsx index 00073d9e211..a478c20db70 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/FormattingTips-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/FormattingTips-test.tsx @@ -44,9 +44,9 @@ it('should render correctly', () => { it('should correctly open a new window', () => { const wrapper = shallowRender(); - expect(window.open).not.toBeCalled(); + expect(window.open).not.toHaveBeenCalled(); click(wrapper.find('a')); - expect(window.open).toBeCalled(); + expect(window.open).toHaveBeenCalled(); }); function shallowRender(props: Partial<FormattingTips['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/common/__tests__/Link-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/Link-test.tsx index 2de4d6ffdcb..6781926337d 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/Link-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/Link-test.tsx @@ -30,12 +30,12 @@ it('should correctly render an internal link', () => { it('should correctly render a link that opens in a new window, but is not considered external', () => { renderLink({ target: '_blank', to: '/path' }); - expect(screen.getByRole('link').getAttribute('rel')).toBe('noopener noreferrer'); + expect(screen.getByRole('link')).toHaveAttribute('rel', 'noopener noreferrer'); }); it('should correctly render an external link', () => { renderLink({ target: '_blank', to: 'http://example.com' }); - expect(screen.getByRole('link').getAttribute('rel')).toBe('noopener noreferrer'); + expect(screen.getByRole('link')).toHaveAttribute('rel', 'noopener noreferrer'); expect(screen.getByLabelText('opens_in_new_window')).toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx index 83a56c9d804..34e1023031d 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/ResetPasswordForm-test.tsx @@ -32,12 +32,12 @@ it('should trigger on password change prop', () => { const onPasswordChange = jest.fn(); const wrapper = shallowRender({ onPasswordChange }); wrapper.instance().handleSuccessfulChange(); - expect(onPasswordChange).not.toBeCalled(); + expect(onPasswordChange).not.toHaveBeenCalled(); wrapper.instance().oldPassword = { value: '' } as HTMLInputElement; wrapper.instance().password = { value: '' } as HTMLInputElement; wrapper.instance().passwordConfirmation = { value: '' } as HTMLInputElement; wrapper.instance().handleSuccessfulChange(); - expect(onPasswordChange).toBeCalled(); + expect(onPasswordChange).toHaveBeenCalled(); }); it('should not trigger password change', () => { @@ -46,7 +46,7 @@ it('should not trigger password change', () => { wrapper.instance().password = { value: 'test', focus: () => {} } as HTMLInputElement; wrapper.instance().passwordConfirmation = { value: 'test1' } as HTMLInputElement; wrapper.instance().handleChangePassword(mockEvent()); - expect(changePassword).not.toBeCalled(); + expect(changePassword).not.toHaveBeenCalled(); expect(wrapper.state().errors).toBeDefined(); }); @@ -55,7 +55,7 @@ it('should trigger password change', async () => { const wrapper = shallowRender({ user }); wrapper.instance().handleChangePassword(mockEvent()); await waitAndUpdate(wrapper); - expect(changePassword).not.toBeCalled(); + expect(changePassword).not.toHaveBeenCalled(); wrapper.instance().oldPassword = { value: 'testold' } as HTMLInputElement; wrapper.instance().password = { value: 'test' } as HTMLInputElement; @@ -63,7 +63,7 @@ it('should trigger password change', async () => { wrapper.instance().handleChangePassword(mockEvent()); await waitAndUpdate(wrapper); - expect(changePassword).toBeCalledWith({ + expect(changePassword).toHaveBeenCalledWith({ login: user.login, password: 'test', previousPassword: 'testold' diff --git a/server/sonar-web/src/main/js/components/common/__tests__/SelectList-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/SelectList-test.tsx index 66d6dbd063b..f81935ff561 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/SelectList-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/SelectList-test.tsx @@ -63,7 +63,7 @@ it('should correclty handle user actions', () => { keydown({ key: KeyboardKeys.UpArrow }); expect(list.state().selected).toBe('seconditem'); keydown({ key: KeyboardKeys.Enter }); - expect(onSelect).toBeCalledWith('seconditem'); + expect(onSelect).toHaveBeenCalledWith('seconditem'); list.instance().componentWillUnmount!(); }); diff --git a/server/sonar-web/src/main/js/components/common/__tests__/VisibilitySelector-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/VisibilitySelector-test.tsx index d39287a4e35..b16a241f969 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/VisibilitySelector-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/VisibilitySelector-test.tsx @@ -32,7 +32,7 @@ it('changes visibility', () => { .first() .props() .onCheck('private'); - expect(onChange).toBeCalledWith('private'); + expect(onChange).toHaveBeenCalledWith('private'); wrapper.setProps({ visibility: 'private' }); expect(wrapper).toMatchSnapshot(); @@ -42,7 +42,7 @@ it('changes visibility', () => { .first() .props() .onCheck('public'); - expect(onChange).toBeCalledWith('public'); + expect(onChange).toHaveBeenCalledWith('public'); }); it('renders disabled', () => { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ActionsDropdown-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ActionsDropdown-test.tsx index 611920edcfd..60c7d6a00e3 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ActionsDropdown-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ActionsDropdown-test.tsx @@ -59,7 +59,7 @@ describe('ActionsDropdownItem', () => { const onClick = jest.fn(); const wrapper = shallowRender({ onClick }); click(wrapper.find('a')); - expect(onClick).toBeCalled(); + expect(onClick).toHaveBeenCalled(); }); function shallowRender(props: Partial<ActionsDropdownItem['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/BackButton-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/BackButton-test.tsx index 8c7415b0312..40525562433 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/BackButton-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/BackButton-test.tsx @@ -32,7 +32,7 @@ it('should handle click', () => { const wrapper = shallowRender({ onClick }); expect(wrapper).toMatchSnapshot(); click(wrapper.find('a')); - expect(onClick).toBeCalled(); + expect(onClick).toHaveBeenCalled(); }); function shallowRender(props: Partial<BackButton['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx index c1569132cbe..11092c58b2d 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/BoxedGroupAccordion-test.tsx @@ -28,7 +28,7 @@ it('should behave correctly', async () => { renderDeliveryAccordion(); expect(screen.queryByText('children')).not.toBeInTheDocument(); await user.click(screen.getByRole('button', { expanded: false })); - expect(screen.queryByText('children')).toBeInTheDocument(); + expect(screen.getByText('children')).toBeInTheDocument(); }); it('should render header correctly', () => { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx index cd987b866fa..0bce5a8b967 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Checkbox-test.tsx @@ -48,7 +48,7 @@ describe.each([ it('should accept partial state', () => { renderCheckbox({ label: 'me', thirdState: true, children, checked: false }); - expect(screen.getByRole('checkbox', { name: 'me' })).toHaveAttribute('aria-checked', 'mixed'); + expect(screen.getByRole('checkbox', { name: 'me' })).not.toBeChecked(); }); it('should render loading state', () => { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ClickEventBoundary-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ClickEventBoundary-test.tsx index 0a4ccfbc10e..ad833169842 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ClickEventBoundary-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ClickEventBoundary-test.tsx @@ -31,8 +31,8 @@ it('should correctly capture a click event', () => { const wrapper = shallowRender({ onClick: parentOnClick }, { onClick: childOnClick }); // Don't use our click() helper, so we make sure the bubbling works correctly. wrapper.find('button').simulate('click'); - expect(childOnClick).toBeCalled(); - expect(parentOnClick).not.toBeCalled(); + expect(childOnClick).toHaveBeenCalled(); + expect(parentOnClick).not.toHaveBeenCalled(); }); function shallowRender(parentProps = {}, childProps = {}) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ConfirmModal-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ConfirmModal-test.tsx index df0619c302a..8a7ca0ccd4e 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ConfirmModal-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ConfirmModal-test.tsx @@ -52,7 +52,7 @@ it('should confirm and close after confirm', async () => { ); const modalContent = wrapper.find('SimpleModal').dive(); submit(modalContent.find('form')); - expect(onConfirm).toBeCalledWith('data'); + expect(onConfirm).toHaveBeenCalledWith('data'); expect(modalContent.find('footer')).toMatchSnapshot(); await waitAndUpdate(wrapper); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/DateInput-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/DateInput-test.tsx index af5f77d7fe4..c5792886537 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/DateInput-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/DateInput-test.tsx @@ -66,17 +66,17 @@ it('should select a day', () => { wrapper.setState({ open: true }); instance.handleDayClick(dateA, { disabled: true, outside: undefined, today: undefined }); - expect(onChange).not.toBeCalled(); + expect(onChange).not.toHaveBeenCalled(); expect(wrapper.state().open).toBe(true); instance.handleDayClick(dateA, { outside: undefined, today: undefined }); - expect(onChange).lastCalledWith(dateA); + expect(onChange).toHaveBeenLastCalledWith(dateA); wrapper.update(); expect(wrapper.state().open).toBe(false); expect(wrapper).toMatchSnapshot(); instance.handleResetClick(); - expect(onChange).lastCalledWith(undefined); + expect(onChange).toHaveBeenLastCalledWith(undefined); }); it('should hightlightFrom range', () => { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/DateRangeInput-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/DateRangeInput-test.tsx index 01e0e24f717..07082c970d3 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/DateRangeInput-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/DateRangeInput-test.tsx @@ -51,10 +51,10 @@ it('should change', () => { const wrapper = shallow(<DateRangeInput onChange={onChange} />); wrapper.find('DateInput[data-test="from"]').prop<Function>('onChange')(dateA); - expect(onChange).lastCalledWith({ from: dateA, to: undefined }); + expect(onChange).toHaveBeenLastCalledWith({ from: dateA, to: undefined }); wrapper.setProps({ value: { from: dateA } }); wrapper.find('DateInput[data-test="to"]').prop<Function>('onChange')(dateB); wrapper.update(); - expect(onChange).lastCalledWith({ from: dateA, to: dateB }); + expect(onChange).toHaveBeenLastCalledWith({ from: dateA, to: dateB }); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Dropdown-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Dropdown-test.tsx index 7b17e5b0699..d95dcb2efca 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Dropdown-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Dropdown-test.tsx @@ -72,9 +72,9 @@ describe('Dropdown', () => { <Button /> </Dropdown> ); - expect(onOpen).not.toBeCalled(); + expect(onOpen).not.toHaveBeenCalled(); click(wrapper.find('Button')); - expect(onOpen).toBeCalled(); + expect(onOpen).toHaveBeenCalled(); }); function checkToggle(wrapper: ShallowWrapper, selector = 'Button') { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.tsx index a641cc0c1ee..24264836697 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ListFooter-test.tsx @@ -57,14 +57,14 @@ it('should properly call loadMore', () => { const loadMore = jest.fn(); const wrapper = shallowRender({ loadMore }); click(wrapper.find(Button)); - expect(loadMore).toBeCalled(); + expect(loadMore).toHaveBeenCalled(); }); it('should properly call reload', () => { const reload = jest.fn(); const wrapper = shallowRender({ needReload: true, reload }); click(wrapper.find(Button)); - expect(reload).toBeCalled(); + expect(reload).toHaveBeenCalled(); }); function shallowRender(props: Partial<ListFooterProps> = {}) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ReloadButton-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ReloadButton-test.tsx index e5681155378..e09624a7db9 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ReloadButton-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ReloadButton-test.tsx @@ -32,7 +32,7 @@ it('should handle click', () => { const wrapper = shallowRender({ onClick }); expect(wrapper).toMatchSnapshot(); click(wrapper.find('a')); - expect(onClick).toBeCalled(); + expect(onClick).toHaveBeenCalled(); }); function shallowRender(props: Partial<ReloadButton['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/SearchBox-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/SearchBox-test.tsx index 8adf4643bfe..5977c6e09d5 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/SearchBox-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/SearchBox-test.tsx @@ -62,7 +62,7 @@ it('shows clear button only when there is a value', () => { it('attaches ref', () => { const ref = jest.fn(); mount(<SearchBox innerRef={ref} onChange={jest.fn()} placeholder="placeholder" value="f" />); - expect(ref).toBeCalled(); + expect(ref).toHaveBeenCalled(); expect(ref.mock.calls[0][0]).toBeInstanceOf(HTMLInputElement); }); @@ -70,14 +70,14 @@ it('resets', () => { const onChange = jest.fn(); const wrapper = shallow(<SearchBox onChange={onChange} placeholder="placeholder" value="f" />); click(wrapper.find('.search-box-clear')); - expect(onChange).toBeCalledWith(''); + expect(onChange).toHaveBeenCalledWith(''); }); it('changes', () => { const onChange = jest.fn(); const wrapper = shallow(<SearchBox onChange={onChange} placeholder="placeholder" value="f" />); change(wrapper.find('.search-box-input'), 'foo'); - expect(onChange).toBeCalledWith('foo'); + expect(onChange).toHaveBeenCalledWith('foo'); }); it('does not change when value is too short', () => { @@ -86,5 +86,5 @@ it('does not change when value is too short', () => { <SearchBox minLength={3} onChange={onChange} placeholder="placeholder" value="" /> ); change(wrapper.find('.search-box-input'), 'fo'); - expect(onChange).not.toBeCalled(); + expect(onChange).not.toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/SimpleModal-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/SimpleModal-test.tsx index 55e3edadc78..6f93e21ce8d 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/SimpleModal-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/SimpleModal-test.tsx @@ -34,7 +34,7 @@ it('closes', () => { ); const wrapper = shallowRender({ children, onClose }); click(wrapper.find('Button')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); it('submits', async () => { @@ -49,7 +49,7 @@ it('submits', async () => { expect(wrapper).toMatchSnapshot(); click(wrapper.find('Button')); - expect(onSubmit).toBeCalled(); + expect(onSubmit).toHaveBeenCalled(); expect(wrapper).toMatchSnapshot(); await waitAndUpdate(wrapper); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.tsx index b33b8583a26..0848bd32ef4 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Toggle-test.tsx @@ -33,7 +33,7 @@ it('should call onChange when clicked', () => { const onChange = jest.fn(); const wrapper = shallowRender({ disabled: false, onChange, value: true }); click(wrapper.find(Button)); - expect(onChange).toBeCalledWith(false); + expect(onChange).toHaveBeenCalledWith(false); }); function shallowRender(props?: Partial<Toggle['props']>) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx index e02b980294e..b4fc7e2ec11 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Tooltip-test.tsx @@ -67,24 +67,24 @@ it('should open & close', () => { jest.runOnlyPendingTimers(); wrapper.update(); expect(wrapper.find('TooltipPortal').exists()).toBe(true); - expect(onShow).toBeCalled(); + expect(onShow).toHaveBeenCalled(); wrapper.find('#tooltip').simulate('pointerleave'); jest.runOnlyPendingTimers(); wrapper.update(); expect(wrapper.find('TooltipPortal').exists()).toBe(false); - expect(onHide).toBeCalled(); + expect(onHide).toHaveBeenCalled(); onShow.mockReset(); onHide.mockReset(); wrapper.find('#tooltip').simulate('focus'); expect(wrapper.find('TooltipPortal').exists()).toBe(true); - expect(onShow).toBeCalled(); + expect(onShow).toHaveBeenCalled(); wrapper.find('#tooltip').simulate('blur'); expect(wrapper.find('TooltipPortal').exists()).toBe(false); - expect(onHide).toBeCalled(); + expect(onHide).toHaveBeenCalled(); }); it('should not open when pointer goes away quickly', () => { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx index 589c31247e4..c4496bd08a8 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationForm-test.tsx @@ -32,16 +32,16 @@ it('should render and submit', async () => { ); expect(wrapper).toMatchSnapshot(); wrapper.dive(); - expect(render).toBeCalledWith( + expect(render).toHaveBeenCalledWith( expect.objectContaining({ dirty: false, errors: {}, values: { foo: 'bar' } }) ); wrapper.prop<Function>('onSubmit')({ foo: 'bar' }, { setSubmitting }); - expect(setSubmitting).toBeCalledWith(false); + expect(setSubmitting).toHaveBeenCalledWith(false); onSubmit.mockResolvedValue(undefined).mockClear(); setSubmitting.mockClear(); wrapper.prop<Function>('onSubmit')({ foo: 'bar' }, { setSubmitting }); await new Promise(setImmediate); - expect(setSubmitting).toBeCalledWith(false); + expect(setSubmitting).toHaveBeenCalledWith(false); }); diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx index a233d35807b..1be93af16b6 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ValidationModal-test.tsx @@ -41,10 +41,10 @@ it('should handle submit', async () => { const wrapper = shallowRender({ onClose, onSubmit }); wrapper.instance().handleSubmit(data); - expect(onSubmit).toBeCalledWith(data); + expect(onSubmit).toHaveBeenCalledWith(data); await waitAndUpdate(wrapper); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); function shallowRender(props: Partial<ValidationModal<{ field: string }>['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/buttons-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/buttons-test.tsx index 811bf2380c6..13d4ac4019a 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/buttons-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/buttons-test.tsx @@ -30,9 +30,9 @@ describe('Button', () => { const wrapper = shallowRender({ onClick }); expect(wrapper).toMatchSnapshot(); click(wrapper.find('button'), mockEvent({ preventDefault, stopPropagation })); - expect(onClick).toBeCalled(); - expect(preventDefault).toBeCalled(); - expect(stopPropagation).not.toBeCalled(); + expect(onClick).toHaveBeenCalled(); + expect(preventDefault).toHaveBeenCalled(); + expect(stopPropagation).not.toHaveBeenCalled(); }); it('should not stop propagation, but prevent default of the click event', () => { @@ -40,8 +40,8 @@ describe('Button', () => { const stopPropagation = jest.fn(); const wrapper = shallowRender({ preventDefault: false, stopPropagation: true }); click(wrapper.find('button'), mockEvent({ preventDefault, stopPropagation })); - expect(preventDefault).not.toBeCalled(); - expect(stopPropagation).toBeCalled(); + expect(preventDefault).not.toHaveBeenCalled(); + expect(stopPropagation).toHaveBeenCalled(); }); it('should disable buttons with a class', () => { @@ -52,8 +52,8 @@ describe('Button', () => { expect(button.props().className).toContain('disabled'); expect(button.props()['aria-disabled']).toBe(true); click(button, mockEvent({ preventDefault })); - expect(onClick).not.toBeCalled(); - expect(preventDefault).toBeCalled(); + expect(onClick).not.toHaveBeenCalled(); + expect(preventDefault).toHaveBeenCalled(); }); function shallowRender(props: Partial<Button['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx index a062a3d0f81..1df772fbe6f 100644 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx +++ b/server/sonar-web/src/main/js/components/docs/__tests__/DocMarkdownBlock-test.tsx @@ -114,20 +114,20 @@ it('should correctly scroll to clicked headings', () => { // Node Ref isn't set yet. instance.handleAnchorClick('#unknown', mockEvent()); - expect(scrollToElement).not.toBeCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); // Set node Ref. instance.node = { querySelector } as HTMLElement; // Unknown element. instance.handleAnchorClick('#unknown', mockEvent()); - expect(scrollToElement).not.toBeCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); // Known element, should scroll. instance.handleAnchorClick('#id', mockEvent({ preventDefault })); - expect(scrollToElement).toBeCalledWith(element, { bottomOffset: 720 }); - expect(preventDefault).toBeCalled(); - expect(historyPushState).toBeCalledWith(null, '', '#id'); + expect(scrollToElement).toHaveBeenCalledWith(element, { bottomOffset: 720 }); + expect(preventDefault).toHaveBeenCalled(); + expect(historyPushState).toHaveBeenCalledWith(null, '', '#id'); }); it('should correctly scroll to a specific heading if passed as a prop', () => { @@ -139,11 +139,11 @@ it('should correctly scroll to a specific heading if passed as a prop', () => { const instance = wrapper.instance(); instance.node = { querySelector } as HTMLElement; - expect(scrollToElement).not.toBeCalled(); + expect(scrollToElement).not.toHaveBeenCalled(); jest.runAllTimers(); - expect(scrollToElement).toBeCalledWith(element, { bottomOffset: 720 }); + expect(scrollToElement).toHaveBeenCalledWith(element, { bottomOffset: 720 }); jest.runOnlyPendingTimers(); jest.useRealTimers(); }); diff --git a/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx b/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx index 0d0fbe25906..1a837603275 100644 --- a/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx +++ b/server/sonar-web/src/main/js/components/docs/__tests__/DocToc-test.tsx @@ -73,7 +73,7 @@ it('should trigger the handler when an anchor is clicked', () => { const onAnchorClick = jest.fn(); const wrapper = renderComponent({ onAnchorClick }); click(wrapper.find('a[href="#sit-amet"]')); - expect(onAnchorClick).toBeCalled(); + expect(onAnchorClick).toHaveBeenCalled(); }); it('should highlight anchors when scrolling', () => { diff --git a/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx b/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx index 0b1d70d7bf7..887f75a1097 100644 --- a/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx +++ b/server/sonar-web/src/main/js/components/facet/__tests__/Facet-it.tsx @@ -45,7 +45,7 @@ it('should render and function correctly', () => { const facet1 = screen.getByRole('checkbox', { name: 'Foo/Bar 10' }); expect(facet1).toHaveClass('active'); facet1.click(); - expect(onFacetClick).toBeCalledWith('bar', false); + expect(onFacetClick).toHaveBeenCalledWith('bar', false); const facet2 = screen.getByRole('checkbox', { name: 'Foo/Baz' }); expect(facet2).not.toHaveClass('active'); diff --git a/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx b/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx index b7f65b91cb6..a6c9e7430be 100644 --- a/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx +++ b/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacet-test.tsx @@ -33,42 +33,42 @@ it('should select items', () => { // select one item instance.handleItemClick('b', false); - expect(onChange).lastCalledWith({ foo: ['b'] }); + expect(onChange).toHaveBeenLastCalledWith({ foo: ['b'] }); wrapper.setProps({ values: ['b'] }); // select another item instance.handleItemClick('a', false); - expect(onChange).lastCalledWith({ foo: ['a'] }); + expect(onChange).toHaveBeenLastCalledWith({ foo: ['a'] }); wrapper.setProps({ values: ['a'] }); // unselect item instance.handleItemClick('a', false); - expect(onChange).lastCalledWith({ foo: [] }); + expect(onChange).toHaveBeenLastCalledWith({ foo: [] }); wrapper.setProps({ values: [] }); // select multiple items wrapper.setProps({ values: ['b'] }); instance.handleItemClick('c', true); - expect(onChange).lastCalledWith({ foo: ['b', 'c'] }); + expect(onChange).toHaveBeenLastCalledWith({ foo: ['b', 'c'] }); wrapper.setProps({ values: ['b', 'c'] }); // unselect item instance.handleItemClick('c', true); - expect(onChange).lastCalledWith({ foo: ['b'] }); + expect(onChange).toHaveBeenLastCalledWith({ foo: ['b'] }); }); it('should toggle', () => { const onToggle = jest.fn(); const wrapper = shallowRender({ onToggle }); wrapper.find('FacetHeader').prop<Function>('onClick')(); - expect(onToggle).toBeCalled(); + expect(onToggle).toHaveBeenCalled(); }); it('should clear', () => { const onChange = jest.fn(); const wrapper = shallowRender({ onChange, values: ['a'] }); wrapper.find('FacetHeader').prop<Function>('onClear')(); - expect(onChange).toBeCalledWith({ foo: [] }); + expect(onChange).toHaveBeenCalledWith({ foo: [] }); }); it('should search', async () => { @@ -83,8 +83,8 @@ it('should search', async () => { wrapper.find('SearchBox').prop<Function>('onChange')('query'); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(onSearch).lastCalledWith('query'); - expect(loadSearchResultCount).lastCalledWith(['d', 'e']); + expect(onSearch).toHaveBeenLastCalledWith('query'); + expect(loadSearchResultCount).toHaveBeenLastCalledWith(['d', 'e']); // load more results onSearch.mockResolvedValue({ @@ -95,7 +95,7 @@ it('should search', async () => { wrapper.find('ListFooter').prop<Function>('loadMore')(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(onSearch).lastCalledWith('query', 2); + expect(onSearch).toHaveBeenLastCalledWith('query', 2); // clear search onSearch.mockClear(); @@ -103,24 +103,24 @@ it('should search', async () => { wrapper.find('SearchBox').prop<Function>('onChange')(''); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(onSearch).not.toBeCalled(); - expect(loadSearchResultCount).not.toBeCalled(); + expect(onSearch).not.toHaveBeenCalled(); + expect(loadSearchResultCount).not.toHaveBeenCalled(); // search for no results onSearch.mockResolvedValue({ results: [], paging: { pageIndex: 1, pageSize: 2, total: 0 } }); wrapper.find('SearchBox').prop<Function>('onChange')('blabla'); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(onSearch).lastCalledWith('blabla'); - expect(loadSearchResultCount).not.toBeCalled(); + expect(onSearch).toHaveBeenLastCalledWith('blabla'); + expect(loadSearchResultCount).not.toHaveBeenCalled(); // search fails onSearch.mockRejectedValue(undefined); wrapper.find('SearchBox').prop<Function>('onChange')('blabla'); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); // should render previous results - expect(onSearch).lastCalledWith('blabla'); - expect(loadSearchResultCount).not.toBeCalled(); + expect(onSearch).toHaveBeenLastCalledWith('blabla'); + expect(loadSearchResultCount).not.toHaveBeenCalled(); }); it('should limit the number of items', () => { diff --git a/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacetFooter-test.tsx b/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacetFooter-test.tsx index 3a2fd18f845..7bce3ed8441 100644 --- a/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacetFooter-test.tsx +++ b/server/sonar-web/src/main/js/components/facet/__tests__/ListStyleFacetFooter-test.tsx @@ -36,7 +36,7 @@ it('should show more', () => { ); expect(wrapper).toMatchSnapshot(); click(wrapper.find(ButtonLink)); - expect(showMore).toBeCalled(); + expect(showMore).toHaveBeenCalled(); }); it('should show less', () => { @@ -46,7 +46,7 @@ it('should show less', () => { ); expect(wrapper).toMatchSnapshot(); click(wrapper.find(ButtonLink)); - expect(showLess).toBeCalled(); + expect(showLess).toHaveBeenCalled(); }); it('should not render "show less"', () => { diff --git a/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx b/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx index 94948c10831..3f4c0d904a7 100644 --- a/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx +++ b/server/sonar-web/src/main/js/components/hoc/__tests__/whenLoggedIn-test.tsx @@ -40,7 +40,7 @@ it('should render for logged in user', () => { it('should not render for anonymous user', () => { const wrapper = shallowRender(false); expect(getRenderedType(wrapper)).toBeNull(); - expect(handleRequiredAuthentication).toBeCalled(); + expect(handleRequiredAuthentication).toHaveBeenCalled(); }); function getRenderedType(wrapper: ShallowWrapper) { diff --git a/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx b/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx index 4655585f85f..d1b0c500b03 100644 --- a/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx +++ b/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx @@ -65,32 +65,32 @@ it('should correctly bind key events for component navigation', () => { ); keydown({ key: KeyboardKeys.DownArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[2]); - expect(onSelect).not.toBeCalled(); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[2]); + expect(onSelect).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.UpArrow }); keydown({ key: KeyboardKeys.UpArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[0]); - expect(onSelect).not.toBeCalled(); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[0]); + expect(onSelect).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.UpArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[2]); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[2]); keydown({ key: KeyboardKeys.DownArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[0]); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[0]); keydown({ key: KeyboardKeys.RightArrow, metaKey: true }); - expect(onSelect).not.toBeCalled(); + expect(onSelect).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.RightArrow }); - expect(onSelect).toBeCalledWith(COMPONENTS[0]); + expect(onSelect).toHaveBeenCalledWith(COMPONENTS[0]); keydown({ key: KeyboardKeys.Enter }); - expect(onSelect).toBeCalledWith(COMPONENTS[0]); + expect(onSelect).toHaveBeenCalledWith(COMPONENTS[0]); keydown({ key: KeyboardKeys.LeftArrow, metaKey: true }); - expect(onGoToParent).not.toBeCalled(); + expect(onGoToParent).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.LeftArrow }); - expect(onGoToParent).toBeCalled(); + expect(onGoToParent).toHaveBeenCalled(); }); it('should support not cycling through elements, and triggering a callback on reaching the last element', () => { @@ -107,18 +107,18 @@ it('should support not cycling through elements, and triggering a callback on re ); keydown({ key: KeyboardKeys.DownArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[0]); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[0]); keydown({ key: KeyboardKeys.DownArrow }); keydown({ key: KeyboardKeys.DownArrow }); keydown({ key: KeyboardKeys.DownArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[2]); - expect(onEndOfList).toBeCalled(); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[2]); + expect(onEndOfList).toHaveBeenCalled(); keydown({ key: KeyboardKeys.UpArrow }); keydown({ key: KeyboardKeys.UpArrow }); keydown({ key: KeyboardKeys.UpArrow }); keydown({ key: KeyboardKeys.UpArrow }); - expect(onHighlight).toBeCalledWith(COMPONENTS[0]); + expect(onHighlight).toHaveBeenCalledWith(COMPONENTS[0]); }); it('should correctly bind key events for codeview navigation', () => { @@ -136,22 +136,22 @@ it('should correctly bind key events for codeview navigation', () => { }) ); - expect(onHighlight).not.toBeCalled(); + expect(onHighlight).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.DownArrow }); - expect(onHighlight).not.toBeCalled(); + expect(onHighlight).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.UpArrow }); - expect(onHighlight).not.toBeCalled(); + expect(onHighlight).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.RightArrow }); - expect(onSelect).not.toBeCalled(); + expect(onSelect).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.Enter }); - expect(onSelect).not.toBeCalled(); + expect(onSelect).not.toHaveBeenCalled(); keydown({ key: KeyboardKeys.LeftArrow }); - expect(onGoToParent).toBeCalled(); + expect(onGoToParent).toHaveBeenCalled(); }); function applyProps(props: Partial<WithKeyboardNavigationProps> = {}) { diff --git a/server/sonar-web/src/main/js/components/hoc/__tests__/withNotifications-test.tsx b/server/sonar-web/src/main/js/components/hoc/__tests__/withNotifications-test.tsx index 0bd982d2d33..c29439d7f6e 100644 --- a/server/sonar-web/src/main/js/components/hoc/__tests__/withNotifications-test.tsx +++ b/server/sonar-web/src/main/js/components/hoc/__tests__/withNotifications-test.tsx @@ -69,7 +69,7 @@ it('should fetch notifications and render', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); - expect(getNotifications).toBeCalled(); + expect(getNotifications).toHaveBeenCalled(); }); it('should add and remove a notification', () => { diff --git a/server/sonar-web/src/main/js/components/issue/__tests__/actions-test.ts b/server/sonar-web/src/main/js/components/issue/__tests__/actions-test.ts index fb0a525465b..44aa7a71e40 100644 --- a/server/sonar-web/src/main/js/components/issue/__tests__/actions-test.ts +++ b/server/sonar-web/src/main/js/components/issue/__tests__/actions-test.ts @@ -45,38 +45,38 @@ describe('updateIssue', () => { it('makes successful optimistic updates', async () => { updateIssue(onChange, successPromise(), oldIssue, newIssue); - expect(onChange).toBeCalledWith(newIssue); + expect(onChange).toHaveBeenCalledWith(newIssue); await new Promise(setImmediate); - expect(onChange).toBeCalledTimes(1); + expect(onChange).toHaveBeenCalledTimes(1); }); it('makes successful non-optimistic updates', async () => { updateIssue(onChange, successPromise()); - expect(onChange).not.toBeCalled(); + expect(onChange).not.toHaveBeenCalled(); await new Promise(setImmediate); - expect(onChange).toBeCalledWith(parsedIssue); - expect(onChange).toBeCalledTimes(1); + expect(onChange).toHaveBeenCalledWith(parsedIssue); + expect(onChange).toHaveBeenCalledTimes(1); }); it('makes unsuccessful optimistic updates', async () => { updateIssue(onChange, errorPromise(), oldIssue, newIssue); - expect(onChange).toBeCalledWith(newIssue); + expect(onChange).toHaveBeenCalledWith(newIssue); await new Promise(setImmediate); - expect(onChange).toBeCalledWith(oldIssue); - expect(onChange).toBeCalledTimes(2); + expect(onChange).toHaveBeenCalledWith(oldIssue); + expect(onChange).toHaveBeenCalledTimes(2); }); it('makes unsuccessful non-optimistic updates', async () => { updateIssue(onChange, errorPromise()); - expect(onChange).not.toBeCalled(); + expect(onChange).not.toHaveBeenCalled(); await new Promise(setImmediate); - expect(parseIssueFromResponse).not.toBeCalled(); - expect(throwGlobalError).toBeCalled(); + expect(parseIssueFromResponse).not.toHaveBeenCalled(); + expect(throwGlobalError).toHaveBeenCalled(); }); }); diff --git a/server/sonar-web/src/main/js/components/issue/__tests__/issue-test.tsx b/server/sonar-web/src/main/js/components/issue/__tests__/issue-test.tsx index 91a7b49da56..b99f62cb3e7 100644 --- a/server/sonar-web/src/main/js/components/issue/__tests__/issue-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/__tests__/issue-test.tsx @@ -51,33 +51,33 @@ it('should call the proper function with the proper props when pressing shortcut shallowRender({ onPopupToggle, issue, onCheck }); keydown({ key: KeyboardKeys.KeyF, metaKey: true }); - expect(onPopupToggle).not.toBeCalledWith(issue.key, 'transition', undefined); + expect(onPopupToggle).not.toHaveBeenCalledWith(issue.key, 'transition', undefined); keydown({ key: KeyboardKeys.KeyF }); - expect(onPopupToggle).toBeCalledWith(issue.key, 'transition', undefined); + expect(onPopupToggle).toHaveBeenCalledWith(issue.key, 'transition', undefined); keydown({ key: KeyboardKeys.KeyA }); - expect(onPopupToggle).toBeCalledWith(issue.key, 'assign', undefined); + expect(onPopupToggle).toHaveBeenCalledWith(issue.key, 'assign', undefined); keydown({ key: KeyboardKeys.Escape }); keydown({ key: KeyboardKeys.KeyM }); - expect(onPopupToggle).toBeCalledWith(issue.key, 'assign', false); + expect(onPopupToggle).toHaveBeenCalledWith(issue.key, 'assign', false); keydown({ key: KeyboardKeys.KeyI }); - expect(onPopupToggle).toBeCalledWith(issue.key, 'set-severity', undefined); + expect(onPopupToggle).toHaveBeenCalledWith(issue.key, 'set-severity', undefined); keydown({ key: KeyboardKeys.KeyC, metaKey: true }); - expect(onPopupToggle).not.toBeCalledWith(issue.key, 'comment', undefined); + expect(onPopupToggle).not.toHaveBeenCalledWith(issue.key, 'comment', undefined); keydown({ key: KeyboardKeys.KeyC }); - expect(onPopupToggle).toBeCalledWith(issue.key, 'comment', undefined); + expect(onPopupToggle).toHaveBeenCalledWith(issue.key, 'comment', undefined); keydown({ key: KeyboardKeys.Escape }); keydown({ key: KeyboardKeys.KeyT }); - expect(onPopupToggle).toBeCalledWith(issue.key, 'edit-tags', undefined); + expect(onPopupToggle).toHaveBeenCalledWith(issue.key, 'edit-tags', undefined); keydown({ key: KeyboardKeys.Space }); - expect(onCheck).toBeCalledWith(issue.key); + expect(onCheck).toHaveBeenCalledWith(issue.key); }); function shallowRender(props: Partial<Issue['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueActionsBar-test.tsx b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueActionsBar-test.tsx index 00655ccdaa2..d893ed2c69a 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueActionsBar-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueActionsBar-test.tsx @@ -105,7 +105,7 @@ describe('callback', () => { instance.setIssueProperty('author', 'popup', apiCallMock, 'Jay'); expect(togglePopupMock).toHaveBeenCalledTimes(1); - expect(apiCallMock).toBeCalledTimes(1); + expect(apiCallMock).toHaveBeenCalledTimes(1); }); it('toggleComment should call togglePopup and update state', () => { diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx index 0147d912475..2ca70c90b5a 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx @@ -54,7 +54,7 @@ it('should open why is this an issue workspace', () => { const wrapper = shallowRender(); wrapper.find(ButtonLink).simulate('click'); - expect(openRule).toBeCalled(); + expect(openRule).toHaveBeenCalled(); }); function shallowRender(props: Partial<IssueMessageProps> = {}) { diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.tsx b/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.tsx index 96b6f0ab157..f4dc2d36a8e 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/ChangelogPopup-test.tsx @@ -45,7 +45,7 @@ beforeEach(() => { it('should render the changelog popup correctly', async () => { const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(getIssueChangelog).toBeCalledWith('issuekey'); + expect(getIssueChangelog).toHaveBeenCalledWith('issuekey'); expect(wrapper).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/CommentPopup-test.tsx b/server/sonar-web/src/main/js/components/issue/popups/__tests__/CommentPopup-test.tsx index dd3e8007aa7..d03edef1638 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/CommentPopup-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/CommentPopup-test.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { screen } from '@testing-library/dom'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import * as React from 'react'; import { renderComponent } from '../../../../helpers/testReactTestingUtils'; diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetAssigneePopup-test.tsx b/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetAssigneePopup-test.tsx index 84bd9d76531..d37ffd973b1 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetAssigneePopup-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/SetAssigneePopup-test.tsx @@ -41,7 +41,7 @@ it('should allow to search for a user on SQ', async () => { const wrapper = shallowRender(); wrapper.find('SearchBox').prop<Function>('onChange')('o'); await waitAndUpdate(wrapper); - expect(searchUsers).toBeCalledWith({ q: 'o', ps: 10 }); + expect(searchUsers).toHaveBeenCalledWith({ q: 'o', ps: 10 }); expect(wrapper.state('users')).toEqual([mockUser()]); }); diff --git a/server/sonar-web/src/main/js/components/issue/popups/__tests__/SimilarIssuesPopup-test.tsx b/server/sonar-web/src/main/js/components/issue/popups/__tests__/SimilarIssuesPopup-test.tsx index 4a6d09a474d..66bbeb8e55e 100644 --- a/server/sonar-web/src/main/js/components/issue/popups/__tests__/SimilarIssuesPopup-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/popups/__tests__/SimilarIssuesPopup-test.tsx @@ -45,7 +45,7 @@ it('should filter properly', () => { const onFilter = jest.fn(); const wrapper = shallowRender({ issue, onFilter }); wrapper.find('SelectList').prop<Function>('onSelect')('assignee'); - expect(onFilter).toBeCalledWith('assignee', issue); + expect(onFilter).toHaveBeenCalledWith('assignee', issue); }); function shallowRender(props: Partial<SimilarIssuesPopup['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/tutorials/__tests__/TutorialSelection-test.tsx b/server/sonar-web/src/main/js/components/tutorials/__tests__/TutorialSelection-test.tsx index 7dd92e43fd8..80b92e0166b 100644 --- a/server/sonar-web/src/main/js/components/tutorials/__tests__/TutorialSelection-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/__tests__/TutorialSelection-test.tsx @@ -97,8 +97,8 @@ it('should fetch the correct baseUrl', async () => { let wrapper = shallowRender(); - expect(getValue).toBeCalled(); - expect(getHostUrl).toBeCalled(); + expect(getValue).toHaveBeenCalled(); + expect(getHostUrl).toHaveBeenCalled(); // No baseURL, fallback to the URL in the browser. await waitAndUpdate(wrapper); @@ -133,18 +133,18 @@ it("should correctly determine the user's permission", async () => { }); await waitAndUpdate(wrapper); expect(wrapper.state().currentUserCanScanProject).toBe(true); - expect(getScannableProjects).not.toBeCalled(); + expect(getScannableProjects).not.toHaveBeenCalled(); // Project scan permission. wrapper = shallowRender({ component }); await waitAndUpdate(wrapper); - expect(getScannableProjects).toBeCalled(); + expect(getScannableProjects).toHaveBeenCalled(); expect(wrapper.state().currentUserCanScanProject).toBe(true); // No scan permission. wrapper = shallowRender({ component }); await waitAndUpdate(wrapper); - expect(getScannableProjects).toBeCalledTimes(2); + expect(getScannableProjects).toHaveBeenCalledTimes(2); expect(wrapper.state().currentUserCanScanProject).toBe(false); }); diff --git a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/EditTokenModal-test.tsx b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/EditTokenModal-test.tsx index aef45fe0738..7681d5487c8 100644 --- a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/EditTokenModal-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/EditTokenModal-test.tsx @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { screen, waitFor } from '@testing-library/dom'; +import { screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { UserEvent } from '@testing-library/user-event/dist/types/setup'; import * as React from 'react'; @@ -58,9 +58,7 @@ it('should behave correctly', async () => { expect(screen.getByText('onboarding.token.text.PROJECT_ANALYSIS_TOKEN')).toBeInTheDocument(); // Renders form correctly. - await waitFor(() => - expect(screen.getByLabelText('onboarding.token.name.label')).toBeInTheDocument() - ); + await screen.findByLabelText('onboarding.token.name.label'); // Should be getByLabelText(), but this is due to a limitation with React Select. expect(screen.getByText('users.tokens.expires_in')).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'continue' })).toBeInTheDocument(); @@ -118,9 +116,7 @@ it('should allow setting a preferred token type', async () => { }); const user = userEvent.setup(); - await waitFor(() => - expect(screen.getByLabelText('onboarding.token.name.label')).toBeInTheDocument() - ); + await screen.findByLabelText('onboarding.token.name.label'); await clickButton(user, 'onboarding.token.generate'); const lastToken = tokenMock.getLastToken(); @@ -136,9 +132,7 @@ it('should fallback to project tokens if the user cannot generate global tokens' }); const user = userEvent.setup(); - await waitFor(() => - expect(screen.getByLabelText('onboarding.token.name.label')).toBeInTheDocument() - ); + await screen.findByLabelText('onboarding.token.name.label'); await clickButton(user, 'onboarding.token.generate'); const lastToken = tokenMock.getLastToken(); diff --git a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/Step-test.tsx b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/Step-test.tsx index c0f419a5205..90f7eff0951 100644 --- a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/Step-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/Step-test.tsx @@ -53,5 +53,5 @@ it('re-opens', () => { /> ); click(wrapper); - expect(onOpen).toBeCalled(); + expect(onOpen).toHaveBeenCalled(); }); diff --git a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/YamlFileStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/YamlFileStep-test.tsx index fe381429bda..d38f3b83222 100644 --- a/server/sonar-web/src/main/js/components/tutorials/components/__tests__/YamlFileStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/components/__tests__/YamlFileStep-test.tsx @@ -33,7 +33,7 @@ it('should render child correctly', () => { const wrapper = shallowRender({ children }); expect(wrapper).toMatchSnapshot('C unavailable'); wrapper.find(RenderOptions).simulate('check', BuildTools.DotNet); - expect(children).toBeCalledWith(BuildTools.DotNet); + expect(children).toHaveBeenCalledWith(BuildTools.DotNet); }); function shallowRender(props: Partial<YamlFileStepProps> = {}) { diff --git a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx index c6ca825d5cd..c52d8491ace 100644 --- a/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/gitlabci/__tests__/ProjectKeyStep-test.tsx @@ -51,7 +51,7 @@ it('should correctly callback with selected build tool', () => { const wrapper = shallowRender({ setBuildTool }); selectBuildTool(wrapper, BuildTools.Maven); - expect(setBuildTool).toBeCalledWith(BuildTools.Maven); + expect(setBuildTool).toHaveBeenCalledWith(BuildTools.Maven); }); function selectBuildTool(wrapper: ShallowWrapper<ProjectKeyStepProps>, tool: BuildTools) { diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStep-test.tsx index a43b813cf66..100bba0acb5 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/WebhookStep-test.tsx @@ -36,7 +36,7 @@ it.each([ [AlmKeys.BitbucketServer, mockProjectBitbucketBindingResponse()], [AlmKeys.GitHub, mockProjectGithubBindingResponse()], [AlmKeys.GitLab, mockProjectAlmBindingResponse({ alm: AlmKeys.GitLab })] -])('it should render correctly for %s', (alm, projectBinding) => { +])('should render correctly for %s', (alm, projectBinding) => { const wrapper = shallowRender({ alm, projectBinding }); expect(wrapper).toMatchSnapshot('wrapper'); expect(renderStepContent(wrapper)).toMatchSnapshot('content'); diff --git a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/WebhookStep-test.tsx.snap b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/WebhookStep-test.tsx.snap index 6ab72065f9b..4e2ce5adcff 100644 --- a/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/WebhookStep-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/tutorials/jenkins/__tests__/__snapshots__/WebhookStep-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`it should render correctly for azure: content 1`] = ` +exports[`should render correctly for azure: content 1`] = ` <div className="boxed-group-inner" > @@ -36,7 +36,7 @@ exports[`it should render correctly for azure: content 1`] = ` </div> `; -exports[`it should render correctly for azure: wrapper 1`] = ` +exports[`should render correctly for azure: wrapper 1`] = ` <Step finished={false} onOpen={[MockFunction]} @@ -47,7 +47,7 @@ exports[`it should render correctly for azure: wrapper 1`] = ` /> `; -exports[`it should render correctly for bitbucket: content 1`] = ` +exports[`should render correctly for bitbucket: content 1`] = ` <div className="boxed-group-inner" > @@ -103,7 +103,7 @@ exports[`it should render correctly for bitbucket: content 1`] = ` </div> `; -exports[`it should render correctly for bitbucket: wrapper 1`] = ` +exports[`should render correctly for bitbucket: wrapper 1`] = ` <Step finished={false} onOpen={[MockFunction]} @@ -114,7 +114,7 @@ exports[`it should render correctly for bitbucket: wrapper 1`] = ` /> `; -exports[`it should render correctly for bitbucketcloud: content 1`] = ` +exports[`should render correctly for bitbucketcloud: content 1`] = ` <div className="boxed-group-inner" > @@ -169,7 +169,7 @@ exports[`it should render correctly for bitbucketcloud: content 1`] = ` </div> `; -exports[`it should render correctly for bitbucketcloud: wrapper 1`] = ` +exports[`should render correctly for bitbucketcloud: wrapper 1`] = ` <Step finished={false} onOpen={[MockFunction]} @@ -180,7 +180,7 @@ exports[`it should render correctly for bitbucketcloud: wrapper 1`] = ` /> `; -exports[`it should render correctly for github: content 1`] = ` +exports[`should render correctly for github: content 1`] = ` <div className="boxed-group-inner" > @@ -234,7 +234,7 @@ exports[`it should render correctly for github: content 1`] = ` </div> `; -exports[`it should render correctly for github: wrapper 1`] = ` +exports[`should render correctly for github: wrapper 1`] = ` <Step finished={false} onOpen={[MockFunction]} @@ -245,7 +245,7 @@ exports[`it should render correctly for github: wrapper 1`] = ` /> `; -exports[`it should render correctly for gitlab: content 1`] = ` +exports[`should render correctly for gitlab: content 1`] = ` <div className="boxed-group-inner" > @@ -285,7 +285,7 @@ exports[`it should render correctly for gitlab: content 1`] = ` </div> `; -exports[`it should render correctly for gitlab: wrapper 1`] = ` +exports[`should render correctly for gitlab: wrapper 1`] = ` <Step finished={false} onOpen={[MockFunction]} diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx index 36dc3ce673d..0749c9a33b8 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/BuildToolForm-test.tsx @@ -38,11 +38,11 @@ it('correctly calls the onDone prop', () => { const wrapper = shallowRender({ onDone }); wrapper.instance().handleBuildToolChange(BuildTools.Gradle); - expect(onDone).toBeCalledWith(expect.objectContaining({ buildTool: BuildTools.Gradle })); + expect(onDone).toHaveBeenCalledWith(expect.objectContaining({ buildTool: BuildTools.Gradle })); wrapper.setState({ config: { buildTool: BuildTools.Other } }); wrapper.instance().handleOSChange(OSs.Windows); - expect(onDone).toBeCalledWith( + expect(onDone).toHaveBeenCalledWith( expect.objectContaining({ os: OSs.Windows, buildTool: BuildTools.Other }) ); }); diff --git a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx index 77a80a10529..d081f981aff 100644 --- a/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx +++ b/server/sonar-web/src/main/js/components/tutorials/other/__tests__/TokenStep-test.tsx @@ -86,7 +86,7 @@ it('continues', async () => { await new Promise(setImmediate); wrapper.setState({ token: 'abcd1234', tokenName: 'my token' }); click(wrapper.dive().find('[className="js-continue"]')); - expect(onContinue).toBeCalledWith('abcd1234'); + expect(onContinue).toHaveBeenCalledWith('abcd1234'); }); it('uses existing token', async () => { @@ -95,7 +95,7 @@ it('uses existing token', async () => { await new Promise(setImmediate); wrapper.setState({ existingToken: 'abcd1234', selection: 'use-existing' }); click(wrapper.dive().find('[className="js-continue"]')); - expect(onContinue).toBeCalledWith('abcd1234'); + expect(onContinue).toHaveBeenCalledWith('abcd1234'); }); function shallowRender(props: Partial<TokenStep['props']> = {}) { diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/DismissableAlert-test.tsx b/server/sonar-web/src/main/js/components/ui/__tests__/DismissableAlert-test.tsx index 7e94989f03b..93148c340fb 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/DismissableAlert-test.tsx +++ b/server/sonar-web/src/main/js/components/ui/__tests__/DismissableAlert-test.tsx @@ -59,7 +59,7 @@ it('should not render if it was dismissed', () => { it('should correctly allow dismissing', () => { const wrapper = shallowRender(); click(wrapper.find(ButtonIcon)); - expect(save).toBeCalledWith(DISMISSED_ALERT_STORAGE_KEY, 'true', 'foo'); + expect(save).toHaveBeenCalledWith(DISMISSED_ALERT_STORAGE_KEY, 'true', 'foo'); }); function shallowRender(props: Partial<DismissableAlertProps> = {}) { diff --git a/server/sonar-web/src/main/js/components/ui/__tests__/NewsBox-test.tsx b/server/sonar-web/src/main/js/components/ui/__tests__/NewsBox-test.tsx index 1551e76111e..2ada28e5aa5 100644 --- a/server/sonar-web/src/main/js/components/ui/__tests__/NewsBox-test.tsx +++ b/server/sonar-web/src/main/js/components/ui/__tests__/NewsBox-test.tsx @@ -31,7 +31,7 @@ it('should call onClose', () => { const wrapper = shallowRender({ onClose }); click(wrapper.find('ClearButton')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); function shallowRender(props: Partial<Props> = {}) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceComponentViewer-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceComponentViewer-test.tsx index ec91f648898..b99ef855691 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceComponentViewer-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceComponentViewer-test.tsx @@ -41,7 +41,7 @@ it('should close', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); wrapper.find('WorkspaceHeader').prop<Function>('onClose')(); - expect(onClose).toBeCalledWith('foo'); + expect(onClose).toHaveBeenCalledWith('foo'); }); it('should call back after load', () => { @@ -52,7 +52,7 @@ it('should call back after load', () => { path: 'src/foo.js', q: 'FIL' }); - expect(onLoad).toBeCalledWith({ key: 'foo', name: 'src/foo.js', qualifier: 'FIL' }); + expect(onLoad).toHaveBeenCalledWith({ key: 'foo', name: 'src/foo.js', qualifier: 'FIL' }); }); it('should refresh branch status if issues are updated', async () => { @@ -67,9 +67,9 @@ it('should refresh branch status if issues are updated', async () => { await waitAndUpdate(wrapper); instance.handleIssueChange(mockIssue()); - expect(getParents).toBeCalledWith(component.key); + expect(getParents).toHaveBeenCalledWith(component.key); await waitAndUpdate(wrapper); - expect(fetchBranchStatus).toBeCalledWith(branchLike, 'bar'); + expect(fetchBranchStatus).toHaveBeenCalledWith(branchLike, 'bar'); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceHeader-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceHeader-test.tsx index 378f629e9e3..bee32547a64 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceHeader-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceHeader-test.tsx @@ -29,7 +29,7 @@ it('should resize', () => { const onResize = jest.fn(); const wrapper = shallowRender({ onResize }); wrapper.find('DraggableCore').prop<Function>('onDrag')({}, { deltaY: 15 }); - expect(onResize).toBeCalledWith(15); + expect(onResize).toHaveBeenCalledWith(15); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavComponent-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavComponent-test.tsx index 56491bb145f..b8c0a1127d0 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavComponent-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavComponent-test.tsx @@ -29,14 +29,14 @@ it('should close', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); wrapper.find('WorkspaceNavItem').prop<Function>('onClose')(); - expect(onClose).toBeCalledWith('foo'); + expect(onClose).toHaveBeenCalledWith('foo'); }); it('should open', () => { const onOpen = jest.fn(); const wrapper = shallowRender({ onOpen }); wrapper.find('WorkspaceNavItem').prop<Function>('onOpen')(); - expect(onOpen).toBeCalledWith('foo'); + expect(onOpen).toHaveBeenCalledWith('foo'); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavItem-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavItem-test.tsx index 20d256e2511..1ad7e749cfd 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavItem-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavItem-test.tsx @@ -30,14 +30,14 @@ it('should close', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); click(wrapper.find('ClearButton')); - expect(onClose).toBeCalled(); + expect(onClose).toHaveBeenCalled(); }); it('should open', () => { const onOpen = jest.fn(); const wrapper = shallowRender({ onOpen }); click(wrapper.find('.workspace-nav-item-link')); - expect(onOpen).toBeCalled(); + expect(onOpen).toHaveBeenCalled(); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavRule-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavRule-test.tsx index f831450d738..e8d0e48a32c 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavRule-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceNavRule-test.tsx @@ -29,14 +29,14 @@ it('should close', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); wrapper.find('WorkspaceNavItem').prop<Function>('onClose')(); - expect(onClose).toBeCalledWith('foo'); + expect(onClose).toHaveBeenCalledWith('foo'); }); it('should open', () => { const onOpen = jest.fn(); const wrapper = shallowRender({ onOpen }); wrapper.find('WorkspaceNavItem').prop<Function>('onOpen')(); - expect(onOpen).toBeCalledWith('foo'); + expect(onOpen).toHaveBeenCalledWith('foo'); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx index d2eb4416644..ea1b1f01ab2 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleDetails-test.tsx @@ -41,7 +41,7 @@ it('should call back on load', async () => { const onLoad = jest.fn(); const wrapper = shallowRender({ onLoad }); await waitAndUpdate(wrapper); - expect(onLoad).toBeCalledWith({ name: 'Foo' }); + expect(onLoad).toHaveBeenCalledWith({ name: 'Foo' }); }); function shallowRender(props?: Partial<WorkspaceRuleDetails['props']>) { diff --git a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx index b922f37d9e5..b800108cd59 100644 --- a/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx +++ b/server/sonar-web/src/main/js/components/workspace/__tests__/WorkspaceRuleViewer-test.tsx @@ -61,7 +61,7 @@ it('should close', () => { const onClose = jest.fn(); const wrapper = shallowRender({ onClose }); wrapper.find('WorkspaceHeader').prop<Function>('onClose')(); - expect(onClose).toBeCalledWith('foo'); + expect(onClose).toHaveBeenCalledWith('foo'); }); it('should call back after load', () => { @@ -69,7 +69,7 @@ it('should call back after load', () => { const wrapper = shallowRender({ onLoad }); const details = wrapper.findWhere(w => w.name().includes('WorkspaceRuleDetails')); details.prop<Function>('onLoad')({ name: 'Foo' }); - expect(onLoad).toBeCalledWith({ key: 'foo', name: 'Foo' }); + expect(onLoad).toHaveBeenCalledWith({ key: 'foo', name: 'Foo' }); }); function shallowRender(props?: Partial<Props>) { diff --git a/server/sonar-web/src/main/js/helpers/__tests__/code-difference-test.tsx b/server/sonar-web/src/main/js/helpers/__tests__/code-difference-test.tsx index 9a8ba09ca32..098a88cc325 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/code-difference-test.tsx +++ b/server/sonar-web/src/main/js/helpers/__tests__/code-difference-test.tsx @@ -24,6 +24,7 @@ import applyCodeDifferences from '../code-difference'; it('should apply diff view correctly', () => { const { container } = renderDom(properCodeSnippet); applyCodeDifferences(container); + // eslint-disable-next-line testing-library/no-container, testing-library/no-node-access expect(container.getElementsByClassName('code-difference-scrollable')).toMatchSnapshot( 'differenciatedCode' ); @@ -32,12 +33,14 @@ it('should apply diff view correctly', () => { it('should not apply diff view if 3 examples are present', () => { const { container } = renderDom(codeSnippetWith3Examples); applyCodeDifferences(container); + // eslint-disable-next-line testing-library/no-container, testing-library/no-node-access expect(container.getElementsByClassName('code-difference-scrollable').length).toEqual(0); }); it('should not apply diff view if compliant code is absent', () => { const { container } = renderDom(codeSnippetWithoutCompliantCode); applyCodeDifferences(container); + // eslint-disable-next-line testing-library/no-container, testing-library/no-node-access expect(container.getElementsByClassName('code-difference-scrollable').length).toEqual(0); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts index 8615870ad6d..b053ff7746f 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/error-test.ts @@ -48,7 +48,7 @@ it('should display the error message', async () => { }) .catch(() => {}); - expect(addGlobalErrorMessage).toBeCalledWith('error 1'); + expect(addGlobalErrorMessage).toHaveBeenCalledWith('error 1'); }); it('should display the default error messsage', async () => { @@ -62,19 +62,17 @@ it('should display the default error messsage', async () => { }) .catch(() => {}); - expect(addGlobalErrorMessage).toBeCalledWith('default_error_message'); + expect(addGlobalErrorMessage).toHaveBeenCalledWith('default_error_message'); }); -it('should handle weird response types', () => { +it('should handle weird response types', async () => { const response = { weird: 'response type' }; - return throwGlobalError(response) - .then(() => { + await expect( + throwGlobalError(response).then(() => { throw new Error('Should throw'); }) - .catch(error => { - expect(error).toBe(response); - }); + ).rejects.toBe(response); }); it('should unwrap response if necessary', async () => { diff --git a/server/sonar-web/src/main/js/helpers/__tests__/extensions-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/extensions-test.ts index 06f2a0a204e..4198e8e1241 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/extensions-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/extensions-test.ts @@ -73,7 +73,7 @@ describe('getExtensionStart', () => { const result = getExtensionStart('bar'); await new Promise(setImmediate); - expect(exposeLibraries).toBeCalled(); + expect(exposeLibraries).toHaveBeenCalled(); (window as any).registerExtension('bar', start, true); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/globalMessages-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/globalMessages-test.ts index c6842d9b7a8..afd4a547a5a 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/globalMessages-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/globalMessages-test.ts @@ -30,7 +30,7 @@ it('should work as expected', () => { addGlobalErrorMessage('test'); - expect(listener1).toBeCalledWith( + expect(listener1).toHaveBeenCalledWith( expect.objectContaining({ text: 'test', level: MessageLevel.Error }) ); @@ -40,10 +40,10 @@ it('should work as expected', () => { addGlobalSuccessMessage('test'); - expect(listener1).toBeCalledWith( + expect(listener1).toHaveBeenCalledWith( expect.objectContaining({ text: 'test', level: MessageLevel.Success }) ); - expect(listener2).toBeCalledWith( + expect(listener2).toHaveBeenCalledWith( expect.objectContaining({ text: 'test', level: MessageLevel.Success }) ); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/handleRequiredAuthentication-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/handleRequiredAuthentication-test.ts index 48ce7ea3071..eb637128ec4 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/handleRequiredAuthentication-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/handleRequiredAuthentication-test.ts @@ -46,5 +46,5 @@ afterAll(() => { it('should not render for anonymous user', () => { handleRequiredAuthentication(); - expect(replace).toBeCalledWith('/sessions/new?return_to=%2Fpath%3Fid%3D12%23tag'); + expect(replace).toHaveBeenCalledWith('/sessions/new?return_to=%2Fpath%3Fid%3D12%23tag'); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts index b4201f41bb6..5c74c9f20ab 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/markdown-test.ts @@ -172,7 +172,7 @@ it('should not break when conditional tags are misused', () => { Break <!-- static -->Static <!-- /sonarcloud -->stuff`; expect(filterContent(content)).toMatchSnapshot(); - expect(console.error).toBeCalledTimes(2); + expect(console.error).toHaveBeenCalledTimes(2); console.error = originalConsoleError; }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts index 3a301c9b9b6..840d92d4bde 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts @@ -273,12 +273,15 @@ describe('getMinDecimalsCountToBeDistinctFromThreshold', () => { expect(getMinDecimalsCountToBeDistinctFromThreshold(2.5005, 2.5)).toBe(4); expect(getMinDecimalsCountToBeDistinctFromThreshold(85.01, 85)).toBe(2); expect(getMinDecimalsCountToBeDistinctFromThreshold(84.95, 85)).toBe(2); + // eslint-disable-next-line no-loss-of-precision expect(getMinDecimalsCountToBeDistinctFromThreshold(84.999999999999554, 85)).toBe( '9999999999995'.length ); + // eslint-disable-next-line no-loss-of-precision expect(getMinDecimalsCountToBeDistinctFromThreshold(85.0000000000000954, 85)).toBe( '00000000000009'.length ); + // eslint-disable-next-line no-loss-of-precision expect(getMinDecimalsCountToBeDistinctFromThreshold(85.00000000000000009, 85)).toBe(1); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/pages-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/pages-test.ts index c5f9d90fb16..e4086984f96 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/pages-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/pages-test.ts @@ -34,7 +34,7 @@ describe('class adders', () => { ])('%s should add the class', (fct, cls) => { const toggle = jest.spyOn(document.body.classList, 'toggle'); fct(); - expect(toggle).toBeCalledWith(cls, true); + expect(toggle).toHaveBeenCalledWith(cls, true); }); }); @@ -46,6 +46,6 @@ describe('class removers', () => { ])('%s should add the class', (fct, cls) => { const toggle = jest.spyOn(document.body.classList, 'toggle'); fct(); - expect(toggle).toBeCalledWith(cls, false); + expect(toggle).toHaveBeenCalledWith(cls, false); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts index a6a0e39ecff..05ddee8a84c 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/periods-test.ts @@ -36,21 +36,21 @@ describe('getPeriodLabel', () => { expect( getPeriodLabel(mockPeriod({ mode: 'date', parameter: '2019-02-21T01:11:21+0100' }), formatter) ).toBe('overview.period.date.2019-02-21T01:11:21+0100'); - expect(formatter).toBeCalledTimes(1); + expect(formatter).toHaveBeenCalledTimes(1); }); it('should handle days', () => { expect(getPeriodLabel(mockPeriod({ mode: 'days', modeParam: '12' }), formatter)).toBe( 'overview.period.days.12' ); - expect(formatter).not.toBeCalled(); + expect(formatter).not.toHaveBeenCalled(); }); it('should handle previous analysis', () => { expect( getPeriodLabel(mockPeriod({ mode: 'previous_analysis', parameter: 'param' }), formatter) ).toBe('overview.period.previous_analysis.param'); - expect(formatter).not.toBeCalled(); + expect(formatter).not.toHaveBeenCalled(); }); it('should handle previous version', () => { @@ -60,7 +60,7 @@ describe('getPeriodLabel', () => { expect( getPeriodLabel(mockPeriod({ mode: 'previous_version', parameter: '7.9' }), formatter) ).toBe('overview.period.previous_version.7.9'); - expect(formatter).not.toBeCalled(); + expect(formatter).not.toHaveBeenCalled(); }); it('should handle version', () => { @@ -70,7 +70,7 @@ describe('getPeriodLabel', () => { expect( getPeriodLabel(mockPeriod({ mode: 'previous_version', parameter: '7.9' }), formatter) ).toBe('overview.period.previous_version.7.9'); - expect(formatter).not.toBeCalled(); + expect(formatter).not.toHaveBeenCalled(); }); it('should handle manual baseline', () => { @@ -80,7 +80,7 @@ describe('getPeriodLabel', () => { expect(getPeriodLabel(mockPeriod({ mode: 'manual_baseline' }), formatter)).toBe( 'overview.period.manual_baseline.2019-04-23T02:12:32+0100' ); - expect(formatter).toBeCalledTimes(1); + expect(formatter).toHaveBeenCalledTimes(1); }); it('should handle SPECIFIC_ANALYSIS', () => { @@ -90,7 +90,7 @@ describe('getPeriodLabel', () => { expect(getPeriodLabel(mockPeriod({ mode: 'SPECIFIC_ANALYSIS' }), formatter)).toBe( 'overview.period.specific_analysis.2019-04-23T02:12:32+0100' ); - expect(formatter).toBeCalledTimes(2); + expect(formatter).toHaveBeenCalledTimes(2); }); it('should handle PREVIOUS_VERSION', () => { @@ -100,6 +100,6 @@ describe('getPeriodLabel', () => { expect(getPeriodLabel(mockPeriod({ mode: 'PREVIOUS_VERSION' }), formatter)).toBe( 'overview.period.previous_version.2019-04-23T02:12:32+0100' ); - expect(formatter).toBeCalledTimes(1); + expect(formatter).toHaveBeenCalledTimes(1); }); }); diff --git a/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts index 7d319a58b81..99be07950fa 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/request-test.ts @@ -53,13 +53,13 @@ describe('getJSON', () => { getJSON(url); await new Promise(setImmediate); - expect(window.fetch).toBeCalledWith(url, expect.objectContaining({ method: 'GET' })); - expect(response.json).toBeCalled(); + expect(window.fetch).toHaveBeenCalledWith(url, expect.objectContaining({ method: 'GET' })); + expect(response.json).toHaveBeenCalled(); }); it('should get json with parameters', () => { getJSON(url, { data: 'test' }); - expect(window.fetch).toBeCalledWith( + expect(window.fetch).toHaveBeenCalledWith( url + '?data=test', expect.objectContaining({ method: 'GET' }) ); @@ -73,13 +73,13 @@ describe('getText', () => { getText(url); await new Promise(setImmediate); - expect(window.fetch).toBeCalledWith(url, expect.objectContaining({ method: 'GET' })); - expect(response.text).toBeCalled(); + expect(window.fetch).toHaveBeenCalledWith(url, expect.objectContaining({ method: 'GET' })); + expect(response.text).toHaveBeenCalled(); }); it('should get text with parameters', () => { getText(url, { data: 'test' }); - expect(window.fetch).toBeCalledWith( + expect(window.fetch).toHaveBeenCalledWith( url + '?data=test', expect.objectContaining({ method: 'GET' }) ); @@ -115,7 +115,7 @@ describe('parseJSON', () => { const body = { test: 2 }; const response = mockResponse({}, HttpStatus.Ok, body); const jsonResponse = parseJSON(response); - expect(response.json).toBeCalled(); + expect(response.json).toHaveBeenCalled(); return expect(jsonResponse).resolves.toEqual(body); }); }); @@ -125,7 +125,7 @@ describe('parseText', () => { const body = 'test'; const response = mockResponse({}, HttpStatus.Ok, body); const textResponse = parseText(response); - expect(response.text).toBeCalled(); + expect(response.text).toHaveBeenCalled(); return expect(textResponse).resolves.toBe(body); }); }); @@ -137,13 +137,13 @@ describe('postJSON', () => { postJSON(url); await new Promise(setImmediate); - expect(window.fetch).toBeCalledWith(url, expect.objectContaining({ method: 'POST' })); - expect(response.json).toBeCalled(); + expect(window.fetch).toHaveBeenCalledWith(url, expect.objectContaining({ method: 'POST' })); + expect(response.json).toHaveBeenCalled(); }); it('should post with a body and get json', () => { postJSON(url, { data: 'test' }); - expect(window.fetch).toBeCalledWith( + expect(window.fetch).toHaveBeenCalledWith( url, expect.objectContaining({ body: 'data=test', method: 'POST' }) ); @@ -157,13 +157,13 @@ describe('postJSONBody', () => { postJSONBody(url); await new Promise(setImmediate); - expect(window.fetch).toBeCalledWith(url, expect.objectContaining({ method: 'POST' })); - expect(response.json).toBeCalled(); + expect(window.fetch).toHaveBeenCalledWith(url, expect.objectContaining({ method: 'POST' })); + expect(response.json).toHaveBeenCalled(); }); it('should post with a body and get json', () => { postJSONBody(url, { nested: { data: 'test', withArray: [1, 2] } }); - expect(window.fetch).toBeCalledWith( + expect(window.fetch).toHaveBeenCalledWith( url, expect.objectContaining({ headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, @@ -181,12 +181,12 @@ describe('post', () => { post(url, { data: 'test' }); await new Promise(setImmediate); - expect(window.fetch).toBeCalledWith( + expect(window.fetch).toHaveBeenCalledWith( url, expect.objectContaining({ body: 'data=test', method: 'POST' }) ); - expect(response.json).not.toBeCalled(); - expect(response.text).not.toBeCalled(); + expect(response.json).not.toHaveBeenCalled(); + expect(response.text).not.toHaveBeenCalled(); }); it('should handle array values', async () => { @@ -195,7 +195,7 @@ describe('post', () => { post(url, { dataArray: ['1', '2'] }); await new Promise(setImmediate); - expect(window.fetch).toBeCalledWith( + expect(window.fetch).toHaveBeenCalledWith( url, expect.objectContaining({ body: 'dataArray=1&dataArray=2', method: 'POST' }) ); @@ -228,15 +228,15 @@ describe('requestTryAndRepeatUntil', () => { for (let i = 1; i < 5; i++) { jest.runAllTimers(); - expect(apiCall).toBeCalledTimes(i); + expect(apiCall).toHaveBeenCalledTimes(i); await new Promise(setImmediate); - expect(stopRepeat).toBeCalledTimes(i); + expect(stopRepeat).toHaveBeenCalledTimes(i); } apiCall.mockResolvedValue({ repeat: false }); jest.runAllTimers(); - expect(apiCall).toBeCalledTimes(5); + expect(apiCall).toHaveBeenCalledTimes(5); await new Promise(setImmediate); - expect(stopRepeat).toBeCalledTimes(5); + expect(stopRepeat).toHaveBeenCalledTimes(5); await expect(promiseResult).resolves.toEqual({ repeat: false }); }); @@ -253,14 +253,14 @@ describe('requestTryAndRepeatUntil', () => { for (let i = 1; i < 5; i++) { jest.runAllTimers(); - expect(apiCall).toBeCalledTimes(i); + expect(apiCall).toHaveBeenCalledTimes(i); await new Promise(setImmediate); } apiCall.mockResolvedValue('Success'); jest.runAllTimers(); - expect(apiCall).toBeCalledTimes(5); + expect(apiCall).toHaveBeenCalledTimes(5); await new Promise(setImmediate); - expect(stopRepeat).toBeCalledTimes(1); + expect(stopRepeat).toHaveBeenCalledTimes(1); await expect(promiseResult).resolves.toBe('Success'); }); @@ -275,16 +275,16 @@ describe('requestTryAndRepeatUntil', () => { ); for (let i = 1; i < 3; i++) { - expect(apiCall).toBeCalledTimes(i); + expect(apiCall).toHaveBeenCalledTimes(i); await new Promise(setImmediate); jest.runAllTimers(); } - expect(apiCall).toBeCalledTimes(3); + expect(apiCall).toHaveBeenCalledTimes(3); await expect(promiseResult).rejects.toBeUndefined(); // It should not call anymore after 3 times jest.runAllTimers(); - expect(apiCall).toBeCalledTimes(3); + expect(apiCall).toHaveBeenCalledTimes(3); }); it('should slow down after 2 calls', async () => { @@ -298,24 +298,24 @@ describe('requestTryAndRepeatUntil', () => { for (let i = 1; i < 3; i++) { jest.advanceTimersByTime(500); - expect(apiCall).toBeCalledTimes(i); + expect(apiCall).toHaveBeenCalledTimes(i); await new Promise(setImmediate); } jest.advanceTimersByTime(500); - expect(apiCall).toBeCalledTimes(2); + expect(apiCall).toHaveBeenCalledTimes(2); jest.advanceTimersByTime(2000); - expect(apiCall).toBeCalledTimes(2); + expect(apiCall).toHaveBeenCalledTimes(2); jest.advanceTimersByTime(500); - expect(apiCall).toBeCalledTimes(3); + expect(apiCall).toHaveBeenCalledTimes(3); await new Promise(setImmediate); jest.advanceTimersByTime(3000); - expect(apiCall).toBeCalledTimes(4); + expect(apiCall).toHaveBeenCalledTimes(4); await new Promise(setImmediate); jest.runAllTimers(); - expect(apiCall).toBeCalledTimes(5); + expect(apiCall).toHaveBeenCalledTimes(5); await expect(promiseResult).rejects.toBeUndefined(); }); @@ -333,17 +333,14 @@ describe('checkStatus', () => { }); it('should handle required authentication', async () => { - await checkStatus(mockResponse({}, HttpStatus.Unauthorized)).catch(() => { - expect(handleRequiredAuthentication).toBeCalled(); - }); + await checkStatus(mockResponse({}, HttpStatus.Unauthorized)).catch(() => {}); + expect(handleRequiredAuthentication).toHaveBeenCalled(); }); it('should bybass the redirect with a 401 error', async () => { const mockedResponse = mockResponse({}, HttpStatus.Unauthorized); - await checkStatus(mockedResponse, true).catch(response => { - expect(handleRequiredAuthentication).not.toBeCalled(); - expect(response).toEqual(mockedResponse); - }); + await expect(checkStatus(mockedResponse, true)).rejects.toBe(mockedResponse); + expect(handleRequiredAuthentication).not.toHaveBeenCalled(); }); }); it('should export status codes', () => { diff --git a/server/sonar-web/src/main/js/helpers/__tests__/scrolling-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/scrolling-test.ts index 098d00ad5d9..47272979ca4 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/scrolling-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/scrolling-test.ts @@ -74,7 +74,7 @@ describe('scrollToElement', () => { scrollToElement(element, { smooth: false }); - expect(window.scrollTo).toBeCalledWith(0, 445); + expect(window.scrollTo).toHaveBeenCalledWith(0, 445); }); it('should scroll window up to element', () => { @@ -88,7 +88,7 @@ describe('scrollToElement', () => { scrollToElement(element, { smooth: false }); - expect(window.scrollTo).toBeCalledWith(0, -10); + expect(window.scrollTo).toHaveBeenCalledWith(0, -10); }); it('should scroll window down to element smoothly', () => { @@ -104,7 +104,7 @@ describe('scrollToElement', () => { jest.runAllTimers(); - expect(window.scrollTo).toBeCalledTimes(10); + expect(window.scrollTo).toHaveBeenCalledTimes(10); }); }); @@ -156,7 +156,7 @@ describe('scrollHorizontally', () => { scrollHorizontally(element, { smooth: false }); - expect(window.scrollTo).toBeCalledWith(445, 0); + expect(window.scrollTo).toHaveBeenCalledWith(445, 0); }); it('should scroll window left to element', () => { @@ -170,7 +170,7 @@ describe('scrollHorizontally', () => { scrollHorizontally(element, { smooth: false }); - expect(window.scrollTo).toBeCalledWith(-10, 0); + expect(window.scrollTo).toHaveBeenCalledWith(-10, 0); }); it('should scroll window right to element smoothly', () => { @@ -186,7 +186,7 @@ describe('scrollHorizontally', () => { jest.runAllTimers(); - expect(window.scrollTo).toBeCalledTimes(10); + expect(window.scrollTo).toHaveBeenCalledTimes(10); }); }); @@ -207,11 +207,11 @@ it('correctly queues and processes multiple scroll calls', async () => { await Promise.resolve(setImmediate); await Promise.resolve(setImmediate); - expect(window.scrollTo).toBeCalledTimes(11); + expect(window.scrollTo).toHaveBeenCalledTimes(11); scrollHorizontally(element1, {}); jest.runAllTimers(); - expect(window.scrollTo).toBeCalledTimes(21); + expect(window.scrollTo).toHaveBeenCalledTimes(21); }); const mockGetBoundingClientRect = (overrides: Partial<ClientRect>) => () => diff --git a/server/sonar-web/src/main/js/helpers/__tests__/sonarlint-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/sonarlint-test.ts index d466f014d83..bb961c22932 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/sonarlint-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/sonarlint-test.ts @@ -129,6 +129,6 @@ describe('sendUserToken', () => { await expect(async () => { await sendUserToken(64122, { ...token, isExpired: false }); - }).rejects.toThrowError('400 I no likez. Meh'); + }).rejects.toThrow('400 I no likez. Meh'); }); }); |