Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix act errors in FaveStar test #21360

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions superset-frontend/src/components/FaveStar/FaveStar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jest.mock('src/components/Tooltip', () => ({
Tooltip: (props: any) => <div data-test="tooltip" {...props} />,
}));

test('render right content', () => {
test('render right content', async () => {
const props = {
itemId: 3,
saveFaveStar: jest.fn(),
};

const { rerender } = render(<FaveStar {...props} isStarred />);
const { rerender, findByRole } = render(<FaveStar {...props} isStarred />);
expect(screen.getByRole('button')).toBeInTheDocument();
expect(
screen.getByRole('img', { name: 'favorite-selected' }),
Expand All @@ -45,7 +45,7 @@ test('render right content', () => {

rerender(<FaveStar {...props} />);
expect(
screen.getByRole('img', { name: 'favorite-unselected' }),
await findByRole('img', { name: 'favorite-unselected' }),
).toBeInTheDocument();

expect(props.saveFaveStar).toBeCalledTimes(1);
Expand All @@ -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,
Expand All @@ -63,7 +63,7 @@ test('render content on tooltip', () => {

render(<FaveStar {...props} />);

expect(screen.getByTestId('tooltip')).toBeInTheDocument();
expect(await screen.findByTestId('tooltip')).toBeInTheDocument();
expect(screen.getByTestId('tooltip')).toHaveAttribute(
'id',
'fave-unfave-tooltip',
Expand All @@ -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(),
Expand All @@ -84,7 +84,10 @@ test('Call fetchFaveStar only on the first render', () => {
showTooltip: false,
};

const { rerender } = render(<FaveStar {...props} />);
const { rerender, findByRole } = render(<FaveStar {...props} />);
expect(
await findByRole('img', { name: 'favorite-unselected' }),
).toBeInTheDocument();
expect(props.fetchFaveStar).toBeCalledTimes(1);
expect(props.fetchFaveStar).toBeCalledWith(props.itemId);

Expand Down