Skip to content

Commit

Permalink
GH-54 fix(test): mock sanity client in blog post page
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jul 14, 2020
1 parent e96b3a1 commit edc817d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pages-tests/blogpost.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { axe } from 'jest-axe';
import { render } from 'offbeat-appetite-render';
import { render, waitFor } from 'offbeat-appetite-render';

import BlogPostPage from '../pages/[categoryId]/[postId]';
import testRecipeData from '../data/posts/will-malta-s-spinach-and-tuna-pie-make-the-cut.json';
Expand All @@ -15,6 +15,14 @@ import { SanityBlogPostFull } from '../typings';

const blogPostData = testRecipeData as SanityBlogPostFull;

jest.mock('../components/blog-post/sanity-browser-client', () => {
return {
getPostReviews: (): { reviews: number[] } => {
return { reviews: [1, 5, 3] };
},
};
});

beforeAll(() => {
process.env = Object.assign(process.env);
});
Expand Down Expand Up @@ -68,7 +76,9 @@ describe('Post Page', () => {
router: { asPath: '/recipes/egg-in-coffee-behind-vietnam-s-egg-coffee-recipe' },
});

expect(getByText('subscribe to the newsletter')).toHaveAttribute('href', '#subscribe');
await waitFor(() =>
expect(getByText('subscribe to the newsletter')).toHaveAttribute('href', '#subscribe')
);

expect(await axe(container)).toHaveNoViolations();

Expand Down

0 comments on commit edc817d

Please sign in to comment.