From fd6569e3ed4c5322942c7dc67118c2695e3d0a43 Mon Sep 17 00:00:00 2001
From: Lyndsi Kay Williams <55605634+lyndsiWilliams@users.noreply.github.com>
Date: Thu, 8 Sep 2022 05:47:43 -0500
Subject: [PATCH] test: Fix act errors in FaveStar test (#21360)
---
.../src/components/FaveStar/FaveStar.test.tsx | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/superset-frontend/src/components/FaveStar/FaveStar.test.tsx b/superset-frontend/src/components/FaveStar/FaveStar.test.tsx
index 68433db96ea4e..ab2fa9fa0ed1e 100644
--- a/superset-frontend/src/components/FaveStar/FaveStar.test.tsx
+++ b/superset-frontend/src/components/FaveStar/FaveStar.test.tsx
@@ -26,13 +26,13 @@ jest.mock('src/components/Tooltip', () => ({
Tooltip: (props: any) =>
,
}));
-test('render right content', () => {
+test('render right content', async () => {
const props = {
itemId: 3,
saveFaveStar: jest.fn(),
};
- const { rerender } = render();
+ const { rerender, findByRole } = render();
expect(screen.getByRole('button')).toBeInTheDocument();
expect(
screen.getByRole('img', { name: 'favorite-selected' }),
@@ -45,7 +45,7 @@ test('render right content', () => {
rerender();
expect(
- screen.getByRole('img', { name: 'favorite-unselected' }),
+ await findByRole('img', { name: 'favorite-unselected' }),
).toBeInTheDocument();
expect(props.saveFaveStar).toBeCalledTimes(1);
@@ -54,7 +54,7 @@ test('render right content', () => {
expect(props.saveFaveStar).toBeCalledWith(props.itemId, false);
});
-test('render content on tooltip', () => {
+test('render content on tooltip', async () => {
const props = {
itemId: 3,
showTooltip: true,
@@ -63,7 +63,7 @@ test('render content on tooltip', () => {
render();
- expect(screen.getByTestId('tooltip')).toBeInTheDocument();
+ expect(await screen.findByTestId('tooltip')).toBeInTheDocument();
expect(screen.getByTestId('tooltip')).toHaveAttribute(
'id',
'fave-unfave-tooltip',
@@ -75,7 +75,7 @@ test('render content on tooltip', () => {
expect(screen.getByRole('button')).toBeInTheDocument();
});
-test('Call fetchFaveStar only on the first render', () => {
+test('Call fetchFaveStar only on the first render', async () => {
const props = {
itemId: 3,
fetchFaveStar: jest.fn(),
@@ -84,7 +84,10 @@ test('Call fetchFaveStar only on the first render', () => {
showTooltip: false,
};
- const { rerender } = render();
+ const { rerender, findByRole } = render();
+ expect(
+ await findByRole('img', { name: 'favorite-unselected' }),
+ ).toBeInTheDocument();
expect(props.fetchFaveStar).toBeCalledTimes(1);
expect(props.fetchFaveStar).toBeCalledWith(props.itemId);