From fb749e8befb2dcdc266c2e8b7ef7c9001947143a Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 27 Nov 2023 19:40:40 +0100 Subject: test(services): add tests for posts fetchers --- .../fetchers/posts/fetch-posts-count.test.ts | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/services/graphql/fetchers/posts/fetch-posts-count.test.ts (limited to 'src/services/graphql/fetchers/posts/fetch-posts-count.test.ts') diff --git a/src/services/graphql/fetchers/posts/fetch-posts-count.test.ts b/src/services/graphql/fetchers/posts/fetch-posts-count.test.ts new file mode 100644 index 0000000..a0fd594 --- /dev/null +++ b/src/services/graphql/fetchers/posts/fetch-posts-count.test.ts @@ -0,0 +1,26 @@ +import { afterEach, describe, expect, it } from '@jest/globals'; +import { wpPostsFixture } from '../../../../../tests/fixtures'; +import { fetchPostsCount } from './fetch-posts-count'; + +describe('fetch-posts-count', () => { + afterEach(() => { + window.history.replaceState({}, '', '/'); + }); + + it('returns the WordPress posts count using GraphQL', async () => { + const result = await fetchPostsCount(); + + expect.assertions(1); + + expect(result).toBe(wpPostsFixture.length); + }); + + it('rejects with an error when no posts are found', async () => { + window.history.replaceState({}, '', '/?error=true'); + expect.assertions(1); + + await expect(async () => fetchPostsCount()).rejects.toEqual( + new Error('Unable to find the total number of posts.') + ); + }); +}); -- cgit v1.2.3