diff --git a/__mocks__/@wordpress/api-fetch/index.js b/__mocks__/@wordpress/api-fetch/index.js deleted file mode 100644 index d50cbe08b867c4..00000000000000 --- a/__mocks__/@wordpress/api-fetch/index.js +++ /dev/null @@ -1,6 +0,0 @@ -const apiFetch = jest.fn( () => { - return apiFetch.mockReturnValue; -} ); -apiFetch.mockReturnValue = 'Mock this value by overriding apiFetch.mockReturnValue.'; - -export default apiFetch; diff --git a/packages/components/src/higher-order/with-api-data/test/request.js b/packages/components/src/higher-order/with-api-data/test/request.js index 4a8798d5625e05..1a8d7e27f39072 100644 --- a/packages/components/src/higher-order/with-api-data/test/request.js +++ b/packages/components/src/higher-order/with-api-data/test/request.js @@ -14,7 +14,7 @@ import request, { isRequestMethod, } from '../request'; -jest.mock( '@wordpress/api-fetch' ); +jest.mock( '@wordpress/api-fetch', () => jest.fn() ); describe( 'request', () => { const actualResponse = { @@ -31,13 +31,7 @@ describe( 'request', () => { delete cache[ key ]; } - apiFetch.mockReturnValue = { - // jQuery.Deferred aren't true promises, particularly in their - // treatment of resolved arguments. $.ajax will spread resolved - // arguments, but this is not valid for Promise (only single). - // Instead, we emulate by invoking the callback manually. - then: ( callback ) => Promise.resolve( callback( actualResponse ) ), - }; + apiFetch.mockImplementation( () => Promise.resolve( actualResponse ) ); } ); describe( 'getCachedResponse()', () => { diff --git a/packages/core-data/src/test/entities.js b/packages/core-data/src/test/entities.js index 7d22393280b6ac..e8a84dd965cdcd 100644 --- a/packages/core-data/src/test/entities.js +++ b/packages/core-data/src/test/entities.js @@ -9,7 +9,7 @@ import apiFetch from '@wordpress/api-fetch'; import { getMethodName, defaultEntities, getKindEntities } from '../entities'; import { addEntities } from '../actions'; -jest.mock( '@wordpress/api-fetch' ); +jest.mock( '@wordpress/api-fetch', () => jest.fn() ); describe( 'getMethodName', () => { it( 'should return the right method name for an entity with the root kind', () => { diff --git a/packages/core-data/src/test/resolvers.js b/packages/core-data/src/test/resolvers.js index 29f0cf68bf2712..c721f1ddd895ea 100644 --- a/packages/core-data/src/test/resolvers.js +++ b/packages/core-data/src/test/resolvers.js @@ -9,7 +9,7 @@ import apiFetch from '@wordpress/api-fetch'; import { getCategories, getEntityRecord, getEntityRecords } from '../resolvers'; import { receiveTerms, receiveEntityRecords, addEntities } from '../actions'; -jest.mock( '@wordpress/api-fetch' ); +jest.mock( '@wordpress/api-fetch', () => jest.fn() ); describe( 'getCategories', () => { const CATEGORIES = [ { id: 1 } ]; diff --git a/packages/editor/src/store/effects/test/reusable-blocks.js b/packages/editor/src/store/effects/test/reusable-blocks.js index c58fd050e15854..2ff4081a650a79 100644 --- a/packages/editor/src/store/effects/test/reusable-blocks.js +++ b/packages/editor/src/store/effects/test/reusable-blocks.js @@ -38,6 +38,8 @@ import { } from '../../actions'; import reducer from '../../reducer'; +jest.mock( '@wordpress/api-fetch', () => jest.fn() ); + describe( 'reusable blocks effects', () => { beforeAll( () => { registerBlockType( 'core/test-block', {