From 81f6542b7427247b0f0c2987e1024ceee5db689a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 31 Jan 2023 14:58:26 +0100 Subject: [PATCH] await expect instead of expect await MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../apis/StarredEntitiesApi/migration.test.ts | 4 ++-- .../CatalogPage/DefaultCatalogPage.test.tsx | 24 +++++++++++-------- .../CatalogTable/CatalogTable.test.tsx | 8 +++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/plugins/catalog/src/apis/StarredEntitiesApi/migration.test.ts b/plugins/catalog/src/apis/StarredEntitiesApi/migration.test.ts index b3bc5400d5..7e5ad3f2f7 100644 --- a/plugins/catalog/src/apis/StarredEntitiesApi/migration.test.ts +++ b/plugins/catalog/src/apis/StarredEntitiesApi/migration.test.ts @@ -46,7 +46,7 @@ describe('performMigrationToTheNewBucket', () => { await performMigrationToTheNewBucket({ storageApi: mockStorage }); // read NEW bucket - expect(await newBucket.snapshot('entityRefs').value).toEqual([ + await expect(newBucket.snapshot('entityRefs').value).resolves.toEqual([ 'component:default/c', 'component:default/a', 'template:custom/b', @@ -72,7 +72,7 @@ describe('performMigrationToTheNewBucket', () => { await performMigrationToTheNewBucket({ storageApi: mockStorage }); // read NEW bucket - expect(await newBucket.snapshot('entityRefs').value).toEqual([ + await expect(newBucket.snapshot('entityRefs').value).resolves.toEqual([ 'component:default/a', ]); diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx index a2b26b87e1..10f06ca09e 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx @@ -198,10 +198,12 @@ describe('DefaultCatalogPage', () => { it('should render the default actions of an item in the grid', async () => { await renderWrapped(); fireEvent.click(screen.getByTestId('user-picker-owned')); - expect(await screen.findByText(/Owned \(1\)/)).toBeInTheDocument(); - expect(await screen.findByTitle(/View/)).toBeInTheDocument(); - expect(await screen.findByTitle(/Edit/)).toBeInTheDocument(); - expect(await screen.findByTitle(/Add to favorites/)).toBeInTheDocument(); + await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument(); + await expect(screen.findByTitle(/View/)).resolves.toBeInTheDocument(); + await expect(screen.findByTitle(/Edit/)).resolves.toBeInTheDocument(); + await expect( + screen.findByTitle(/Add to favorites/), + ).resolves.toBeInTheDocument(); }, 20_000); it('should render the custom actions of an item passed as prop', async () => { @@ -226,10 +228,12 @@ describe('DefaultCatalogPage', () => { await renderWrapped(); fireEvent.click(screen.getByTestId('user-picker-owned')); - expect(await screen.findByText(/Owned \(1\)/)).toBeInTheDocument(); - expect(await screen.findByTitle(/Foo Action/)).toBeInTheDocument(); - expect(await screen.findByTitle(/Bar Action/)).toBeInTheDocument(); - expect((await screen.findByTitle(/Bar Action/)).firstChild).toBeDisabled(); + await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument(); + await expect(screen.findByTitle(/Foo Action/)).resolves.toBeInTheDocument(); + await expect(screen.findByTitle(/Bar Action/)).resolves.toBeInTheDocument(); + await expect( + screen.findByTitle(/Bar Action/).then(e => e.firstChild), + ).resolves.toBeDisabled(); }, 20_000); // this test right now causes some red lines in the log output when running tests @@ -256,7 +260,7 @@ describe('DefaultCatalogPage', () => { await expect(screen.findByText(/Owned \(1\)/)).resolves.toBeInTheDocument(); // The "Starred" menu option should initially be disabled, since there // aren't any starred entities. - await expect(screen.getByTestId('user-picker-starred')).toHaveAttribute( + expect(screen.getByTestId('user-picker-starred')).toHaveAttribute( 'aria-disabled', 'true', ); @@ -269,7 +273,7 @@ describe('DefaultCatalogPage', () => { // Now that we've starred an entity, the "Starred" menu option should be // enabled. - await expect(screen.getByTestId('user-picker-starred')).not.toHaveAttribute( + expect(screen.getByTestId('user-picker-starred')).not.toHaveAttribute( 'aria-disabled', 'true', ); diff --git a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx index 652c9f3873..f8a655413e 100644 --- a/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx +++ b/plugins/catalog/src/components/CatalogTable/CatalogTable.test.tsx @@ -78,10 +78,9 @@ describe('CatalogTable component', () => { }, }, ); - const errorMessage = await screen.findByText( - /Could not fetch catalog entities./, - ); - expect(errorMessage).toBeInTheDocument(); + await expect( + screen.findByText(/Could not fetch catalog entities./), + ).resolves.toBeInTheDocument(); }); it('should display entity names when loading has finished and no error occurred', async () => { @@ -306,6 +305,7 @@ describe('CatalogTable component', () => { }, 20_000, ); + it('should render the subtitle when it is specified', async () => { const entity = { apiVersion: 'backstage.io/v1alpha1',