Some checks failed
Node.js CI / build (push) Failing after 2s
Node.js CI / e2e-tests (+(a11y|security|bugs)/**/*cy.js) (push) Failing after 2s
Node.js CI / e2e-tests (features/**/!(o|d|m)*.cy.js) (push) Failing after 2s
Node.js CI / e2e-tests (features/**/+(o|d)*.cy.js) (push) Failing after 2s
Node.js CI / e2e-tests (features/**/m*.cy.js) (push) Failing after 2s
CodeQL / Analyze (javascript) (push) Failing after 2m49s
Security scan for docker image / build (push) Failing after 54s
40 lines
1.2 KiB
JavaScript
Executable File
40 lines
1.2 KiB
JavaScript
Executable File
import React from "react"
|
|
import { render } from "enzyme"
|
|
import { Link } from "core/components/layout-utils"
|
|
|
|
describe("<Link/> Anchor Target Safety", function () {
|
|
const dummyComponent = () => null
|
|
const components = {
|
|
Link
|
|
}
|
|
const baseProps = {
|
|
getComponent: c => components[c] || dummyComponent
|
|
}
|
|
|
|
it("renders regular links with `noreferrer` and `noopener`", function () {
|
|
const props = {
|
|
...baseProps,
|
|
href: "http://google.com/"
|
|
}
|
|
let wrapper = render(<Link {...props} />)
|
|
|
|
expect(wrapper.attr("href")).toEqual("http://google.com/")
|
|
expect(wrapper.attr("rel") || "").toMatch("noopener")
|
|
expect(wrapper.attr("rel") || "").toMatch("noreferrer")
|
|
})
|
|
|
|
it("enforces `noreferrer` and `noopener` on target=_blank links", function () {
|
|
const props = {
|
|
...baseProps,
|
|
href: "http://google.com/",
|
|
target: "_blank"
|
|
}
|
|
let wrapper = render(<Link {...props} />)
|
|
|
|
expect(wrapper.attr("href")).toEqual("http://google.com/")
|
|
expect(wrapper.attr("target")).toEqual("_blank")
|
|
expect(wrapper.attr("rel") || "").toMatch("noopener")
|
|
expect(wrapper.attr("rel") || "").toMatch("noreferrer")
|
|
})
|
|
})
|