diff --git a/packages/core/src/data/strategies/SinglePostFetchStrategy.ts b/packages/core/src/data/strategies/SinglePostFetchStrategy.ts index fe36bf9d4..5ba018529 100644 --- a/packages/core/src/data/strategies/SinglePostFetchStrategy.ts +++ b/packages/core/src/data/strategies/SinglePostFetchStrategy.ts @@ -249,7 +249,7 @@ export class SinglePostFetchStrategy< if (!post) { throw new NotFoundError( - `Post was found but did not match current path: "${this.path}""`, + `Post #${result[0].id} - "${result[0].link}" was found but did not match current path: "${this.path}""`, ); } diff --git a/packages/core/src/data/strategies/__tests__/PostOrPostsFetchStrategy.ts b/packages/core/src/data/strategies/__tests__/PostOrPostsFetchStrategy.ts index 9d12a92a3..2af7cb18d 100644 --- a/packages/core/src/data/strategies/__tests__/PostOrPostsFetchStrategy.ts +++ b/packages/core/src/data/strategies/__tests__/PostOrPostsFetchStrategy.ts @@ -183,7 +183,7 @@ describe('PostOrPostsFetchStrategy', () => { ); await expect(() => fetchStrategy.fetcher('', params)).rejects.toThrow( - 'Neither single or archive returned data: The request to /wp-json/wp/v2/posts?_embed=true&categories=distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam returned no data, Post was found but did not match current path: "/uncategorized/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam"', + 'Neither single or archive returned data: The request to /wp-json/wp/v2/posts?_embed=true&categories=distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam returned no data, Post #54 - "https://js1.10up.com/2020/05/07/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam/" was found but did not match current path: "/uncategorized/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam"', ); // now make it work by faking full path diff --git a/packages/core/src/react/hooks/__tests__/useFetchPost.tsx b/packages/core/src/react/hooks/__tests__/useFetchPost.tsx index cb089a064..bde415af9 100644 --- a/packages/core/src/react/hooks/__tests__/useFetchPost.tsx +++ b/packages/core/src/react/hooks/__tests__/useFetchPost.tsx @@ -1,6 +1,7 @@ import { renderHook, waitFor } from '@testing-library/react'; import * as React from 'react'; import { expectTypeOf } from 'expect-type'; +import { SWRConfig } from 'swr'; import { DRAFT_POST_ID, VALID_AUTH_TOKEN } from '../../../../test/server'; import { PostEntity, PostParams } from '../../../data'; import { SettingsProvider } from '../../provider'; @@ -10,7 +11,11 @@ import { mockUseFetchErrorResponse } from '../mocks'; describe('useFetchPost', () => { const wrapper = ({ children }) => { - return {children}; + return ( + new Map() }}> + {children} + + ); }; it('throws errors if accessing data before fetch', async () => { @@ -185,7 +190,15 @@ describe('useFetchPost', () => { it('reads param from the url and sets isMainQuery flag', async () => { const { result } = renderHook( - () => useFetchPost({}, {}, '/modi-qui-dignissimos-sed-assumenda-sint-iusto'), + () => + useFetchPost( + { + fullPath: + 'https://js1.10up.com/2020/05/07/modi-qui-dignissimos-sed-assumenda-sint-iusto/', + }, + {}, + '/modi-qui-dignissimos-sed-assumenda-sint-iusto/', + ), { wrapper, }, @@ -200,7 +213,7 @@ describe('useFetchPost', () => { }); const { result: secondResult } = renderHook( - () => useFetchPost({ slug: 'modi-qui-dignissimos-sed-assumenda-sint-iusto' }), + () => useFetchPost({ slug: 'modi-qui-dignissimos-sed-assumenda-sint-iusto' }, {}), { wrapper, }, diff --git a/packages/core/src/react/hooks/__tests__/useFetchPostOrPosts.tsx b/packages/core/src/react/hooks/__tests__/useFetchPostOrPosts.tsx index c712bfae0..d65894a16 100644 --- a/packages/core/src/react/hooks/__tests__/useFetchPostOrPosts.tsx +++ b/packages/core/src/react/hooks/__tests__/useFetchPostOrPosts.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { renderHook, waitFor } from '@testing-library/react'; +import { SWRConfig } from 'swr'; import { SettingsProvider } from '../../provider'; import { setHeadstartWPConfig } from '../../../utils'; import { useFetchPostOrPosts } from '../useFetchPostOrPosts'; @@ -11,6 +12,14 @@ import { mockUseFetchErrorResponse } from '../mocks'; describe('useFetchPostOrPosts', () => { const wrapper = ({ children }) => { + return ( + new Map() }}> + {children} + + ); + }; + + const wrapperWithCache = ({ children }) => { return {children}; }; @@ -120,7 +129,7 @@ describe('useFetchPostOrPosts', () => { '/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam', ), { - wrapper, + wrapper: wrapperWithCache, }, ); @@ -138,7 +147,7 @@ describe('useFetchPostOrPosts', () => { '/distinctio-rerum-ratione-maxime-repudiandae-laboriosam-quam', ), { - wrapper, + wrapper: wrapperWithCache, }, ); @@ -161,7 +170,7 @@ describe('useFetchPostOrPosts', () => { }; const { result } = renderHook(() => useFetchPostOrPosts(p, undefined, '/uncategorized'), { - wrapper, + wrapper: wrapperWithCache, }); await waitFor(() => { @@ -171,7 +180,7 @@ describe('useFetchPostOrPosts', () => { const { result: result2 } = renderHook( () => useFetchPosts(p.archive, undefined, '/uncategorized'), { - wrapper, + wrapper: wrapperWithCache, }, ); diff --git a/packages/core/src/react/hooks/__tests__/useFetchPosts.tsx b/packages/core/src/react/hooks/__tests__/useFetchPosts.tsx index 3d5a2f3ef..33065ac6b 100644 --- a/packages/core/src/react/hooks/__tests__/useFetchPosts.tsx +++ b/packages/core/src/react/hooks/__tests__/useFetchPosts.tsx @@ -2,6 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react'; import { expectTypeOf } from 'expect-type'; import * as React from 'react'; +import { SWRConfig } from 'swr'; import { PostEntity, PostsArchiveParams } from '../../../data'; import { SettingsProvider } from '../../provider'; import { useFetchPosts } from '../useFetchPosts'; @@ -11,7 +12,11 @@ import { mockUseFetchErrorResponse } from '../mocks'; describe('useFetchPosts', () => { const wrapper = ({ children }) => { - return {children}; + return ( + new Map() }}> + {children} + + ); }; beforeEach(() => { @@ -338,7 +343,7 @@ describe('useFetchPosts', () => { () => useFetchPosts( { - randomArgument: 10, // bypass swr cache + // randomArgument: 10, // bypass swr cache category: 'uncategorized', per_page: 1, }, diff --git a/packages/core/src/react/hooks/__tests__/useFetchSearch.tsx b/packages/core/src/react/hooks/__tests__/useFetchSearch.tsx index bcb021cbb..901936205 100644 --- a/packages/core/src/react/hooks/__tests__/useFetchSearch.tsx +++ b/packages/core/src/react/hooks/__tests__/useFetchSearch.tsx @@ -2,6 +2,7 @@ import { renderHook, waitFor } from '@testing-library/react'; import { expectTypeOf } from 'expect-type'; import * as React from 'react'; +import { SWRConfig } from 'swr'; import { PostEntity, PostsArchiveParams } from '../../../data'; import { SettingsProvider } from '../../provider'; import { useFetchSearch } from '../useFetchSearch'; @@ -11,7 +12,11 @@ import { mockUseFetchErrorResponse } from '../mocks'; describe('useFetchSearch', () => { const wrapper = ({ children }) => { - return {children}; + return ( + new Map() }}> + {children} + + ); }; setHeadlessConfig({