Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Try preventing navigation in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed May 31, 2023
1 parent ab0c824 commit 9557d04
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe( 'Proceed to checkout block', () => {
expect( console ).toHaveErrored();
} );
it( 'dispatches the onProceedToCheckout event when the button is clicked', async () => {
const mockObserver = jest.fn();
const mockObserver = jest.fn().mockReturnValue( { type: 'error' } );
const MockObserverComponent = () => {
const { onProceedToCheckout } = useCartEventsContext();
useEffect( () => {
Expand All @@ -77,6 +77,10 @@ describe( 'Proceed to checkout block', () => {
);
expect( screen.getByText( 'Mock observer' ) ).toBeInTheDocument();
const button = screen.getByText( 'Proceed to Checkout' );

// Forcibly set the button URL to # to prevent JSDOM error: `["Error: Not implemented: navigation (except hash changes)`
button.parentElement?.removeAttribute( 'href' );

button.click();
await waitFor( () => {
expect( mockObserver ).toHaveBeenCalled();
Expand Down

0 comments on commit 9557d04

Please sign in to comment.