Skip to content

Commit

Permalink
Check if the the request hasn't started (#92665)
Browse files Browse the repository at this point in the history
It was not enough to check isPending, because isIdle is the status that we have before performing the request. Here, isPending is false, so it lets us to render component. That resulted in flakiness in the component and tests' behaviours.
  • Loading branch information
merkushin authored Jul 14, 2024
1 parent 15d1f1f commit 330352e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions client/blocks/importer/wordpress/upgrade-plan/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ describe( 'UpgradePlan', () => {
it( 'should call onCtaClick when the user clicks on the Continue button', async () => {
const mockOnCtaClick = jest.fn();

renderUpgradePlanComponent( getUpgradePlanProps( { onCtaClick: mockOnCtaClick } ) );
renderUpgradePlanComponent(
getUpgradePlanProps( { onCtaClick: mockOnCtaClick } ),
UnwrappedUpgradePlan
);

await userEvent.click( screen.getByRole( 'button', { name: /Continue/ } ) );

Expand All @@ -183,7 +186,8 @@ describe( 'UpgradePlan', () => {
const mockOnCtaClick = jest.fn();

renderUpgradePlanComponent(
getUpgradePlanProps( { ctaText: 'My Custom CTA', onCtaClick: mockOnCtaClick } )
getUpgradePlanProps( { ctaText: 'My Custom CTA', onCtaClick: mockOnCtaClick } ),
UnwrappedUpgradePlan
);

await userEvent.click( screen.getByRole( 'button', { name: /My Custom CTA/ } ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const withMigrationSticker =

const {
addMigrationSticker,
addMutationRest: { isPending },
addMutationRest: { isIdle, isPending },
deleteMigrationSticker,
} = useMigrationStickerMutation();

Expand All @@ -32,7 +32,7 @@ const withMigrationSticker =
};
}, [ addMigrationSticker, deleteMigrationSticker, siteId ] );

if ( isPending ) {
if ( isIdle || isPending ) {
return <Skeleton />;
}

Expand Down

0 comments on commit 330352e

Please sign in to comment.