* config(jest): updated setup * config(jest): update testMatch to include jsx files * config(jest): add transformIgnorePatterns * config(jest): update ignore files that do not work in jest yet * config: add test:unit-jest to test script * fix(jest): lint with eslint-plugin-jest * refactor(jest): move unit test directory * refactor(mocha): restore mocha tests that fail in jest * docs(jest): update helpful scripts with test:unit-jest
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import React from "react"
|
|
import { render } from "enzyme"
|
|
import { Link } from "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} />)
|
|
const anchor = wrapper.find("a")
|
|
|
|
expect(anchor.attr("href")).toEqual("http://google.com/")
|
|
expect(anchor.attr("rel") || "").toMatch("noopener")
|
|
expect(anchor.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} />)
|
|
const anchor = wrapper.find("a")
|
|
|
|
expect(anchor.attr("href")).toEqual("http://google.com/")
|
|
expect(anchor.attr("target")).toEqual("_blank")
|
|
expect(anchor.attr("rel") || "").toMatch("noopener")
|
|
expect(anchor.attr("rel") || "").toMatch("noreferrer")
|
|
})
|
|
})
|