Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SarahElson/16976e33e5c7bd22f40f5e35477fe36e to your computer and use it in GitHub Desktop.
Save SarahElson/16976e33e5c7bd22f40f5e35477fe36e to your computer and use it in GitHub Desktop.
Getting Started With Gatsby Testing -
// 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