Skip to content

Commit

Permalink
chore(www): Create tests for mdx-link (#21103)
Browse files Browse the repository at this point in the history
* fix file links

* add tests for mdx-link

* add test for mdx-link
  • Loading branch information
tesseralis committed Jan 31, 2020
1 parent c18555c commit 491bdf9
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions www/src/components/__tests__/mdx-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react"
import { render } from "@testing-library/react"
import MdxLink, { shouldRenderRawLink } from "../mdx-link"

jest.mock("../localized-link", () => {
// Mock the component to use a different tag so we can easily differentiate
return () => <span />
})

describe("mdx-link", () => {
it("creates a raw link on external links", () => {
const { container } = render(
<MdxLink href="https://github.com/gatsbyjs.gatsby" />
)
expect(container.firstChild.nodeName).toBe("A")
})

it("creates a raw link on hashes", () => {
const { container } = render(<MdxLink href="#gatsby" />)
expect(container.firstChild.nodeName).toBe("A")
})

it("creates a raw link on files", () => {
const { container } = render(<MdxLink href="/gatsby-cheat-sheet.pdf" />)
expect(container.firstChild.nodeName).toBe("A")
})

it("creates a localized link for internal links", () => {
const { container } = render(<MdxLink href="/docs" />)
expect(container.firstChild.nodeName).toBe("SPAN")
})
})

0 comments on commit 491bdf9

Please sign in to comment.