online-validator-badge.jsx 865 B

123456789101112131415161718192021222324252627282930
  1. import React from "react"
  2. import { mount } from "enzyme"
  3. import OnlineValidatorBadge from "components/online-validator-badge"
  4. describe("<OnlineValidatorBadge/> Anchor Target Safety", function () {
  5. it("should render a validator link with safe `rel` attributes", function () {
  6. // When
  7. const props = {
  8. getConfigs: () => ({}),
  9. getComponent: () => null,
  10. specSelectors: {
  11. url: () => "swagger.json"
  12. }
  13. }
  14. const wrapper = mount(
  15. <OnlineValidatorBadge {...props} />
  16. )
  17. const anchor = wrapper.find("a")
  18. // Then
  19. expect(anchor.props().href).toEqual(
  20. "https://validator.swagger.io/validator/debug?url=swagger.json"
  21. )
  22. expect(anchor.props().target).toEqual("_blank")
  23. expect(anchor.props().rel || "").toInclude("noopener")
  24. expect(anchor.props().rel || "").toInclude("noreferrer")
  25. })
  26. })