Created
June 10, 2022 16:37
-
-
Save SarahElson/16976e33e5c7bd22f40f5e35477fe36e to your computer and use it in GitHub Desktop.
Getting Started With Gatsby Testing -
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// components/__tests__/sample.js | |
import React from "react" | |
import { render } from "@testing-library/react" | |
import { useStaticQuery } from "gatsby" | |
import Helmet from "react-helmet" | |
import Sample from "../sample" | |
describe("Sample component", () => { | |
beforeAll(() => { | |
useStaticQuery.mockReturnValue({ | |
site: { | |
siteMetadata: { | |
title: `Gatsby Starter Blog for Freshers`, | |
description: `A starter blog demonstrating what Gatsby can do and the features offered.`, | |
social: { | |
twitter: `irshad`, | |
}, | |
}, | |
}, | |
}) | |
}) | |
it("renders the tests correctly", () => { | |
const mockTitle = "All posts | Gatsby Starter Blog for Freshers" | |
const mockDescription = "A starter blog demonstrating what Gatsby can do and the features offered." | |
const mockTwitterHandler = "Irshad" | |
render(<SEO title="All posts" />) | |
const { title, metaTags } = Helmet.peek() | |
expect(title).toBe(mockTitle) | |
expect(metaTags[0].content).toBe(mockDescription) | |
expect(metaTags[5].content).toBe(mockTwitterHandler) | |
expect(metaTags.length).toBe(10) | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment