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

Commit

Permalink
Mock data.dispatch for task-list-item.test.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
chihsuan committed Feb 17, 2022
1 parent 37ca4a5 commit 2b03298
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/tasks/test/task-list-item.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import { act, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { WooOnboardingTaskListItem } from '@woocommerce/onboarding';
import { SlotFillProvider } from '@wordpress/components';
import { useDispatch } from '@wordpress/data';
import { useSlot } from '@woocommerce/experimental';
Expand All @@ -13,7 +12,17 @@ import { useSlot } from '@woocommerce/experimental';
*/
import { TaskListItem } from '../task-list-item';

jest.mock( '@wordpress/data' );
jest.mock( '@wordpress/data', () => {
const originalModule = jest.requireActual( '@wordpress/data' );
return {
...originalModule,
useDispatch: jest.fn(),
// Mock dispatch to avoid errors for @wordpress/viewport listener.
dispatch: jest.fn().mockReturnValue( {
setIsMatching: jest.fn(),
} ),
};
} );

const mockDispatch = {
createNotice: jest.fn(),
Expand Down

0 comments on commit 2b03298

Please sign in to comment.