diff --git a/.eslintrc.js b/.eslintrc.js index 0257a2af1e..675a834efb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -50,179 +50,191 @@ module.exports = { 'testing-library/no-await-sync-query': 'error', 'testing-library/prefer-wait-for': 'error', 'testing-library/no-dom-import': 'error', + 'testing-library/no-wait-for-side-effects': 'error', + 'testing-library/no-wait-for-empty-callback': 'error', 'no-restricted-globals': [ 'error', - 'postMessage', - 'blur', - 'focus', - 'close', - 'frames', - 'self', - 'parent', - 'opener', - 'top', - 'length', - 'closed', - 'location', - 'origin', - 'name', - 'locationbar', - 'menubar', - 'personalbar', - 'scrollbars', - 'statusbar', - 'toolbar', - 'status', - 'frameElement', - 'navigator', - 'customElements', - 'external', - 'screen', - 'innerWidth', - 'innerHeight', - 'scrollX', - 'pageXOffset', - 'scrollY', - 'pageYOffset', - 'screenX', - 'screenY', - 'outerWidth', - 'outerHeight', - 'devicePixelRatio', - 'clientInformation', - 'screenLeft', - 'screenTop', - 'defaultStatus', - 'defaultstatus', - 'styleMedia', - 'onanimationend', - 'onanimationiteration', - 'onanimationstart', - 'onsearch', - 'ontransitionend', - 'onwebkitanimationend', - 'onwebkitanimationiteration', - 'onwebkitanimationstart', - 'onwebkittransitionend', - 'isSecureContext', - 'onabort', - 'onblur', - 'oncancel', - 'oncanplay', - 'oncanplaythrough', - 'onchange', - 'onclick', - 'onclose', - 'oncontextmenu', - 'oncuechange', - 'ondblclick', - 'ondrag', - 'ondragend', - 'ondragenter', - 'ondragleave', - 'ondragover', - 'ondragstart', - 'ondrop', - 'ondurationchange', - 'onemptied', - 'onended', - 'onerror', - 'onfocus', - 'oninput', - 'oninvalid', - 'onkeydown', - 'onkeypress', - 'onkeyup', - 'onload', - 'onloadeddata', - 'onloadedmetadata', - 'onloadstart', - 'onmousedown', - 'onmouseenter', - 'onmouseleave', - 'onmousemove', - 'onmouseout', - 'onmouseover', - 'onmouseup', - 'onmousewheel', - 'onpause', - 'onplay', - 'onplaying', - 'onprogress', - 'onratechange', - 'onreset', - 'onresize', - 'onscroll', - 'onseeked', - 'onseeking', - 'onselect', - 'onstalled', - 'onsubmit', - 'onsuspend', - 'ontimeupdate', - 'ontoggle', - 'onvolumechange', - 'onwaiting', - 'onwheel', - 'onauxclick', - 'ongotpointercapture', - 'onlostpointercapture', - 'onpointerdown', - 'onpointermove', - 'onpointerup', - 'onpointercancel', - 'onpointerover', - 'onpointerout', - 'onpointerenter', - 'onpointerleave', - 'onafterprint', - 'onbeforeprint', - 'onbeforeunload', - 'onhashchange', - 'onlanguagechange', - 'onmessage', - 'onmessageerror', - 'onoffline', - 'ononline', - 'onpagehide', - 'onpageshow', - 'onpopstate', - 'onrejectionhandled', - 'onstorage', - 'onunhandledrejection', - 'onunload', - 'performance', - 'stop', - 'open', - 'print', - 'captureEvents', - 'releaseEvents', - 'getComputedStyle', - 'matchMedia', - 'moveTo', - 'moveBy', - 'resizeTo', - 'resizeBy', - 'getSelection', - 'find', - 'createImageBitmap', - 'scroll', - 'scrollTo', - 'scrollBy', - 'onappinstalled', - 'onbeforeinstallprompt', - 'crypto', - 'ondevicemotion', - 'ondeviceorientation', - 'ondeviceorientationabsolute', - 'indexedDB', - 'webkitStorageInfo', - 'chrome', - 'visualViewport', - 'speechSynthesis', - 'webkitRequestFileSystem', - 'webkitResolveLocalFileSystemURL', - 'openDatabase', - ], + [ + 'blur', + 'captureEvents', + 'chrome', + 'clientInformation', + 'close', + 'closed', + 'createImageBitmap', + 'crypto', + 'customElements', + 'defaultstatus', + 'defaultStatus', + 'devicePixelRatio', + 'external', + 'find', + 'focus', + 'frameElement', + 'frames', + 'getComputedStyle', + 'getSelection', + 'indexedDB', + 'innerHeight', + 'innerWidth', + 'isSecureContext', + 'length', + 'location', + 'locationbar', + 'matchMedia', + 'menubar', + 'moveBy', + 'moveTo', + 'name', + 'navigator', + 'onabort', + 'onafterprint', + 'onanimationend', + 'onanimationiteration', + 'onanimationstart', + 'onappinstalled', + 'onauxclick', + 'onbeforeinstallprompt', + 'onbeforeprint', + 'onbeforeunload', + 'onblur', + 'oncancel', + 'oncanplay', + 'oncanplaythrough', + 'onchange', + 'onclick', + 'onclose', + 'oncontextmenu', + 'oncuechange', + 'ondblclick', + 'ondevicemotion', + 'ondeviceorientation', + 'ondeviceorientationabsolute', + 'ondrag', + 'ondragend', + 'ondragenter', + 'ondragleave', + 'ondragover', + 'ondragstart', + 'ondrop', + 'ondurationchange', + 'onemptied', + 'onended', + 'onerror', + 'onfocus', + 'ongotpointercapture', + 'onhashchange', + 'oninput', + 'oninvalid', + 'onkeydown', + 'onkeypress', + 'onkeyup', + 'onlanguagechange', + 'onload', + 'onloadeddata', + 'onloadedmetadata', + 'onloadstart', + 'onlostpointercapture', + 'onmessage', + 'onmessageerror', + 'onmousedown', + 'onmouseenter', + 'onmouseleave', + 'onmousemove', + 'onmouseout', + 'onmouseover', + 'onmouseup', + 'onmousewheel', + 'onoffline', + 'ononline', + 'onpagehide', + 'onpageshow', + 'onpause', + 'onplay', + 'onplaying', + 'onpointercancel', + 'onpointerdown', + 'onpointerenter', + 'onpointerleave', + 'onpointermove', + 'onpointerout', + 'onpointerover', + 'onpointerup', + 'onpopstate', + 'onprogress', + 'onratechange', + 'onrejectionhandled', + 'onreset', + 'onresize', + 'onscroll', + 'onsearch', + 'onseeked', + 'onseeking', + 'onselect', + 'onstalled', + 'onstorage', + 'onsubmit', + 'onsuspend', + 'ontimeupdate', + 'ontoggle', + 'ontransitionend', + 'onunhandledrejection', + 'onunload', + 'onvolumechange', + 'onwaiting', + 'onwebkitanimationend', + 'onwebkitanimationiteration', + 'onwebkitanimationstart', + 'onwebkittransitionend', + 'onwheel', + 'open', + 'openDatabase', + 'opener', + 'origin', + 'outerHeight', + 'outerWidth', + 'pageXOffset', + 'pageYOffset', + 'parent', + 'performance', + 'personalbar', + 'postMessage', + 'print', + 'releaseEvents', + 'resizeBy', + 'resizeTo', + 'screen', + 'screenLeft', + 'screenTop', + 'screenX', + 'screenY', + 'scroll', + 'scrollbars', + 'scrollBy', + 'scrollTo', + 'scrollX', + 'scrollY', + 'self', + 'speechSynthesis', + 'status', + 'statusbar', + 'stop', + 'styleMedia', + 'toolbar', + 'top', + 'visualViewport', + 'webkitRequestFileSystem', + 'webkitResolveLocalFileSystemURL', + 'webkitStorageInfo', + ].map(function f(name) { + return { + name: name, + message: + 'Avoid using implicitly global variables. Use e.g. window.' + + name + + ' instead if this was your intent.', + }; + }), + ].flat(), }, }; diff --git a/packages/core-app-api/src/routing/FeatureFlagged.test.tsx b/packages/core-app-api/src/routing/FeatureFlagged.test.tsx index 410540f77e..8ee74c0a23 100644 --- a/packages/core-app-api/src/routing/FeatureFlagged.test.tsx +++ b/packages/core-app-api/src/routing/FeatureFlagged.test.tsx @@ -16,7 +16,7 @@ import React from 'react'; import { FeatureFlagged } from './FeatureFlagged'; -import { render } from '@testing-library/react'; +import { render, screen } from '@testing-library/react'; import { LocalStorageFeatureFlags } from '../apis'; import { TestApiProvider } from '@backstage/test-utils'; import { featureFlagsApiRef } from '@backstage/core-plugin-api'; @@ -35,7 +35,7 @@ describe('FeatureFlagged', () => { .spyOn(mockFeatureFlagsApi, 'isActive') .mockImplementation(() => true); - const { queryByText } = render( + render(
@@ -45,14 +45,14 @@ describe('FeatureFlagged', () => { , ); - expect(queryByText('BACKSTAGE!')).toBeInTheDocument(); + expect(screen.getByText('BACKSTAGE!')).toBeInTheDocument(); }); it('should not render contents when the feature flag is disabled', async () => { jest .spyOn(mockFeatureFlagsApi, 'isActive') .mockImplementation(() => false); - const { queryByText } = render( + render(
@@ -62,7 +62,7 @@ describe('FeatureFlagged', () => { , ); - expect(queryByText('BACKSTAGE!')).not.toBeInTheDocument(); + expect(screen.queryByText('BACKSTAGE!')).not.toBeInTheDocument(); }); }); describe('without', () => { @@ -71,7 +71,7 @@ describe('FeatureFlagged', () => { .spyOn(mockFeatureFlagsApi, 'isActive') .mockImplementation(() => true); - const { queryByText } = render( + render(
@@ -81,14 +81,14 @@ describe('FeatureFlagged', () => { , ); - expect(queryByText('BACKSTAGE!')).not.toBeInTheDocument(); + expect(screen.queryByText('BACKSTAGE!')).not.toBeInTheDocument(); }); it('should render contents when the feature flag is disabled', async () => { jest .spyOn(mockFeatureFlagsApi, 'isActive') .mockImplementation(() => false); - const { queryByText } = render( + render(
@@ -98,7 +98,7 @@ describe('FeatureFlagged', () => { , ); - expect(queryByText('BACKSTAGE!')).toBeInTheDocument(); + expect(screen.getByText('BACKSTAGE!')).toBeInTheDocument(); }); }); }); diff --git a/packages/core-components/src/components/AlertDisplay/AlertDisplay.test.tsx b/packages/core-components/src/components/AlertDisplay/AlertDisplay.test.tsx index 477057f31b..c366082b46 100644 --- a/packages/core-components/src/components/AlertDisplay/AlertDisplay.test.tsx +++ b/packages/core-components/src/components/AlertDisplay/AlertDisplay.test.tsx @@ -15,6 +15,7 @@ */ import React from 'react'; +import { screen } from '@testing-library/react'; import { AlertDisplay } from './AlertDisplay'; import { alertApiRef } from '@backstage/core-plugin-api'; import { AlertApiForwarder } from '@backstage/core-app-api'; @@ -34,7 +35,7 @@ describe('', () => { }); it('renders with message', async () => { - const { queryByText } = await renderInTestApp( + await renderInTestApp( ', () => { , ); - expect(queryByText(TEST_MESSAGE)).toBeInTheDocument(); + expect(screen.getByText(TEST_MESSAGE)).toBeInTheDocument(); }); describe('with multiple messages', () => { @@ -73,23 +74,23 @@ describe('', () => { ] as const; it('renders first message', async () => { - const { queryByText } = await renderInTestApp( + await renderInTestApp( , ); - expect(queryByText('message one')).toBeInTheDocument(); + expect(screen.getByText('message one')).toBeInTheDocument(); }); it('renders a count of remaining messages', async () => { - const { queryByText } = await renderInTestApp( + await renderInTestApp( , ); - expect(queryByText('(2 older messages)')).toBeInTheDocument(); + expect(screen.getByText('(2 older messages)')).toBeInTheDocument(); }); }); }); diff --git a/packages/core-components/src/components/LogViewer/RealLogViewer.test.tsx b/packages/core-components/src/components/LogViewer/RealLogViewer.test.tsx index b56279a53f..dd707778e1 100644 --- a/packages/core-components/src/components/LogViewer/RealLogViewer.test.tsx +++ b/packages/core-components/src/components/LogViewer/RealLogViewer.test.tsx @@ -60,11 +60,11 @@ describe('RealLogViewer', () => { await userEvent.keyboard('{shift>}{enter}{/shift}'); expect(rendered.getByText('3/3')).toBeInTheDocument(); - expect(rendered.queryByText('Some Log Line')).toBeInTheDocument(); + expect(rendered.getByText('Some Log Line')).toBeInTheDocument(); await userEvent.keyboard('{meta>}{enter}{/meta}'); expect(rendered.queryByText('Some Log Line')).not.toBeInTheDocument(); await userEvent.keyboard('{meta>}{enter}{/meta}'); - expect(rendered.queryByText('Some Log Line')).toBeInTheDocument(); + expect(rendered.getByText('Some Log Line')).toBeInTheDocument(); // Tab down to line #2 and click await userEvent.tab(); diff --git a/packages/core-components/src/components/SupportButton/SupportButton.test.tsx b/packages/core-components/src/components/SupportButton/SupportButton.test.tsx index 2907b24702..6b0e239aa5 100644 --- a/packages/core-components/src/components/SupportButton/SupportButton.test.tsx +++ b/packages/core-components/src/components/SupportButton/SupportButton.test.tsx @@ -14,15 +14,15 @@ * limitations under the License. */ -import React from 'react'; -import { fireEvent, screen } from '@testing-library/react'; +import { configApiRef } from '@backstage/core-plugin-api'; import { MockConfigApi, renderInTestApp, TestApiProvider, } from '@backstage/test-utils'; +import { act, fireEvent, screen } from '@testing-library/react'; +import React from 'react'; import { SupportButton } from './SupportButton'; -import { configApiRef } from '@backstage/core-plugin-api'; const configApi = new MockConfigApi({ app: { @@ -45,8 +45,9 @@ const POPOVER_ID = 'support-button-popover'; describe('', () => { it('renders without exploding', async () => { await renderInTestApp(); - - expect(screen.getByTestId(SUPPORT_BUTTON_ID)).toBeInTheDocument(); + await expect( + screen.findByTestId(SUPPORT_BUTTON_ID), + ).resolves.toBeInTheDocument(); }); it('supports passing a title', async () => { @@ -96,11 +97,13 @@ describe('', () => { it('shows popover on click', async () => { await renderInTestApp(); - const supportButton = screen.getByTestId(SUPPORT_BUTTON_ID); - expect(supportButton).toBeInTheDocument(); + await expect( + screen.findByTestId(SUPPORT_BUTTON_ID), + ).resolves.toBeInTheDocument(); + await act(async () => { + fireEvent.click(screen.getByTestId(SUPPORT_BUTTON_ID)); + }); - fireEvent.click(supportButton); - - expect(screen.getByTestId(POPOVER_ID)).toBeInTheDocument(); + await expect(screen.findByTestId(POPOVER_ID)).resolves.toBeInTheDocument(); }); }); diff --git a/packages/core-components/src/components/TabbedLayout/RoutedTabs.test.tsx b/packages/core-components/src/components/TabbedLayout/RoutedTabs.test.tsx index 15b00937a0..bbdb901f33 100644 --- a/packages/core-components/src/components/TabbedLayout/RoutedTabs.test.tsx +++ b/packages/core-components/src/components/TabbedLayout/RoutedTabs.test.tsx @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { renderInTestApp } from '@backstage/test-utils'; import { act, fireEvent } from '@testing-library/react'; import React from 'react'; @@ -65,14 +66,14 @@ describe('RoutedTabs', () => { expect(rendered.queryByText('tabbed-test-content')).not.toBeInTheDocument(); expect(rendered.getByText('tabbed-test-title-2')).toBeInTheDocument(); - expect(rendered.queryByText('tabbed-test-content-2')).toBeInTheDocument(); + expect(rendered.getByText('tabbed-test-content-2')).toBeInTheDocument(); const thirdTab = rendered.queryAllByRole('tab')[2]; act(() => { fireEvent.click(thirdTab); }); expect(rendered.getByText('tabbed-test-title-3')).toBeInTheDocument(); - expect(rendered.queryByText('tabbed-test-content-3')).toBeInTheDocument(); + expect(rendered.getByText('tabbed-test-content-3')).toBeInTheDocument(); }); describe('correctly delegates nested links', () => { @@ -113,9 +114,9 @@ describe('RoutedTabs', () => { expect( rendered.queryByText('tabbed-test-content'), ).not.toBeInTheDocument(); - expect(rendered.queryByText('tabbed-test-content-2')).toBeInTheDocument(); + expect(rendered.getByText('tabbed-test-content-2')).toBeInTheDocument(); expect( - rendered.queryByText('tabbed-test-nested-content-2'), + rendered.getByText('tabbed-test-nested-content-2'), ).toBeInTheDocument(); }); @@ -125,7 +126,7 @@ describe('RoutedTabs', () => { expect( rendered.queryByText('tabbed-test-content'), ).not.toBeInTheDocument(); - expect(rendered.queryByText('tabbed-test-content-2')).toBeInTheDocument(); + expect(rendered.getByText('tabbed-test-content-2')).toBeInTheDocument(); expect( rendered.queryByText('tabbed-test-nested-content-2'), ).not.toBeInTheDocument(); @@ -142,7 +143,7 @@ describe('RoutedTabs', () => { expect(rendered.queryByText('tabbed-test-content')).not.toBeInTheDocument(); expect(rendered.getByText('tabbed-test-title-2')).toBeInTheDocument(); - expect(rendered.queryByText('tabbed-test-content-2')).toBeInTheDocument(); + expect(rendered.getByText('tabbed-test-content-2')).toBeInTheDocument(); }); it('redirects to the top level when no route is matching the url', async () => { diff --git a/packages/core-components/src/components/TabbedLayout/TabbedLayout.test.tsx b/packages/core-components/src/components/TabbedLayout/TabbedLayout.test.tsx index e103fc2f46..b84a7f262d 100644 --- a/packages/core-components/src/components/TabbedLayout/TabbedLayout.test.tsx +++ b/packages/core-components/src/components/TabbedLayout/TabbedLayout.test.tsx @@ -79,6 +79,6 @@ describe('TabbedLayout', () => { expect(queryByText('tabbed-test-content')).not.toBeInTheDocument(); expect(getByText('tabbed-test-title-2')).toBeInTheDocument(); - expect(queryByText('tabbed-test-content-2')).toBeInTheDocument(); + expect(getByText('tabbed-test-content-2')).toBeInTheDocument(); }); }); diff --git a/packages/core-components/src/layout/HeaderActionMenu/HeaderActionMenu.test.tsx b/packages/core-components/src/layout/HeaderActionMenu/HeaderActionMenu.test.tsx index 92ce241aa8..b56ae3167f 100644 --- a/packages/core-components/src/layout/HeaderActionMenu/HeaderActionMenu.test.tsx +++ b/packages/core-components/src/layout/HeaderActionMenu/HeaderActionMenu.test.tsx @@ -43,7 +43,7 @@ describe('', () => { await fireEvent.click(rendered.queryByText('Some label') as Node); expect(onClickFunction).toHaveBeenCalled(); // We do not expect the dropdown to disappear after click - expect(rendered.queryByText('Some label')).toBeInTheDocument(); + expect(rendered.getByText('Some label')).toBeInTheDocument(); }); it('Disabled', async () => { @@ -80,7 +80,7 @@ describe('', () => { await fireEvent.click(rendered.queryByText('Secondary label') as Node); expect(onClickFunction).toHaveBeenCalled(); // We do not expect the dropdown to disappear after click - expect(rendered.queryByText('Some label')).toBeInTheDocument(); + expect(rendered.getByText('Some label')).toBeInTheDocument(); }); it('should close when hitting escape', async () => { diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.test.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.test.tsx index 02b67090fa..a8188ce358 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.test.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.test.tsx @@ -110,7 +110,7 @@ describe('', () => { expect(onSubmitFn).not.toHaveBeenCalled(); expect( - screen.queryByText('Error in required main field'), + screen.getByText('Error in required main field'), ).toBeInTheDocument(); }); }); diff --git a/plugins/catalog-import/src/components/StepPrepareSelectLocations/StepPrepareSelectLocations.test.tsx b/plugins/catalog-import/src/components/StepPrepareSelectLocations/StepPrepareSelectLocations.test.tsx index 5a30c7735a..b5efd3fbbf 100644 --- a/plugins/catalog-import/src/components/StepPrepareSelectLocations/StepPrepareSelectLocations.test.tsx +++ b/plugins/catalog-import/src/components/StepPrepareSelectLocations/StepPrepareSelectLocations.test.tsx @@ -69,7 +69,7 @@ describe('', () => { expect(screen.getByText('url-1')).toBeInTheDocument(); expect(screen.getByText('url-2')).toBeInTheDocument(); expect( - screen.queryByText(/Select one or more locations/), + screen.getByText(/Select one or more locations/), ).toBeInTheDocument(); expect( screen.queryByText(/locations already exist/), @@ -104,7 +104,7 @@ describe('', () => { ); expect(screen.getByText(/my-target/)).toBeInTheDocument(); - expect(screen.queryByText(/locations already exist/)).toBeInTheDocument(); + expect(screen.getByText(/locations already exist/)).toBeInTheDocument(); expect( screen.queryByText(/Select one or more locations/), ).not.toBeInTheDocument(); diff --git a/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx b/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx index d5309a383d..c31381df20 100644 --- a/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx +++ b/plugins/catalog-react/src/components/UserListPicker/UserListPicker.test.tsx @@ -151,8 +151,8 @@ describe('', () => { , ); - expect(screen.queryByText('Personal')).toBeInTheDocument(); - expect(screen.queryByText('Test Company')).toBeInTheDocument(); + expect(screen.getByText('Personal')).toBeInTheDocument(); + expect(screen.getByText('Test Company')).toBeInTheDocument(); }); it('renders filters', () => { diff --git a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx index 980ce13109..08c751c6c6 100644 --- a/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx +++ b/plugins/catalog/src/components/EntityLayout/EntityLayout.test.tsx @@ -190,7 +190,7 @@ describe('EntityLayout', () => { expect(screen.queryByText('tabbed-test-content')).not.toBeInTheDocument(); expect(screen.getByText('tabbed-test-title-2')).toBeInTheDocument(); - expect(screen.queryByText('tabbed-test-content-2')).toBeInTheDocument(); + expect(screen.getByText('tabbed-test-content-2')).toBeInTheDocument(); }); it('should conditionally render tabs', async () => { @@ -228,8 +228,8 @@ describe('EntityLayout', () => { }, ); - expect(screen.queryByText('tabbed-test-title')).toBeInTheDocument(); + expect(screen.getByText('tabbed-test-title')).toBeInTheDocument(); expect(screen.queryByText('tabbed-test-title-2')).not.toBeInTheDocument(); - expect(screen.queryByText('tabbed-test-title-3')).toBeInTheDocument(); + expect(screen.getByText('tabbed-test-title-3')).toBeInTheDocument(); }); }); diff --git a/plugins/catalog/src/components/EntityLinksCard/EntityLinksCard.test.tsx b/plugins/catalog/src/components/EntityLinksCard/EntityLinksCard.test.tsx index 6316bdbc85..304a962212 100644 --- a/plugins/catalog/src/components/EntityLinksCard/EntityLinksCard.test.tsx +++ b/plugins/catalog/src/components/EntityLinksCard/EntityLinksCard.test.tsx @@ -52,7 +52,7 @@ describe('EntityLinksCard', () => { ), ); - expect(screen.queryByText('admin dashboard')).toBeInTheDocument(); + expect(screen.getByText('admin dashboard')).toBeInTheDocument(); expect(screen.queryByText('derp')).not.toBeInTheDocument(); }); @@ -66,7 +66,7 @@ describe('EntityLinksCard', () => { ); expect( - screen.queryByText(/.*No links defined for this entity.*/), + screen.getByText(/.*No links defined for this entity.*/), ).toBeInTheDocument(); expect(screen.queryByText('admin dashboard')).not.toBeInTheDocument(); }); diff --git a/plugins/catalog/src/components/EntityLinksCard/IconLink.test.tsx b/plugins/catalog/src/components/EntityLinksCard/IconLink.test.tsx index 164e54a2eb..be784ae3e8 100644 --- a/plugins/catalog/src/components/EntityLinksCard/IconLink.test.tsx +++ b/plugins/catalog/src/components/EntityLinksCard/IconLink.test.tsx @@ -33,6 +33,6 @@ describe('IconLink', () => { , ); - expect(screen.queryByText('I am Link')).toBeInTheDocument(); + expect(screen.getByText('I am Link')).toBeInTheDocument(); }); }); diff --git a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx index cfe3022261..350349fe95 100644 --- a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx +++ b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.test.tsx @@ -226,7 +226,7 @@ describe('', () => { expect(screen.getByText('Error: Foo')).toBeInTheDocument(); expect(screen.queryByText('Error: This should not be rendered')).toBeNull(); expect( - screen.queryByText('The error below originates from'), + screen.getByText('The error below originates from'), ).toBeInTheDocument(); }); }); diff --git a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx index d2c51465b5..164c7e60fd 100644 --- a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx +++ b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.test.tsx @@ -54,7 +54,7 @@ describe('EntitySwitch', () => { , ); - expect(screen.queryByText('A')).toBeInTheDocument(); + expect(screen.getByText('A')).toBeInTheDocument(); expect(screen.queryByText('B')).not.toBeInTheDocument(); expect(screen.queryByText('C')).not.toBeInTheDocument(); @@ -69,7 +69,7 @@ describe('EntitySwitch', () => { ); expect(screen.queryByText('A')).not.toBeInTheDocument(); - expect(screen.queryByText('B')).toBeInTheDocument(); + expect(screen.getByText('B')).toBeInTheDocument(); expect(screen.queryByText('C')).not.toBeInTheDocument(); rendered.rerender( @@ -84,7 +84,7 @@ describe('EntitySwitch', () => { expect(screen.queryByText('A')).not.toBeInTheDocument(); expect(screen.queryByText('B')).not.toBeInTheDocument(); - expect(screen.queryByText('C')).toBeInTheDocument(); + expect(screen.getByText('C')).toBeInTheDocument(); rendered.rerender( @@ -96,7 +96,7 @@ describe('EntitySwitch', () => { expect(screen.queryByText('A')).not.toBeInTheDocument(); expect(screen.queryByText('B')).not.toBeInTheDocument(); - expect(screen.queryByText('C')).toBeInTheDocument(); + expect(screen.getByText('C')).toBeInTheDocument(); }); it('should switch child when filters switch', () => { @@ -113,7 +113,7 @@ describe('EntitySwitch', () => { , ); - expect(screen.queryByText('A')).toBeInTheDocument(); + expect(screen.getByText('A')).toBeInTheDocument(); expect(screen.queryByText('B')).not.toBeInTheDocument(); rendered.rerender( @@ -128,7 +128,7 @@ describe('EntitySwitch', () => { ); expect(screen.queryByText('A')).not.toBeInTheDocument(); - expect(screen.queryByText('B')).toBeInTheDocument(); + expect(screen.getByText('B')).toBeInTheDocument(); }); it('should switch with async condition that is true', async () => { diff --git a/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx b/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx index dc8d68e2b2..2fcd1c2702 100644 --- a/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx +++ b/plugins/catalog/src/components/SystemDiagramCard/SystemDiagramCard.test.tsx @@ -67,8 +67,8 @@ describe('', () => { }, ); - expect(screen.queryByText(/System Diagram/)).toBeInTheDocument(); - expect(screen.queryByText(/namespace2\/system2/)).toBeInTheDocument(); + expect(screen.getByText(/System Diagram/)).toBeInTheDocument(); + expect(screen.getByText(/namespace2\/system2/)).toBeInTheDocument(); expect(screen.queryByText(/namespace\/entity/)).not.toBeInTheDocument(); }); diff --git a/plugins/cost-insights/src/components/BarChart/BarChart.test.tsx b/plugins/cost-insights/src/components/BarChart/BarChart.test.tsx index 530ca16e8f..37204d5ec6 100644 --- a/plugins/cost-insights/src/components/BarChart/BarChart.test.tsx +++ b/plugins/cost-insights/src/components/BarChart/BarChart.test.tsx @@ -104,7 +104,7 @@ describe('', () => { it('should display stepper if displaying more than 6 resources', async () => { const rendered = await renderWithProps({} as BarChartProps); - expect(rendered.queryByTestId('bar-chart-stepper')).toBeInTheDocument(); + expect(rendered.getByTestId('bar-chart-stepper')).toBeInTheDocument(); }); it('should display the next step button if resources are remaining', async () => { @@ -114,7 +114,7 @@ describe('', () => { rendered.queryByTestId('bar-chart-stepper-button-back'), ).not.toBeInTheDocument(); expect( - rendered.queryByTestId('bar-chart-stepper-button-next'), + rendered.getByTestId('bar-chart-stepper-button-next'), ).toBeInTheDocument(); }); diff --git a/plugins/cost-insights/src/components/BarChart/BarChartLegend.test.tsx b/plugins/cost-insights/src/components/BarChart/BarChartLegend.test.tsx index 690f0bbcd8..db515c233d 100644 --- a/plugins/cost-insights/src/components/BarChart/BarChartLegend.test.tsx +++ b/plugins/cost-insights/src/components/BarChart/BarChartLegend.test.tsx @@ -27,6 +27,6 @@ describe('', () => { , ); expect(rendered.getByText(/\$1,000/)).toBeInTheDocument(); - expect(rendered.queryByText(/\$5,000/)).toBeInTheDocument(); + expect(rendered.getByText(/\$5,000/)).toBeInTheDocument(); }); }); diff --git a/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx b/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx index 015a6279da..337d3d06b2 100644 --- a/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx +++ b/plugins/cost-insights/src/components/CostInsightsHeader/CostInsightsHeader.test.tsx @@ -17,7 +17,6 @@ import { CostInsightsHeader } from './CostInsightsHeader'; import { renderInTestApp, TestApiRegistry } from '@backstage/test-utils'; import React from 'react'; - import { ApiProvider } from '@backstage/core-app-api'; import { IdentityApi, identityApiRef } from '@backstage/core-plugin-api'; @@ -43,7 +42,7 @@ describe('', () => { , ); - expect(rendered.queryByText(/doing great/)).toBeInTheDocument(); + expect(rendered.getByText(/doing great/)).toBeInTheDocument(); }); it('Shows work to do when alerts > 1', async () => { @@ -57,7 +56,7 @@ describe('', () => { /> , ); - expect(rendered.queryByText(/few things/)).toBeInTheDocument(); + expect(rendered.getByText(/few things/)).toBeInTheDocument(); }); it('Handles grammar with a single alert', async () => { @@ -73,7 +72,7 @@ describe('', () => { ); expect(rendered.queryByText(/things/)).not.toBeInTheDocument(); - expect(rendered.queryByText(/one thing/)).toBeInTheDocument(); + expect(rendered.getByText(/one thing/)).toBeInTheDocument(); }); it('Shows no costs when hasCostData is false', async () => { @@ -87,7 +86,7 @@ describe('', () => { /> , ); - expect(rendered.queryByText(/this is awkward/)).toBeInTheDocument(); + expect(rendered.getByText(/this is awkward/)).toBeInTheDocument(); }); describe.each` @@ -109,9 +108,7 @@ describe('', () => { /> , ); - expect( - rendered.queryByText(/Test group display name/), - ).toBeInTheDocument(); + expect(rendered.getByText(/Test group display name/)).toBeInTheDocument(); }); it('Fallbacks to group id when display name not available', async () => { @@ -125,7 +122,7 @@ describe('', () => { /> , ); - expect(rendered.queryByText(/test-user-group-1/)).toBeInTheDocument(); + expect(rendered.getByText(/test-user-group-1/)).toBeInTheDocument(); }); }); }); diff --git a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx index dfac13dd42..7cb95d8006 100644 --- a/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx +++ b/plugins/cost-insights/src/components/PeriodSelect/PeriodSelect.test.tsx @@ -15,7 +15,7 @@ */ import React from 'react'; -import { getByRole, waitFor } from '@testing-library/react'; +import { getByRole, screen, waitFor } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; import userEvent from '@testing-library/user-event'; import { PeriodSelect, getDefaultOptions } from './PeriodSelect'; @@ -29,7 +29,7 @@ const options = getDefaultOptions(lastCompleteBillingDate); describe('', () => { it('Renders without exploding', async () => { - const rendered = await renderInTestApp( + await renderInTestApp( @@ -39,11 +39,11 @@ describe('', () => { /> , ); - expect(rendered.getByTestId('period-select')).toBeInTheDocument(); + expect(screen.getByTestId('period-select')).toBeInTheDocument(); }); it('Should display all costGrowth period options', async () => { - const rendered = await renderInTestApp( + await renderInTestApp( @@ -53,13 +53,13 @@ describe('', () => { /> , ); - const periodSelectContainer = rendered.getByTestId('period-select'); + const periodSelectContainer = screen.getByTestId('period-select'); const button = getByRole(periodSelectContainer, 'button'); await userEvent.click(button); - await waitFor(() => rendered.getByText('Past 60 Days')); + await waitFor(() => screen.getByText('Past 60 Days')); options.forEach(option => expect( - rendered.getByTestId(`period-select-option-${option.value}`), + screen.getByTestId(`period-select-option-${option.value}`), ).toBeInTheDocument(), ); }); @@ -78,19 +78,19 @@ describe('', () => { ? Duration.P30D : DefaultPageFilters.duration; - const rendered = await renderInTestApp( + await renderInTestApp( , , ); - const periodSelect = rendered.getByTestId('period-select'); + const periodSelect = screen.getByTestId('period-select'); const button = getByRole(periodSelect, 'button'); await userEvent.click(button); await userEvent.click( - rendered.getByTestId(`period-select-option-${duration}`), + screen.getByTestId(`period-select-option-${duration}`), ); expect(mockOnSelect).toHaveBeenLastCalledWith(duration); }); diff --git a/plugins/cost-insights/src/components/ProjectSelect/ProjectSelect.test.tsx b/plugins/cost-insights/src/components/ProjectSelect/ProjectSelect.test.tsx index 798b29de0d..7dd5b4253f 100644 --- a/plugins/cost-insights/src/components/ProjectSelect/ProjectSelect.test.tsx +++ b/plugins/cost-insights/src/components/ProjectSelect/ProjectSelect.test.tsx @@ -15,7 +15,7 @@ */ import React from 'react'; -import { getByRole, waitFor } from '@testing-library/react'; +import { getByRole, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { ProjectSelect } from './ProjectSelect'; import { MockFilterProvider } from '../../testUtils'; @@ -42,23 +42,19 @@ describe('', () => { }); it('Renders without exploding', async () => { - const rendered = await renderInTestApp(Component); - expect(rendered.getByText('All Projects')).toBeInTheDocument(); + await renderInTestApp(Component); + expect(screen.getByText('All Projects')).toBeInTheDocument(); }); it('shows all projects in the filter select', async () => { - const rendered = await renderInTestApp(Component); - const projectSelectContainer = rendered.getByTestId( - 'project-filter-select', - ); + await renderInTestApp(Component); + const projectSelectContainer = screen.getByTestId('project-filter-select'); const button = getByRole(projectSelectContainer, 'button'); await userEvent.click(button); - await waitFor(() => rendered.getByTestId('option-all')); + await waitFor(() => screen.getByTestId('option-all')); mockProjects.forEach(project => - expect( - rendered.getByText(project.name ?? project.id), - ).toBeInTheDocument(), + expect(screen.getByText(project.name ?? project.id)).toBeInTheDocument(), ); }); }); diff --git a/plugins/gcalendar/src/components/CalendarCard/AttendeeChip.test.tsx b/plugins/gcalendar/src/components/CalendarCard/AttendeeChip.test.tsx index 64485e74ab..769a225de3 100644 --- a/plugins/gcalendar/src/components/CalendarCard/AttendeeChip.test.tsx +++ b/plugins/gcalendar/src/components/CalendarCard/AttendeeChip.test.tsx @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import { screen } from '@testing-library/react'; import React from 'react'; - import { renderInTestApp } from '@backstage/test-utils'; - import { AttendeeChip } from './AttendeeChip'; import { EventAttendee, ResponseStatus } from '../../api'; @@ -27,8 +27,8 @@ describe('', () => { email, responseStatus: ResponseStatus.needsAction, }; - const { queryByText } = await renderInTestApp(); - expect(queryByText(email)).toBeInTheDocument(); + await renderInTestApp(); + expect(screen.getByText(email)).toBeInTheDocument(); }); it('renders accepted icon', async () => { @@ -37,8 +37,8 @@ describe('', () => { email, responseStatus: ResponseStatus.accepted, }; - const { getByTestId } = await renderInTestApp(); - expect(getByTestId('accepted-icon')).toBeInTheDocument(); + await renderInTestApp(); + expect(screen.getByTestId('accepted-icon')).toBeInTheDocument(); }); it('renders declined icon', async () => { @@ -47,7 +47,7 @@ describe('', () => { email, responseStatus: ResponseStatus.declined, }; - const { getByTestId } = await renderInTestApp(); - expect(getByTestId('declined-icon')).toBeInTheDocument(); + await renderInTestApp(); + expect(screen.getByTestId('declined-icon')).toBeInTheDocument(); }); }); diff --git a/plugins/gcalendar/src/components/CalendarCard/CalendarEvent.test.tsx b/plugins/gcalendar/src/components/CalendarCard/CalendarEvent.test.tsx index 7a48903bec..4a1ca884a9 100644 --- a/plugins/gcalendar/src/components/CalendarCard/CalendarEvent.test.tsx +++ b/plugins/gcalendar/src/components/CalendarCard/CalendarEvent.test.tsx @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import { fireEvent } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import React from 'react'; - import { renderInTestApp } from '@backstage/test-utils'; - import { CalendarEvent } from './CalendarEvent'; describe('', () => { @@ -42,16 +42,14 @@ describe('', () => { }; it('should render calendar event', async () => { - const { queryByText, queryByTestId } = await renderInTestApp( - , - ); - expect(queryByText(event.summary)).toBeInTheDocument(); - expect(queryByTestId('calendar-event-zoom-link')).toBeInTheDocument(); - expect(queryByTestId('calendar-event-zoom-link')).toHaveAttribute( + await renderInTestApp(); + expect(screen.getByText(event.summary)).toBeInTheDocument(); + expect(screen.getByTestId('calendar-event-zoom-link')).toBeInTheDocument(); + expect(screen.queryByTestId('calendar-event-zoom-link')).toHaveAttribute( 'href', event.conferenceData.entryPoints[0].uri, ); - expect(queryByTestId('calendar-event-time')).toBeInTheDocument(); + expect(screen.getByTestId('calendar-event-time')).toBeInTheDocument(); }); it('should not render time for events longer than 1 day', async () => { @@ -64,20 +62,18 @@ describe('', () => { date: '2022-02-19', }, }; - const { queryByText, queryByTestId } = await renderInTestApp( - , - ); - expect(queryByText(allDayEvent.summary)).toBeInTheDocument(); - expect(queryByTestId('calendar-event-time')).not.toBeInTheDocument(); + await renderInTestApp(); + expect(screen.getByText(allDayEvent.summary)).toBeInTheDocument(); + expect(screen.queryByTestId('calendar-event-time')).not.toBeInTheDocument(); }); it('should show popover on click', async () => { - const { queryByTestId, getByTestId } = await renderInTestApp( - , - ); - expect(queryByTestId('calendar-event-popover')).not.toBeInTheDocument(); + await renderInTestApp(); + expect( + screen.queryByTestId('calendar-event-popover'), + ).not.toBeInTheDocument(); - fireEvent.click(getByTestId('calendar-event')); - expect(queryByTestId('calendar-event-popover')).toBeInTheDocument(); + fireEvent.click(screen.getByTestId('calendar-event')); + expect(screen.getByTestId('calendar-event-popover')).toBeInTheDocument(); }); }); diff --git a/plugins/gcalendar/src/components/CalendarCard/CalendarEventPopoverContent.test.tsx b/plugins/gcalendar/src/components/CalendarCard/CalendarEventPopoverContent.test.tsx index fe48b2fd5a..107a3ed180 100644 --- a/plugins/gcalendar/src/components/CalendarCard/CalendarEventPopoverContent.test.tsx +++ b/plugins/gcalendar/src/components/CalendarCard/CalendarEventPopoverContent.test.tsx @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import React from 'react'; - +import { screen } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; - import { CalendarEventPopoverContent } from './CalendarEventPopoverContent'; describe('', () => { @@ -35,21 +35,18 @@ describe('', () => { }; it('should render event info', async () => { - const { queryByText, queryByTestId } = await renderInTestApp( - , - ); - expect(queryByText(event.summary)).toBeInTheDocument(); - expect(queryByText(event.description)).toBeInTheDocument(); - expect(queryByText(event.attendees[0].email)).toBeInTheDocument(); - expect(queryByText('Join Zoom Meeting')).toBeInTheDocument(); - expect(queryByText('Join Zoom Meeting')?.closest('a')).toHaveAttribute( - 'href', - event.conferenceData.entryPoints[0].uri, - ); - expect(queryByTestId('open-calendar-link')).toHaveAttribute( + await renderInTestApp(); + expect(screen.getByText(event.summary)).toBeInTheDocument(); + expect(screen.getByText(event.description)).toBeInTheDocument(); + expect(screen.getByText(event.attendees[0].email)).toBeInTheDocument(); + expect(screen.getByText('Join Zoom Meeting')).toBeInTheDocument(); + expect( + screen.queryByText('Join Zoom Meeting')?.closest('a'), + ).toHaveAttribute('href', event.conferenceData.entryPoints[0].uri); + expect(screen.queryByTestId('open-calendar-link')).toHaveAttribute( 'href', event.htmlLink, ); - expect(queryByText(event.attendees[0].email)).toBeInTheDocument(); + expect(screen.getByText(event.attendees[0].email)).toBeInTheDocument(); }); }); diff --git a/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx b/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx index d8a54928b2..c2ee202841 100644 --- a/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx +++ b/plugins/lighthouse/src/components/AuditList/AuditListTable.test.tsx @@ -76,7 +76,7 @@ describe('AuditListTable', () => { if (!website) throw new Error('https://anchor.fm must be present in fixture'); expect( - rendered.queryByText(formatTime(website.lastAudit.timeCreated)), + rendered.getByText(formatTime(website.lastAudit.timeCreated)), ).toBeInTheDocument(); }); diff --git a/plugins/lighthouse/src/components/AuditView/index.test.tsx b/plugins/lighthouse/src/components/AuditView/index.test.tsx index 00b2843a50..c68daddc67 100644 --- a/plugins/lighthouse/src/components/AuditView/index.test.tsx +++ b/plugins/lighthouse/src/components/AuditView/index.test.tsx @@ -98,7 +98,7 @@ describe('AuditView', () => { websiteResponse.audits.forEach(a => { expect( - rendered.queryByText(formatTime(a.timeCreated)), + rendered.getByText(formatTime(a.timeCreated)), ).toBeInTheDocument(); }); }); @@ -199,7 +199,7 @@ describe('AuditView', () => { await rendered.findByTestId('audit-sidebar'); - expect(rendered.queryByTestId('progress')).toBeInTheDocument(); + expect(rendered.getByTestId('progress')).toBeInTheDocument(); }); }); @@ -219,7 +219,7 @@ describe('AuditView', () => { await rendered.findByTestId('audit-sidebar'); - expect(rendered.queryByText(/This audit failed/)).toBeInTheDocument(); + expect(rendered.getByText(/This audit failed/)).toBeInTheDocument(); }); }); }); diff --git a/plugins/lighthouse/src/components/Intro/index.test.tsx b/plugins/lighthouse/src/components/Intro/index.test.tsx index ed4a11ff43..173dce1315 100644 --- a/plugins/lighthouse/src/components/Intro/index.test.tsx +++ b/plugins/lighthouse/src/components/Intro/index.test.tsx @@ -25,7 +25,7 @@ describe('LighthouseIntro', () => { it('renders successfully', () => { const rendered = render(wrapInTestApp()); expect( - rendered.queryByText('Welcome to Lighthouse in Backstage!'), + rendered.getByText('Welcome to Lighthouse in Backstage!'), ).toBeInTheDocument(); }); @@ -35,7 +35,7 @@ describe('LighthouseIntro', () => { it('selects the first text element', () => { const rendered = render(wrapInTestApp()); - expect(rendered.queryByText(firstTabRe)).toBeInTheDocument(); + expect(rendered.getByText(firstTabRe)).toBeInTheDocument(); expect(rendered.queryByText(secondTabRe)).not.toBeInTheDocument(); }); @@ -43,7 +43,7 @@ describe('LighthouseIntro', () => { const rendered = render(wrapInTestApp()); fireEvent.click(rendered.getByText('Setup')); expect(rendered.queryByText(firstTabRe)).not.toBeInTheDocument(); - expect(rendered.queryByText(secondTabRe)).toBeInTheDocument(); + expect(rendered.getByText(secondTabRe)).toBeInTheDocument(); }); }); diff --git a/plugins/pagerduty/src/components/Incident/Incidents.test.tsx b/plugins/pagerduty/src/components/Incident/Incidents.test.tsx index a83874a995..bd2016eb16 100644 --- a/plugins/pagerduty/src/components/Incident/Incidents.test.tsx +++ b/plugins/pagerduty/src/components/Incident/Incidents.test.tsx @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import React from 'react'; -import { render, waitFor } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import { Incidents } from './Incidents'; import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils'; import { pagerDutyApiRef } from '../../api'; @@ -32,15 +33,15 @@ describe('Incidents', () => { .fn() .mockImplementationOnce(async () => ({ incidents: [] })); - const { getByText, queryByTestId } = render( + render( wrapInTestApp( , ), ); - await waitFor(() => !queryByTestId('progress')); - expect(getByText('Nice! No incidents found!')).toBeInTheDocument(); + await waitFor(() => !screen.queryByTestId('progress')); + expect(screen.getByText('Nice! No incidents found!')).toBeInTheDocument(); }); it('Renders all incidents', async () => { @@ -85,25 +86,25 @@ describe('Incidents', () => { }, ] as PagerDutyIncident[], })); - const { getByText, getAllByTitle, queryByTestId } = render( + render( wrapInTestApp( , ), ); - await waitFor(() => !queryByTestId('progress')); - expect(getByText('title1')).toBeInTheDocument(); - expect(getByText('title2')).toBeInTheDocument(); - expect(getByText('person1')).toBeInTheDocument(); - expect(getByText('person2')).toBeInTheDocument(); - expect(getByText('triggered')).toBeInTheDocument(); - expect(getByText('acknowledged')).toBeInTheDocument(); - expect(queryByTestId('chip-triggered')).toBeInTheDocument(); - expect(queryByTestId('chip-acknowledged')).toBeInTheDocument(); + await waitFor(() => !screen.queryByTestId('progress')); + expect(screen.getByText('title1')).toBeInTheDocument(); + expect(screen.getByText('title2')).toBeInTheDocument(); + expect(screen.getByText('person1')).toBeInTheDocument(); + expect(screen.getByText('person2')).toBeInTheDocument(); + expect(screen.getByText('triggered')).toBeInTheDocument(); + expect(screen.getByText('acknowledged')).toBeInTheDocument(); + expect(screen.getByTestId('chip-triggered')).toBeInTheDocument(); + expect(screen.getByTestId('chip-acknowledged')).toBeInTheDocument(); // assert links, mailto and hrefs, date calculation - expect(getAllByTitle('View in PagerDuty').length).toEqual(2); + expect(screen.getAllByTitle('View in PagerDuty').length).toEqual(2); }); it('Handle errors', async () => { @@ -111,16 +112,18 @@ describe('Incidents', () => { .fn() .mockRejectedValueOnce(new Error('Error occurred')); - const { getByText, queryByTestId } = render( + render( wrapInTestApp( , ), ); - await waitFor(() => !queryByTestId('progress')); + await waitFor(() => !screen.queryByTestId('progress')); expect( - getByText('Error encountered while fetching information. Error occurred'), + screen.getByText( + 'Error encountered while fetching information. Error occurred', + ), ).toBeInTheDocument(); }); }); diff --git a/plugins/playlist/src/components/CreatePlaylistButton/CreatePlaylistButton.test.tsx b/plugins/playlist/src/components/CreatePlaylistButton/CreatePlaylistButton.test.tsx index e00f7dc582..ef8ca57b69 100644 --- a/plugins/playlist/src/components/CreatePlaylistButton/CreatePlaylistButton.test.tsx +++ b/plugins/playlist/src/components/CreatePlaylistButton/CreatePlaylistButton.test.tsx @@ -26,7 +26,6 @@ import { fireEvent, waitFor } from '@testing-library/react'; import { act } from '@testing-library/react-hooks'; import React from 'react'; import { SWRConfig } from 'swr'; - import { PlaylistApi, playlistApiRef } from '../../api'; import { rootRouteRef } from '../../routes'; import { CreatePlaylistButton } from './CreatePlaylistButton'; @@ -103,7 +102,7 @@ describe('', () => { fireEvent.click(rendered.getByRole('button')); }); expect( - rendered.queryByTestId('mock-playlist-edit-dialog'), + rendered.getByTestId('mock-playlist-edit-dialog'), ).toBeInTheDocument(); }); diff --git a/plugins/playlist/src/components/EntityPlaylistDialog/EntityPlaylistDialog.test.tsx b/plugins/playlist/src/components/EntityPlaylistDialog/EntityPlaylistDialog.test.tsx index 9c61105ef9..1d9b298e19 100644 --- a/plugins/playlist/src/components/EntityPlaylistDialog/EntityPlaylistDialog.test.tsx +++ b/plugins/playlist/src/components/EntityPlaylistDialog/EntityPlaylistDialog.test.tsx @@ -28,7 +28,6 @@ import { fireEvent, getByRole, waitFor } from '@testing-library/react'; import { act } from '@testing-library/react-hooks'; import React from 'react'; import { SWRConfig } from 'swr'; - import { PlaylistApi, playlistApiRef } from '../../api'; import { rootRouteRef } from '../../routes'; import { EntityPlaylistDialog } from './EntityPlaylistDialog'; @@ -182,7 +181,7 @@ describe('EntityPlaylistDialog', () => { }); expect( - rendered.queryByTestId('mock-playlist-edit-dialog'), + rendered.getByTestId('mock-playlist-edit-dialog'), ).toBeInTheDocument(); act(() => { diff --git a/plugins/playlist/src/components/PersonalListPicker/PersonalListPicker.test.tsx b/plugins/playlist/src/components/PersonalListPicker/PersonalListPicker.test.tsx index 9255ee1bdb..b8ef0d9de0 100644 --- a/plugins/playlist/src/components/PersonalListPicker/PersonalListPicker.test.tsx +++ b/plugins/playlist/src/components/PersonalListPicker/PersonalListPicker.test.tsx @@ -24,7 +24,7 @@ import { } from '@backstage/core-plugin-api'; import { Playlist } from '@backstage/plugin-playlist-common'; import { MockStorageApi, TestApiRegistry } from '@backstage/test-utils'; -import { fireEvent, render, waitFor } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import React from 'react'; import { MockPlaylistListProvider } from '../../testUtils'; @@ -94,7 +94,7 @@ describe('', () => { }); it('renders filter groups', async () => { - const { queryByText } = render( + render( @@ -103,8 +103,8 @@ describe('', () => { ); await waitFor(() => { - expect(queryByText('Personal')).toBeInTheDocument(); - expect(queryByText('Test Company')).toBeInTheDocument(); + expect(screen.getByText('Personal')).toBeInTheDocument(); + expect(screen.getByText('Test Company')).toBeInTheDocument(); }); }); diff --git a/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx b/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx index f7720b25c1..21658ef36e 100644 --- a/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx +++ b/plugins/playlist/src/components/PlaylistPage/PlaylistEntitiesTable.test.tsx @@ -27,7 +27,6 @@ import { fireEvent, waitFor } from '@testing-library/react'; import { act } from '@testing-library/react-hooks'; import React from 'react'; import { SWRConfig } from 'swr'; - import { PlaylistApi, playlistApiRef } from '../../api'; import { PlaylistEntitiesTable } from './PlaylistEntitiesTable'; @@ -158,7 +157,7 @@ describe('PlaylistEntitiesTable', () => { }); expect( - rendered.queryByTestId('mock-add-entities-drawer'), + rendered.getByTestId('mock-add-entities-drawer'), ).toBeInTheDocument(); act(() => { diff --git a/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx b/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx index 39b051140e..4594a43a88 100644 --- a/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx +++ b/plugins/playlist/src/components/PlaylistPage/PlaylistHeader.test.tsx @@ -31,7 +31,6 @@ import { fireEvent, waitFor } from '@testing-library/react'; import { act } from '@testing-library/react-hooks'; import React from 'react'; import { SWRConfig } from 'swr'; - import { PlaylistApi, playlistApiRef } from '../../api'; import { rootRouteRef } from '../../routes'; import { PlaylistHeader } from './PlaylistHeader'; @@ -122,7 +121,7 @@ describe('PlaylistHeader', () => { testPlaylist.public = false; rendered.rerender(element); - expect(rendered.queryByText('private')).toBeInTheDocument(); + expect(rendered.getByText('private')).toBeInTheDocument(); }); it('has edit and delete options enabled if authorized', async () => { @@ -202,7 +201,7 @@ describe('PlaylistHeader', () => { }); expect( - rendered.queryByTestId('mock-playlist-edit-dialog'), + rendered.getByTestId('mock-playlist-edit-dialog'), ).toBeInTheDocument(); act(() => { diff --git a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx index 40683f01ba..8e2184edf1 100644 --- a/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx +++ b/plugins/scaffolder/src/components/ActionsPage/ActionsPage.test.tsx @@ -65,9 +65,9 @@ describe('TemplatePage', () => { }, }, ); - expect(rendered.queryByText('Test title')).toBeInTheDocument(); - expect(rendered.queryByText('example description')).toBeInTheDocument(); - expect(rendered.queryByText('foobar')).toBeInTheDocument(); + expect(rendered.getByText('Test title')).toBeInTheDocument(); + expect(rendered.getByText('example description')).toBeInTheDocument(); + expect(rendered.getByText('foobar')).toBeInTheDocument(); expect(rendered.queryByText('output')).not.toBeInTheDocument(); }); @@ -109,10 +109,10 @@ describe('TemplatePage', () => { }, }, ); - expect(rendered.queryByText('Test title')).toBeInTheDocument(); - expect(rendered.queryByText('example description')).toBeInTheDocument(); - expect(rendered.queryByText('foobar')).toBeInTheDocument(); - expect(rendered.queryByText('Test output')).toBeInTheDocument(); + expect(rendered.getByText('Test title')).toBeInTheDocument(); + expect(rendered.getByText('example description')).toBeInTheDocument(); + expect(rendered.getByText('foobar')).toBeInTheDocument(); + expect(rendered.getByText('Test output')).toBeInTheDocument(); }); it('renders action with oneOf input', async () => { @@ -160,10 +160,10 @@ describe('TemplatePage', () => { }, }, ); - expect(rendered.queryByText('oneOf')).toBeInTheDocument(); - expect(rendered.queryByText('Foo title')).toBeInTheDocument(); - expect(rendered.queryByText('Foo description')).toBeInTheDocument(); - expect(rendered.queryByText('Bar title')).toBeInTheDocument(); - expect(rendered.queryByText('Bar description')).toBeInTheDocument(); + expect(rendered.getByText('oneOf')).toBeInTheDocument(); + expect(rendered.getByText('Foo title')).toBeInTheDocument(); + expect(rendered.getByText('Foo description')).toBeInTheDocument(); + expect(rendered.getByText('Bar title')).toBeInTheDocument(); + expect(rendered.getByText('Bar description')).toBeInTheDocument(); }); }); diff --git a/plugins/scaffolder/src/components/ScaffolderPage/ScaffolderPageContextMenu.test.tsx b/plugins/scaffolder/src/components/ScaffolderPage/ScaffolderPageContextMenu.test.tsx index 2d07416025..02869bb6da 100644 --- a/plugins/scaffolder/src/components/ScaffolderPage/ScaffolderPageContextMenu.test.tsx +++ b/plugins/scaffolder/src/components/ScaffolderPage/ScaffolderPageContextMenu.test.tsx @@ -45,7 +45,7 @@ describe('ScaffolderPageContextMenu', () => { await userEvent.click(screen.getByTestId('container').firstElementChild!); - expect(screen.queryByText('Template Editor')).toBeInTheDocument(); + expect(screen.getByText('Template Editor')).toBeInTheDocument(); expect(screen.queryByText('Installed Actions')).not.toBeInTheDocument(); }); @@ -62,7 +62,7 @@ describe('ScaffolderPageContextMenu', () => { await userEvent.click(screen.getByTestId('container').firstElementChild!); expect(screen.queryByText('Template Editor')).not.toBeInTheDocument(); - expect(screen.queryByText('Installed Actions')).toBeInTheDocument(); + expect(screen.getByText('Installed Actions')).toBeInTheDocument(); }); it('renders all options', async () => { @@ -77,7 +77,7 @@ describe('ScaffolderPageContextMenu', () => { await userEvent.click(screen.getByTestId('container').firstElementChild!); - expect(screen.queryByText('Template Editor')).toBeInTheDocument(); - expect(screen.queryByText('Installed Actions')).toBeInTheDocument(); + expect(screen.getByText('Template Editor')).toBeInTheDocument(); + expect(screen.getByText('Installed Actions')).toBeInTheDocument(); }); }); diff --git a/plugins/scaffolder/src/components/TaskPage/IconLink.test.tsx b/plugins/scaffolder/src/components/TaskPage/IconLink.test.tsx index 9c1b021071..f7ce850cd8 100644 --- a/plugins/scaffolder/src/components/TaskPage/IconLink.test.tsx +++ b/plugins/scaffolder/src/components/TaskPage/IconLink.test.tsx @@ -33,6 +33,6 @@ describe('IconLink', () => { , ); - expect(rendered.queryByText('I am Link')).toBeInTheDocument(); + expect(rendered.getByText('I am Link')).toBeInTheDocument(); }); }); diff --git a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.test.tsx b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.test.tsx index 65eb59c84a..417c23c483 100644 --- a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.test.tsx +++ b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.test.tsx @@ -70,7 +70,7 @@ describe('DryRunResultsList', () => { , ); - expect(screen.queryByText('Result 1')).toBeInTheDocument(); + expect(screen.getByText('Result 1')).toBeInTheDocument(); expect(screen.queryByText('Result 2')).not.toBeInTheDocument(); await act(async () => { @@ -84,12 +84,12 @@ describe('DryRunResultsList', () => { ); }); - expect(screen.queryByText('Result 1')).toBeInTheDocument(); - expect(screen.queryByText('Result 2')).toBeInTheDocument(); + expect(screen.getByText('Result 1')).toBeInTheDocument(); + expect(screen.getByText('Result 2')).toBeInTheDocument(); await userEvent.click(screen.getAllByLabelText('delete')[0]); expect(screen.queryByText('Result 1')).not.toBeInTheDocument(); - expect(screen.queryByText('Result 2')).toBeInTheDocument(); + expect(screen.getByText('Result 2')).toBeInTheDocument(); }); }); diff --git a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx index 71f5ffad47..5b16c21364 100644 --- a/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx +++ b/plugins/scaffolder/src/components/TemplatePage/TemplatePage.test.tsx @@ -19,7 +19,7 @@ import { renderInTestApp, TestApiRegistry, } from '@backstage/test-utils'; -import { act, fireEvent, within } from '@testing-library/react'; +import { act, fireEvent, screen, within } from '@testing-library/react'; import React from 'react'; import { Route, Routes } from 'react-router'; import { scaffolderApiRef } from '../../api'; @@ -31,7 +31,6 @@ import { FeatureFlagsApi, analyticsApiRef, } from '@backstage/core-plugin-api'; - import { ApiProvider } from '@backstage/core-app-api'; import { errorApiRef } from '@backstage/core-plugin-api'; @@ -135,8 +134,8 @@ describe('TemplatePage', () => { }, ); - expect(rendered.queryByText('Create a New Component')).toBeInTheDocument(); - expect(rendered.queryByText('React SSR Template')).toBeInTheDocument(); + expect(rendered.getByText('Create a New Component')).toBeInTheDocument(); + expect(rendered.getByText('React SSR Template')).toBeInTheDocument(); }); it('renders spinner while loading', async () => { @@ -156,8 +155,8 @@ describe('TemplatePage', () => { }, ); - expect(rendered.queryByText('Create a New Component')).toBeInTheDocument(); - expect(rendered.queryByTestId('loading-progress')).toBeInTheDocument(); + expect(rendered.getByText('Create a New Component')).toBeInTheDocument(); + expect(rendered.getByTestId('loading-progress')).toBeInTheDocument(); await act(async () => { resolve!({ @@ -248,7 +247,7 @@ describe('TemplatePage', () => { expect( rendered.queryByText('Create a New Component'), ).not.toBeInTheDocument(); - expect(rendered.queryByText('This is root')).toBeInTheDocument(); + expect(rendered.getByText('This is root')).toBeInTheDocument(); }); it('display template with oneOf', async () => { @@ -330,7 +329,7 @@ describe('TemplatePage', () => { schemaMockValue, ); - const { queryByText } = await renderInTestApp( + await renderInTestApp( , @@ -341,9 +340,9 @@ describe('TemplatePage', () => { }, ); - expect(queryByText('Name')).not.toBeInTheDocument(); - expect(queryByText('Description')).toBeInTheDocument(); - expect(queryByText('Owner')).toBeInTheDocument(); - expect(queryByText('Send data')).toBeInTheDocument(); + expect(screen.queryByText('Name')).not.toBeInTheDocument(); + expect(screen.getByText('Description')).toBeInTheDocument(); + expect(screen.getByText('Owner')).toBeInTheDocument(); + expect(screen.getByText('Send data')).toBeInTheDocument(); }); }); diff --git a/plugins/scaffolder/src/next/TemplateListPage/RegisterExistingButton.test.tsx b/plugins/scaffolder/src/next/TemplateListPage/RegisterExistingButton.test.tsx index a8e377bd3d..3c2807c4c8 100644 --- a/plugins/scaffolder/src/next/TemplateListPage/RegisterExistingButton.test.tsx +++ b/plugins/scaffolder/src/next/TemplateListPage/RegisterExistingButton.test.tsx @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +import { screen } from '@testing-library/react'; import { renderInTestApp } from '@backstage/test-utils'; import React from 'react'; import { RegisterExistingButton } from './RegisterExistingButton'; @@ -30,28 +32,22 @@ describe('RegisterExistingButton', () => { it('should not render if to is unset', async () => { (usePermission as jest.Mock).mockReturnValue({ allowed: true }); - const { queryByText } = await renderInTestApp( - , - ); + await renderInTestApp(); - expect(queryByText('Pick me')).not.toBeInTheDocument(); + expect(screen.queryByText('Pick me')).not.toBeInTheDocument(); }); it('should not render if permissions are not allowed', async () => { (usePermission as jest.Mock).mockReturnValue({ allowed: false }); - const { queryByText } = await renderInTestApp( - , - ); + await renderInTestApp(); - expect(queryByText('Pick me')).not.toBeInTheDocument(); + expect(screen.queryByText('Pick me')).not.toBeInTheDocument(); }); it('should render the button with the text', async () => { (usePermission as jest.Mock).mockReturnValue({ allowed: true }); - const { queryByText } = await renderInTestApp( - , - ); + await renderInTestApp(); - expect(queryByText('Pick me')).toBeInTheDocument(); + expect(screen.getByText('Pick me')).toBeInTheDocument(); }); }); diff --git a/plugins/techdocs/src/home/components/Grids/EntityListDocsGrid.test.tsx b/plugins/techdocs/src/home/components/Grids/EntityListDocsGrid.test.tsx index 2837ab340a..acaf01b318 100644 --- a/plugins/techdocs/src/home/components/Grids/EntityListDocsGrid.test.tsx +++ b/plugins/techdocs/src/home/components/Grids/EntityListDocsGrid.test.tsx @@ -103,9 +103,9 @@ describe('Entity List Docs Grid', () => { }, ); - expect(screen.queryByText('All Documentation')).toBeInTheDocument(); - expect(screen.queryByText('Documentation #1')).toBeInTheDocument(); - expect(screen.queryByText('Documentation #2')).toBeInTheDocument(); + expect(screen.getByText('All Documentation')).toBeInTheDocument(); + expect(screen.getByText('Documentation #1')).toBeInTheDocument(); + expect(screen.getByText('Documentation #2')).toBeInTheDocument(); expect(screen.queryByTestId('doc-not-found')).not.toBeInTheDocument(); }); @@ -131,8 +131,8 @@ describe('Entity List Docs Grid', () => { }, ); - expect(screen.queryByText('Curated Documentation')).toBeInTheDocument(); - expect(screen.queryByText('Documentation #1')).toBeInTheDocument(); + expect(screen.getByText('Curated Documentation')).toBeInTheDocument(); + expect(screen.getByText('Documentation #1')).toBeInTheDocument(); expect(screen.queryByText('Documentation #2')).not.toBeInTheDocument(); expect(screen.queryByTestId('doc-not-found')).not.toBeInTheDocument(); }); @@ -182,6 +182,6 @@ describe('Entity List Docs Grid', () => { expect(screen.queryByText('All Documentation')).not.toBeInTheDocument(); expect(screen.queryByText('Documentation #1')).not.toBeInTheDocument(); expect(screen.queryByText('Documentation #2')).not.toBeInTheDocument(); - expect(screen.queryByTestId('doc-not-found')).toBeInTheDocument(); + expect(screen.getByTestId('doc-not-found')).toBeInTheDocument(); }); });