diff --git a/plugins/woocommerce-admin/client/layout/transient-notices/test/index.js b/plugins/woocommerce-admin/client/layout/transient-notices/test/index.js index 63ebbe857d3..99f52f5087c 100644 --- a/plugins/woocommerce-admin/client/layout/transient-notices/test/index.js +++ b/plugins/woocommerce-admin/client/layout/transient-notices/test/index.js @@ -9,7 +9,17 @@ import { useSelect, useDispatch } from '@wordpress/data'; */ import TransientNotices from '..'; -jest.mock( '@wordpress/data' ); +jest.mock( '@wordpress/data', () => { + // Require the original module to not be mocked... + const originalModule = jest.requireActual( '@wordpress/data' ); + + return { + __esModule: true, // Use it when dealing with esModules + ...originalModule, + useDispatch: jest.fn(), + useSelect: jest.fn().mockReturnValue( {} ), + }; +} ); useDispatch.mockReturnValue( { removeNotice: jest.fn(), diff --git a/plugins/woocommerce-admin/client/tasks/test/task-list-item.test.tsx b/plugins/woocommerce-admin/client/tasks/test/task-list-item.test.tsx index 0d0ec5f14ab..ef9d34d7e18 100644 --- a/plugins/woocommerce-admin/client/tasks/test/task-list-item.test.tsx +++ b/plugins/woocommerce-admin/client/tasks/test/task-list-item.test.tsx @@ -17,10 +17,6 @@ jest.mock( '@wordpress/data', () => { return { ...originalModule, useDispatch: jest.fn(), - // Mock dispatch to avoid errors for @wordpress/viewport listener. - dispatch: jest.fn().mockReturnValue( { - setIsMatching: jest.fn(), - } ), }; } ); diff --git a/plugins/woocommerce-admin/client/tasks/test/task.test.tsx b/plugins/woocommerce-admin/client/tasks/test/task.test.tsx index cd180624b09..118f2591c98 100644 --- a/plugins/woocommerce-admin/client/tasks/test/task.test.tsx +++ b/plugins/woocommerce-admin/client/tasks/test/task.test.tsx @@ -12,12 +12,30 @@ import { WooOnboardingTask } from '@woocommerce/onboarding'; */ import { Task } from '../task'; -jest.mock( '@wordpress/data' ); +jest.mock( '@wordpress/data', () => { + // Require the original module to not be mocked... + const originalModule = jest.requireActual( '@wordpress/data' ); -jest.mock( '@woocommerce/navigation', () => ( { - getHistory: jest.fn(), - getNewPath: () => 'new-path', -} ) ); + return { + __esModule: true, // Use it when dealing with esModules + ...originalModule, + useDispatch: jest.fn(), + useSelect: jest.fn().mockReturnValue( {} ), + }; +} ); + +jest.mock( '@woocommerce/navigation', () => { + // Require the original module to not be mocked... + const originalModule = jest.requireActual( '@woocommerce/navigation' ); + + return { + __esModule: true, // Use it when dealing with esModules + ...originalModule, + getPersistedQuery: jest.fn().mockReturnValue( {} ), + getHistory: jest.fn(), + getNewPath: () => 'new-path', + }; +} ); jest.mock( '@woocommerce/onboarding', () => ( { WooOnboardingTask: { diff --git a/plugins/woocommerce-admin/client/tasks/test/tasks.test.tsx b/plugins/woocommerce-admin/client/tasks/test/tasks.test.tsx index d51520b2d8f..68284a4172e 100644 --- a/plugins/woocommerce-admin/client/tasks/test/tasks.test.tsx +++ b/plugins/woocommerce-admin/client/tasks/test/tasks.test.tsx @@ -12,7 +12,18 @@ import userEvent from '@testing-library/user-event'; */ import { Tasks } from '../tasks'; -jest.mock( '@wordpress/data' ); +jest.mock( '@wordpress/data', () => { + // Require the original module to not be mocked... + const originalModule = jest.requireActual( '@wordpress/data' ); + + return { + __esModule: true, // Use it when dealing with esModules + ...originalModule, + useDispatch: jest.fn().mockReturnValue( {} ), + useSelect: jest.fn().mockReturnValue( {} ), + }; +} ); + jest.mock( '@woocommerce/explat' ); jest.mock( '@woocommerce/tracks' );