Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 491bdf9

Browse files
authored
chore(www): Create tests for mdx-link (gatsbyjs#21103)
* fix file links * add tests for mdx-link * add test for mdx-link
1 parent c18555c commit 491bdf9

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from "react"
2+
import { render } from "@testing-library/react"
3+
import MdxLink, { shouldRenderRawLink } from "../mdx-link"
4+
5+
jest.mock("../localized-link", () => {
6+
// Mock the component to use a different tag so we can easily differentiate
7+
return () => <span />
8+
})
9+
10+
describe("mdx-link", () => {
11+
it("creates a raw link on external links", () => {
12+
const { container } = render(
13+
<MdxLink href="https://github.com/gatsbyjs.gatsby" />
14+
)
15+
expect(container.firstChild.nodeName).toBe("A")
16+
})
17+
18+
it("creates a raw link on hashes", () => {
19+
const { container } = render(<MdxLink href="#gatsby" />)
20+
expect(container.firstChild.nodeName).toBe("A")
21+
})
22+
23+
it("creates a raw link on files", () => {
24+
const { container } = render(<MdxLink href="/gatsby-cheat-sheet.pdf" />)
25+
expect(container.firstChild.nodeName).toBe("A")
26+
})
27+
28+
it("creates a localized link for internal links", () => {
29+
const { container } = render(<MdxLink href="/docs" />)
30+
expect(container.firstChild.nodeName).toBe("SPAN")
31+
})
32+
})

0 commit comments

Comments
 (0)