Update test mocks

Fix lint
This commit is contained in:
Chi-Hsuan Huang 2022-03-21 18:32:40 +08:00
parent 8ce25e6b1b
commit 3dc5f95254
4 changed files with 46 additions and 11 deletions

View File

@ -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(),

View File

@ -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(),
} ),
};
} );

View File

@ -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: {

View File

@ -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' );