-
+
diff --git a/src/core/plugins/syntax-highlighting/components/HighlightCode.jsx b/src/core/plugins/syntax-highlighting/components/HighlightCode.jsx
index f389f0b95ef..210e94a86c9 100644
--- a/src/core/plugins/syntax-highlighting/components/HighlightCode.jsx
+++ b/src/core/plugins/syntax-highlighting/components/HighlightCode.jsx
@@ -70,7 +70,7 @@ const HighlightCode = ({
{canCopy && (
-
+
)}
diff --git a/test/unit/bugs/3199-sanitization-escaping.jsx b/test/unit/bugs/3199-sanitization-escaping.jsx
index bc0127dcd34..83d1136051d 100644
--- a/test/unit/bugs/3199-sanitization-escaping.jsx
+++ b/test/unit/bugs/3199-sanitization-escaping.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import Markdown from "core/components/providers/markdown"
describe("UI-3199: Sanitized Markdown causing code examples to be double escaped", function(){
@@ -13,9 +13,10 @@ describe("UI-3199: Sanitized Markdown causing code examples to be double escaped
source: str
}
- let el = render(
)
+ const { container } = render(
)
+ const codeElement = container.querySelector("code")
- expect(el.find("code").first().text()).toEqual("{\"abc\": \"def\"}\n")
- expect(el.find("code").first().html()).toEqual("{\"abc\": \"def\"}\n")
+ expect(codeElement.textContent).toEqual("{\"abc\": \"def\"}\n")
+ expect(codeElement.innerHTML).toEqual("{\"abc\": \"def\"}\n")
})
})
diff --git a/test/unit/bugs/3279-empty-markdown-source.jsx b/test/unit/bugs/3279-empty-markdown-source.jsx
index 8267ebd9074..210a672de6e 100644
--- a/test/unit/bugs/3279-empty-markdown-source.jsx
+++ b/test/unit/bugs/3279-empty-markdown-source.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import Markdown from "core/components/providers/markdown"
describe("UI-3279: Empty Markdown inputs causing bare `undefined` in output", function(){
@@ -10,7 +10,7 @@ describe("UI-3279: Empty Markdown inputs causing bare `undefined` in output", fu
let el = render(
)
- expect(el.text()).toEqual("")
+ expect(el.queryByText(/./)).toBeNull()
})
it("should return no text for `undefined` as source input", function(){
@@ -20,7 +20,7 @@ describe("UI-3279: Empty Markdown inputs causing bare `undefined` in output", fu
let el = render(
)
- expect(el.text()).toEqual("")
+ expect(el.queryByText(/./)).toBeNull()
})
it("should return no text for empty string as source input", function(){
@@ -30,6 +30,6 @@ describe("UI-3279: Empty Markdown inputs causing bare `undefined` in output", fu
let el = render(
)
- expect(el.text()).toEqual("")
+ expect(el.queryByText(/./)).toBeNull()
})
})
diff --git a/test/unit/bugs/4557-default-parameter-values.jsx b/test/unit/bugs/4557-default-parameter-values.jsx
index 1fea545c46e..143b0bb066c 100644
--- a/test/unit/bugs/4557-default-parameter-values.jsx
+++ b/test/unit/bugs/4557-default-parameter-values.jsx
@@ -3,7 +3,7 @@
*/
import React from "react"
import { List, fromJS } from "immutable"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import ParameterRow from "core/components/parameter-row"
import {
diff --git a/test/unit/components/filter.jsx b/test/unit/components/filter.jsx
index caa85f0f4a7..7c7f6091018 100644
--- a/test/unit/components/filter.jsx
+++ b/test/unit/components/filter.jsx
@@ -1,10 +1,10 @@
import React from "react"
-import { mount } from "enzyme"
+import { render, screen } from "@testing-library/react"
+import "@testing-library/jest-dom"
import FilterContainer from "core/containers/filter"
import { Col } from "core/components/layout-utils"
describe("
", function(){
-
const mockedProps = {
specSelectors: {
loadingStatus() {}
@@ -16,32 +16,30 @@ describe("
", function(){
}
it("renders FilterContainer if filter is provided", function(){
-
- // Given
- let props = {...mockedProps}
- props.layoutSelectors = {...mockedProps.specSelectors}
- props.layoutSelectors.currentFilter = function() {return true}
+ // Given
+ let props = {...mockedProps}
+ props.layoutSelectors = {...mockedProps.specSelectors}
+ props.layoutSelectors.currentFilter = function() {return true}
// When
- let wrapper = mount(
)
+ render(
)
// Then
- const renderedColInsideFilter = wrapper.find(Col)
- expect(renderedColInsideFilter.length).toEqual(1)
+ const renderedColInsideFilter = screen.queryByTestId("filter-col")
+ expect(renderedColInsideFilter).toBeInTheDocument()
})
it("does not render FilterContainer if filter is false", function(){
-
// Given
let props = {...mockedProps}
props.layoutSelectors = {...mockedProps.specSelectors}
props.layoutSelectors.currentFilter = function() {return false}
// When
- let wrapper = mount(
)
+ render(
)
// Then
- const renderedColInsideFilter = wrapper.find(Col)
- expect(renderedColInsideFilter.length).toEqual(0)
+ const renderedColInsideFilter = screen.queryByTestId("filter-col")
+ expect(renderedColInsideFilter).not.toBeInTheDocument()
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/highlight-code.jsx b/test/unit/components/highlight-code.jsx
index 4186ab5caec..5e2c39487e6 100644
--- a/test/unit/components/highlight-code.jsx
+++ b/test/unit/components/highlight-code.jsx
@@ -1,6 +1,7 @@
+import { render,screen } from "@testing-library/react"
+import "@testing-library/jest-dom"
import React from "react"
import expect from "expect"
-import { shallow, mount } from "enzyme"
import HighlightCode from "core/plugins/syntax-highlighting/components/HighlightCode"
import SyntaxHighlighter from "core/plugins/syntax-highlighting/components/SyntaxHighlighter"
@@ -21,23 +22,29 @@ const fakeGetComponent = (name, isContainer) => {
describe("
", () => {
it("should render a Download button if downloadable", () => {
const props = { downloadable: true, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
- const wrapper = shallow(
)
- expect(wrapper.find(".download-contents").length).toEqual(1)
+ const {
+ container
+ } = render(
)
+ expect(container.querySelectorAll(".download-contents").length).toEqual(1)
})
it("should render a Copy To Clipboard button if copyable", () => {
const props = { canCopy: true, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
- const wrapper = shallow(
)
- expect(wrapper.find("CopyToClipboard").length).toEqual(1)
+ render(
)
+ const copyButton = screen.queryByRole("button", { name: /copy/i })
+ expect(copyButton).toBeInTheDocument()
+
})
it("should render values in a preformatted element", () => {
const value = "test text"
const props = { children: value , getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
- const wrapper = mount(
)
- const preTag = wrapper.find("pre")
+ const {
+ container
+ } = render(
)
+ const preTag = container.querySelectorAll("pre")
expect(preTag.length).toEqual(1)
- expect(preTag.text()).toEqual(value)
+ expect(preTag[0].textContent).toEqual(value)
})
})
diff --git a/test/unit/components/info-wrapper.jsx b/test/unit/components/info-wrapper.jsx
index 1b31d069988..e6b4c67a644 100644
--- a/test/unit/components/info-wrapper.jsx
+++ b/test/unit/components/info-wrapper.jsx
@@ -1,5 +1,5 @@
+import { render } from "@testing-library/react"
import React from "react"
-import { mount } from "enzyme"
import { fromJS } from "immutable"
import InfoContainer from "core/containers/info"
@@ -30,10 +30,12 @@ describe("
", function () {
props.specSelectors.info = function () {return fromJS(["info1", "info2"])}
// When
- let wrapper = mount(
)
+ let {
+ container
+ } = render(
)
// Then
- const renderedInfo = wrapper.find("span.mocked-info")
+ const renderedInfo = container.querySelectorAll("span.mocked-info")
expect(renderedInfo.length).toEqual(1)
})
@@ -45,10 +47,12 @@ describe("
", function () {
props.specSelectors.info = function () {return fromJS([])}
// When
- let wrapper = mount(
)
+ let {
+ container
+ } = render(
)
// Then
- const renderedInfo = wrapper.find("span.mocked-info")
+ const renderedInfo = container.querySelectorAll("span.mocked-info")
expect(renderedInfo.length).toEqual(0)
})
@@ -58,10 +62,12 @@ describe("
", function () {
let props = {...mockedProps}
// When
- let wrapper = mount(
)
+ let {
+ container
+ } = render(
)
// Then
- const renderedInfo = wrapper.find("span.mocked-info")
+ const renderedInfo = container.querySelectorAll("span.mocked-info")
expect(renderedInfo.length).toEqual(0)
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/live-response.jsx b/test/unit/components/live-response.jsx
index aed0aec96b3..7c194169252 100644
--- a/test/unit/components/live-response.jsx
+++ b/test/unit/components/live-response.jsx
@@ -1,9 +1,10 @@
import React from "react"
+import { render, screen } from "@testing-library/react"
+import "@testing-library/jest-dom"
import { fromJSOrdered } from "core/utils"
-import { shallow } from "enzyme"
import Curl from "core/components/curl"
-import LiveResponse from "core/components/live-response"
import ResponseBody from "core/components/response-body"
+import LiveResponse from "core/components/live-response"
describe("
", function(){
let request = fromJSOrdered({
@@ -35,9 +36,7 @@ describe("
", function(){
tests.forEach(function(test) {
it("passes " + test.expected.request + " to Curl when showMutatedRequest = " + test.showMutatedRequest, function() {
-
- // Given
-
+// Given
let response = fromJSOrdered({
status: 200,
url: "http://petstore.swagger.io/v2/pet/1",
@@ -52,8 +51,8 @@ describe("
", function(){
let requestForSpy = jest.fn().mockImplementation(function() { return request })
let components = {
- curl: Curl,
- responseBody: ResponseBody
+ curl: () =>
Mocked Curl
,
+ responseBody: () =>
Mocked ResponseBody
}
let props = {
@@ -69,33 +68,21 @@ describe("
", function(){
displayRequestDuration: true,
getConfigs: () => ({ showMutatedRequest: test.showMutatedRequest })
}
+ // When
+ render(
)
- // When
- let wrapper = shallow(
)
-
- // Then
- expect(mutatedRequestForSpy.mock.calls.length).toEqual(test.expected.mutatedRequestForCalls)
- expect(requestForSpy.mock.calls.length).toEqual(test.expected.requestForCalls)
-
- const curl = wrapper.find(Curl)
- expect(curl.length).toEqual(1)
- expect(curl.props().request).toBe(requests[test.expected.request])
-
- const expectedUrl = requests[test.expected.request].get("url")
- expect(wrapper.find("div.request-url pre.microlight").text()).toEqual(expectedUrl)
+ // Then
+ expect(mutatedRequestForSpy).toHaveBeenCalledTimes(test.expected.mutatedRequestForCalls)
+ expect(requestForSpy).toHaveBeenCalledTimes(test.expected.requestForCalls)
- const duration = wrapper.find("Duration")
- expect(duration.length).toEqual(1)
- expect(duration.props().duration).toEqual(50)
- expect(duration.html())
- .toEqual("
")
+ const expectedUrl = requests[test.expected.request].get("url")
+ expect(screen.getByText(expectedUrl)).toBeInTheDocument()
- const responseHeaders = wrapper.find("Headers")
- expect(duration.length).toEqual(1)
- expect(responseHeaders.props().headers.length).toEqual(1)
- expect(responseHeaders.props().headers[0].key).toEqual("content-type")
- expect(responseHeaders.html())
- .toEqual("
")
+
+ expect(screen.getByText(/50 ms/)).toBeInTheDocument()
+ const headersElement = screen.getByText(/content-type/i)
+ expect(headersElement).toBeInTheDocument()
+ expect(headersElement.textContent).toContain("application/xml")
})
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/markdown.jsx b/test/unit/components/markdown.jsx
index c4e72c9628d..8b2d908a113 100644
--- a/test/unit/components/markdown.jsx
+++ b/test/unit/components/markdown.jsx
@@ -1,5 +1,5 @@
+import { render } from "@testing-library/react"
import React from "react"
-import { render } from "enzyme"
import Markdown from "core/components/providers/markdown"
import { Markdown as OAS3Markdown } from "core/plugins/oas3/wrap-components/markdown.jsx"
@@ -8,39 +8,51 @@ describe("Markdown component", function () {
it("allows elements with class, style and data-* attribs", function () {
const getConfigs = () => ({ useUnsafeMarkdown: true })
const str = `
ONE`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("strips class, style and data-* attribs from elements", function () {
const getConfigs = () => ({ useUnsafeMarkdown: false })
const str = `
ONE`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows td elements with colspan attrib", function () {
const str = `
`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows image elements", function () {
const str = ``
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`

\n
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`

\n
`)
})
it("allows image elements with https scheme", function () {
const str = ``
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`

\n
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`

\n
`)
})
it("allows image elements with data scheme", function () {
const str = `

`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows heading elements", function () {
@@ -51,14 +63,18 @@ describe("Markdown component", function () {
#### h4
##### h5
###### h6`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
h1
\nh2
\nh3
\nh4
\nh5
\nh6
\n`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
h1
\nh2
\nh3
\nh4
\nh5
\nh6
\n`)
})
it("allows links", function () {
const str = `[Link](https://example.com/)`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
})
@@ -66,33 +82,43 @@ describe("Markdown component", function () {
it("allows elements with class, style and data-* attribs", function () {
const getConfigs = () => ({ useUnsafeMarkdown: true })
const str = `
ONE`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("strips class, style and data-* attribs from elements", function () {
const getConfigs = () => ({ useUnsafeMarkdown: false })
const str = `
ONE`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows image elements", function () {
const str = ``
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows image elements with https scheme", function () {
const str = ``
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows image elements with data scheme", function () {
const str = `

`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
`)
})
it("allows heading elements", function () {
@@ -103,8 +129,10 @@ describe("Markdown component", function () {
#### h4
##### h5
###### h6`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
h1
\nh2
\nh3
\nh4
\nh5
\nh6
`)
+ const {
+ container
+ } = render(
)
+ expect(container.innerHTML).toEqual(`
h1
\nh2
\nh3
\nh4
\nh5
\nh6
`)
})
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/online-validator-badge.jsx b/test/unit/components/online-validator-badge.jsx
index c900a3c45bd..8fee2e891a3 100644
--- a/test/unit/components/online-validator-badge.jsx
+++ b/test/unit/components/online-validator-badge.jsx
@@ -1,5 +1,6 @@
import React from "react"
-import { mount } from "enzyme"
+import { render, screen } from "@testing-library/react"
+import "@testing-library/jest-dom"
import OnlineValidatorBadge from "core/components/online-validator-badge"
import expect from "expect"
@@ -13,19 +14,18 @@ describe("
", function () {
url: () => "https://smartbear.com/swagger.json"
}
}
- const wrapper = mount(
-
- )
- // Then
- expect(wrapper.find("a").props().href).toEqual(
+ render(
+
)
+
+ const link = screen.getByRole("link", { name: /validator/i })
+ expect(link).toHaveAttribute(
+ "href",
"https://validator.swagger.io/validator/debug?url=https%3A%2F%2Fsmartbear.com%2Fswagger.json"
)
- expect(wrapper.find("ValidatorImage").length).toEqual(1)
})
- it("should encode a definition URL correctly", function () {
- // When
+ it("should encode a definition URL correctly", () => {
const props = {
getConfigs: () => ({}),
getComponent: () => null,
@@ -33,18 +33,21 @@ describe("
", function () {
url: () => "http://google.com/swagger.json"
}
}
- const wrapper = mount(
+ render(
)
// Then
- expect(wrapper.find("a").props().href).toEqual(
+
+ const link = screen.getByRole("link", { name: /validator/i })
+ expect(link).toHaveAttribute(
+ "href",
"https://validator.swagger.io/validator/debug?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
)
- expect(wrapper.find("ValidatorImage").length).toEqual(1)
- expect(wrapper.find("ValidatorImage").props().src).toEqual(
- "https://validator.swagger.io/validator?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
- )
+
+
+ const validatorElement = screen.getByLabelText("validator")
+ expect(validatorElement).toBeInTheDocument()
})
it("should resolve a definition URL against the browser's location", function () {
@@ -58,18 +61,19 @@ describe("
", function () {
url: () => "http://google.com/swagger.json"
}
}
- const wrapper = mount(
+ render(
)
-
- // Then
- expect(wrapper.find("a").props().href).toEqual(
+
+ const link = screen.getByRole("link", { name: /validator/i })
+ expect(link).toHaveAttribute(
+ "href",
"https://validator.swagger.io/validator/debug?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
)
- expect(wrapper.find("ValidatorImage").length).toEqual(1)
- expect(wrapper.find("ValidatorImage").props().src).toEqual(
- "https://validator.swagger.io/validator?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
- )
+
+
+ const validatorElement = screen.getByLabelText("validator")
+ expect(validatorElement).toBeInTheDocument()
})
- // should resolve a definition URL against the browser's location
-})
+ // should resolve a definition URL against the browser's location
+})
\ No newline at end of file
diff --git a/test/unit/components/operation-tag.jsx b/test/unit/components/operation-tag.jsx
index 0d1ba533ee7..59ad80265a8 100644
--- a/test/unit/components/operation-tag.jsx
+++ b/test/unit/components/operation-tag.jsx
@@ -1,20 +1,21 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import OperationTag from "core/components/operation-tag"
import Im from "immutable"
import { Link } from "core/components/layout-utils"
describe("
", function(){
it("render externalDocs URL for swagger v2", function(){
-
const dummyComponent = () => null
const components = {
Collapse: () => dummyComponent,
Markdown: () => dummyComponent,
DeepLink: () => dummyComponent,
- Link
+ Link,
+ ArrowUpIcon: dummyComponent,
+ ArrowDownIcon: dummyComponent,
}
-
+
let props = {
tagObj: Im.fromJS({
tagDetails: {
@@ -36,18 +37,16 @@ describe("
", function(){
},
show() {
return true
- }
+ },
}
}
-
- let wrapper = shallow(
)
-
- const opblockTag = wrapper.find(".opblock-tag")
- expect(opblockTag.length).toEqual(1)
- expect(opblockTag.getElement().type).toEqual("h3")
-
- const renderedLink = wrapper.find("Link")
- expect(renderedLink.length).toEqual(1)
- expect(renderedLink.props().href).toEqual("http://swagger.io")
+
+ const { getByTestId, getByText } = render(
)
+
+ const opblockTag = getByTestId("opblock-tag")
+ expect(opblockTag.tagName).toBe("H3")
+
+ const renderedLink = getByText("Find out more")
+ expect(renderedLink.getAttribute("href")).toBe("http://swagger.io")
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/operation.jsx b/test/unit/components/operation.jsx
index 18d7da49fb9..26694f37b3b 100644
--- a/test/unit/components/operation.jsx
+++ b/test/unit/components/operation.jsx
@@ -1,5 +1,5 @@
+import { render } from "@testing-library/react"
import React from "react"
-import { shallow } from "enzyme"
import Operation from "core/components/operation"
describe("
", function(){
@@ -17,14 +17,16 @@ describe("
", function(){
toggleCollapse: jest.fn()
}
- let wrapper = shallow(
)
+ let {
+ container
+ } = render(
)
- expect(wrapper.find(".opblock").length).toEqual(1)
- expect(wrapper.find(".opblock-summary-method").text()).toEqual("GET")
- expect(wrapper.find(".opblock-summary-path").text().trim()).toEqual("/one")
- expect(wrapper.find("[isOpened]").prop("isOpened")).toEqual(true)
+ expect(container.querySelectorAll(".opblock").length).toEqual(1)
+ expect(container.querySelectorAll(".opblock-summary-method").textContent).toEqual("GET")
+ expect(container.querySelectorAll(".opblock-summary-path").textContent.trim()).toEqual("/one")
+ expect(container.querySelectorAll("[isOpened]").prop("isOpened")).toEqual(true)
- wrapper.find(".opblock-summary").simulate("click")
+ container.querySelectorAll(".opblock-summary").simulate("click")
expect(props.toggleCollapse).toHaveBeenCalled()
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/operations.jsx b/test/unit/components/operations.jsx
index 0cbb648b7f2..5143836b1cd 100644
--- a/test/unit/components/operations.jsx
+++ b/test/unit/components/operations.jsx
@@ -1,5 +1,5 @@
+import { render } from "@testing-library/react"
import React from "react"
-import { render } from "enzyme"
import { fromJS } from "immutable"
import DeepLink from "core/components/deep-link"
import Operations from "core/components/operations"
@@ -63,10 +63,12 @@ describe("
", function(){
}
}
- let wrapper = render(
)
+ let {
+ container
+ } = render(
)
- expect(wrapper.find("span.mocked-op").length).toEqual(1)
- expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
+ expect(container.querySelectorAll("span.mocked-op").length).toEqual(1)
+ expect(container.querySelectorAll("span.mocked-op")[0].id).toEqual("/pets/{id}-get")
})
it("should render an OAS3 `get` and `trace` method, but not a `foo` method", function(){
@@ -119,10 +121,12 @@ describe("
", function(){
}
}
- let wrapper = render(
)
+ let {
+ container
+ } = render(
)
- expect(wrapper.find("span.mocked-op").length).toEqual(2)
- expect(wrapper.find("span.mocked-op").eq(0).attr("id")).toEqual("/pets/{id}-get")
- expect(wrapper.find("span.mocked-op").eq(1).attr("id")).toEqual("/pets/{id}-trace")
+ expect(container.querySelectorAll("span.mocked-op").length).toEqual(2)
+ expect(container.querySelectorAll("span.mocked-op")[0].id).toEqual("/pets/{id}-get")
+ expect(container.querySelectorAll("span.mocked-op")[1].id).toEqual("/pets/{id}-trace")
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/parameter-row.jsx b/test/unit/components/parameter-row.jsx
index bcf9e540a4d..b1f59fe8798 100644
--- a/test/unit/components/parameter-row.jsx
+++ b/test/unit/components/parameter-row.jsx
@@ -1,9 +1,9 @@
+import { render } from "@testing-library/react"
/**
* @prettier
*/
import React from "react"
import { List, fromJS } from "immutable"
-import { render } from "enzyme"
import ParameterRow from "core/components/parameter-row"
import {
@@ -56,10 +56,12 @@ describe("
", () => {
})
const props = createProps({ param, isOAS3: false })
- const wrapper = render(
)
+ const {
+ container
+ } = render(
)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
+ expect(container.querySelectorAll(".parameter__type").length).toEqual(1)
+ expect(container.querySelectorAll(".parameter__type")[0].textContent).toEqual("string($uuid)")
})
it("Can render Swagger 2 parameter type without format", () => {
@@ -71,10 +73,12 @@ describe("
", () => {
})
const props = createProps({ param, isOAS3: false })
- const wrapper = render(
)
+ const {
+ container
+ } = render(
)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string")
+ expect(container.querySelectorAll(".parameter__type").length).toEqual(1)
+ expect(container.querySelectorAll(".parameter__type")[0].textContent).toEqual("string")
})
it("Can render Swagger 2 parameter type boolean without format", () => {
@@ -86,10 +90,12 @@ describe("
", () => {
})
const props = createProps({ param, isOAS3: false })
- const wrapper = render(
)
+ const {
+ container
+ } = render(
)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("boolean")
+ expect(container.querySelectorAll(".parameter__type").length).toEqual(1)
+ expect(container.querySelectorAll(".parameter__type")[0].textContent).toEqual("boolean")
})
it("Can render OAS3 parameter type with format", () => {
@@ -104,10 +110,12 @@ describe("
", () => {
})
const props = createProps({ param, isOAS3: true })
- const wrapper = render(
)
+ const {
+ container
+ } = render(
)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string($uuid)")
+ expect(container.querySelectorAll(".parameter__type").length).toEqual(1)
+ expect(container.querySelectorAll(".parameter__type")[0].textContent).toEqual("string($uuid)")
})
it("Can render OAS3 parameter type without format", () => {
@@ -121,10 +129,12 @@ describe("
", () => {
})
const props = createProps({ param, isOAS3: true })
- const wrapper = render(
)
+ const {
+ container
+ } = render(
)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("string")
+ expect(container.querySelectorAll(".parameter__type").length).toEqual(1)
+ expect(container.querySelectorAll(".parameter__type")[0].textContent).toEqual("string")
})
it("Can render OAS3 parameter type boolean without format", () => {
@@ -138,10 +148,12 @@ describe("
", () => {
})
const props = createProps({ param, isOAS3: true })
- const wrapper = render(
)
+ const {
+ container
+ } = render(
)
- expect(wrapper.find(".parameter__type").length).toEqual(1)
- expect(wrapper.find(".parameter__type").text()).toEqual("boolean")
+ expect(container.querySelectorAll(".parameter__type").length).toEqual(1)
+ expect(container.querySelectorAll(".parameter__type")[0].textContent).toEqual("boolean")
})
})
@@ -351,4 +363,4 @@ describe("bug #5573: zero default and example values", function () {
expect(props.onChange).toHaveBeenCalled()
expect(props.onChange).toHaveBeenCalledWith(paramValue, "0", false)
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/components/response-body.jsx b/test/unit/components/response-body.jsx
index bf80249f7bc..9f45c88f4be 100644
--- a/test/unit/components/response-body.jsx
+++ b/test/unit/components/response-body.jsx
@@ -1,10 +1,19 @@
+import { render ,screen} from "@testing-library/react"
+import "@testing-library/jest-dom"
import React from "react"
-import { shallow } from "enzyme"
import ResponseBody from "core/components/response-body"
describe("
", function () {
+
+ // Mock component
+ const HighlightCode = ({ children, canCopy }) => (
+
+ {children}
+
+ )
+
const components = {
- HighlightCode: () => null
+ HighlightCode
}
const props = {
getComponent: c => components[c],
@@ -13,35 +22,41 @@ describe("
", function () {
it("renders ResponseBody as 'application/json'", function () {
props.contentType = "application/json"
props.content = "{\"key\": \"a test value\"}"
- const wrapper = shallow(
)
- expect(wrapper.find("HighlightCode").length).toEqual(1)
+ render(
)
+ expect(screen.getByTestId("highlight-code")).toBeInTheDocument()
})
it("renders ResponseBody as 'text/html'", function () {
props.contentType = "application/json"
props.content = "
Result"
- const wrapper = shallow(
)
- expect(wrapper.find("HighlightCode").length).toEqual(1)
+ render(
)
+ expect(screen.getByTestId("highlight-code")).toBeInTheDocument()
})
it("renders ResponseBody as 'image/svg'", function () {
props.contentType = "image/svg"
- const wrapper = shallow(
)
- expect(wrapper.find("HighlightCode").length).toEqual(0)
+ const {
+ container
+ } = render(
)
+ expect(container.querySelectorAll("HighlightCode").length).toEqual(0)
})
it("should render a copyable highlightCodeComponent for text types", function () {
props.contentType = "text/plain"
props.content = "test text"
- const wrapper = shallow(
)
- expect(wrapper.find("HighlightCode[canCopy]").length).toEqual(1)
+ render(
)
+ const copyableCode = screen.getByTestId("highlight-code")
+ expect(copyableCode).toBeInTheDocument()
+ expect(copyableCode).toHaveAttribute("data-cancopy")
})
it("should render Download file link for non-empty Blob response", function () {
props.contentType = "application/octet-stream"
props.content = new Blob(["\"test\""], { type: props.contentType })
- const wrapper = shallow(
)
- expect(wrapper.text()).toMatch(/Download file/)
+ const {
+ container
+ } = render(
)
+ expect(container.textContent).toMatch(/Download file/)
})
it("should render Download file link for non-empty text response", function () {
@@ -50,14 +65,18 @@ describe("
", function () {
props.headers = {
"Content-Disposition": "attachment; filename=\"test.txt\"",
}
- const wrapper = shallow(
)
- expect(wrapper.text()).toMatch(/Download file/)
+ const {
+ container
+ } = render(
)
+ expect(container.textContent).toMatch(/Download file/)
})
it("should not render Download file link for empty response", function () {
props.contentType = "application/octet-stream"
props.content = new Blob()
- const wrapper = shallow(
)
- expect(wrapper.text()).not.toMatch(/Download file/)
+ const {
+ container
+ } = render(
)
+ expect(container.textContent).not.toMatch(/Download file/)
})
})
diff --git a/test/unit/components/version-pragma-filter.jsx b/test/unit/components/version-pragma-filter.jsx
index 2a08ea1cebc..4f48b90b82a 100644
--- a/test/unit/components/version-pragma-filter.jsx
+++ b/test/unit/components/version-pragma-filter.jsx
@@ -1,67 +1,77 @@
+import { render } from "@testing-library/react"
import React from "react"
-import { shallow } from "enzyme"
import VersionPragmaFilter from "core/components/version-pragma-filter"
describe("
", function(){
it("renders children for a Swagger 2 definition", function(){
// When
- let wrapper = shallow(
+ let {
+ container
+ } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(container.querySelectorAll("div").length).toEqual(1)
+ expect(container.querySelector("div").textContent).toEqual("hello!")
})
it("renders children for an OpenAPI 3 definition", function(){
// When
- let wrapper = shallow(
+ let {
+ container
+ } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(container.querySelectorAll("div").length).toEqual(1)
+ expect(container.querySelector("div").textContent).toEqual("hello!")
})
it("renders children when a bypass prop is set", function(){
// When
- let wrapper = shallow(
+ let {
+ container
+ } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(container.querySelectorAll("div").length).toEqual(1)
+ expect(container.querySelector("div").textContent).toEqual("hello!")
})
it("renders the correct message for an ambiguous-version definition", function(){
// When
- let wrapper = shallow(
+ let {
+ container
+ } = render(
hello!
)
// Then
- expect(wrapper.find("div.version-pragma__message--ambiguous").length).toEqual(1)
- expect(wrapper.find("div.version-pragma__message--missing").length).toEqual(0)
+ expect(container.querySelectorAll("div.version-pragma__message--ambiguous").length).toEqual(1)
+ expect(container.querySelectorAll("div.version-pragma__message--missing").length).toEqual(0)
})
it("renders the correct message for a missing-version definition", function(){
// When
- let wrapper = shallow(
+ let {
+ container
+ } = render(
hello!
)
// Then
- expect(wrapper.find("div.version-pragma__message--missing").length).toEqual(1)
- expect(wrapper.find("div.version-pragma__message--ambiguous").length).toEqual(0)
+ expect(container.querySelectorAll("div.version-pragma__message--missing").length).toEqual(1)
+ expect(container.querySelectorAll("div.version-pragma__message--ambiguous").length).toEqual(0)
})
-})
+})
\ No newline at end of file
diff --git a/test/unit/core/plugins/json-schema-5/components/json-schema-form.jsx b/test/unit/core/plugins/json-schema-5/components/json-schema-form.jsx
index 488589dc724..940c2dfb8b3 100644
--- a/test/unit/core/plugins/json-schema-5/components/json-schema-form.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/json-schema-form.jsx
@@ -1,7 +1,7 @@
import React from "react"
import Immutable, { List } from "immutable"
import { Select, Input, TextArea } from "core/components/layout-utils"
-import { mount, render } from "enzyme"
+import { render } from "@testing-library/react"
import * as JsonSchemaComponents from "core/plugins/json-schema-5/components/json-schema-components"
const components = {...JsonSchemaComponents, Select, Input, TextArea}
@@ -30,11 +30,11 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("select")
- expect(wrapper.find("option").length).toEqual(3)
- expect(wrapper.find("option").eq(0).text()).toEqual("--")
- expect(wrapper.find("option").eq(1).text()).toEqual("one")
- expect(wrapper.find("option").eq(2).text()).toEqual("two")
+ expect(wrapper.getByRole("combobox")).toBeInTheDocument()
+ expect(wrapper.getAllByRole("option").length).toEqual(3)
+ expect(wrapper.getByRole("option", { name: "--" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "one" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "two" })).toBeInTheDocument()
})
it("should render a string enum as disabled when JsonSchemaForm is disabled", function(){
@@ -54,7 +54,7 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.attr("disabled")).toEqual("disabled")
+ expect(wrapper.getByRole("combobox")).toBeDisabled()
})
@@ -75,10 +75,10 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("select")
- expect(wrapper.find("select option").length).toEqual(2)
- expect(wrapper.find("select option").eq(0).text()).toEqual("one")
- expect(wrapper.find("select option").eq(1).text()).toEqual("two")
+ expect(wrapper.getByRole("combobox")).toBeInTheDocument()
+ expect(wrapper.getAllByRole("option").length).toEqual(2)
+ expect(wrapper.getByRole("option", { name: "one" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "two" })).toBeInTheDocument()
})
})
describe("booleans", function() {
@@ -97,11 +97,11 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("select")
- expect(wrapper.find("select option").length).toEqual(3)
- expect(wrapper.find("select option").eq(0).text()).toEqual("--")
- expect(wrapper.find("select option").eq(1).text()).toEqual("true")
- expect(wrapper.find("select option").eq(2).text()).toEqual("false")
+ expect(wrapper.getByRole("combobox")).toBeInTheDocument()
+ expect(wrapper.getAllByRole("option").length).toEqual(3)
+ expect(wrapper.getByRole("option", { name: "--" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "true" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "false" })).toBeInTheDocument()
})
@@ -121,11 +121,11 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("select")
- expect(wrapper.find("select option").length).toEqual(2)
- expect(wrapper.find("select option").eq(0).text()).toEqual("--")
- expect(wrapper.find("select option").eq(1).text()).toEqual("true")
- expect(wrapper.find("select option:checked").first().text()).toEqual("--")
+ expect(wrapper.getByRole("combobox")).toBeInTheDocument()
+ expect(wrapper.getAllByRole("option").length).toEqual(2)
+ expect(wrapper.getByRole("option", { name: "--" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "true" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "--" }).selected).toBe(true)
})
it("should render the correct options for a required boolean parameter", function(){
@@ -144,12 +144,12 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("select")
- expect(wrapper.find("select option").length).toEqual(3)
- expect(wrapper.find("select option").eq(0).text()).toEqual("--")
- expect(wrapper.find("select option").eq(1).text()).toEqual("true")
- expect(wrapper.find("select option").eq(2).text()).toEqual("false")
- expect(wrapper.find("select option:checked").first().text()).toEqual("--")
+ expect(wrapper.getByRole("combobox")).toBeInTheDocument()
+ expect(wrapper.getAllByRole("option").length).toEqual(3)
+ expect(wrapper.getByRole("option", { name: "--" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "true" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "false" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "--" }).selected).toBe(true)
})
it("should render the correct options for a required enum boolean parameter", function(){
@@ -169,10 +169,10 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("select")
- expect(wrapper.find("select option").length).toEqual(1)
- expect(wrapper.find("select option").eq(0).text()).toEqual("true")
- expect(wrapper.find("select option:checked").first().text()).toEqual("true")
+ expect(wrapper.getByRole("combobox")).toBeInTheDocument()
+ expect(wrapper.getAllByRole("option").length).toEqual(1)
+ expect(wrapper.getByRole("option", { name: "true" })).toBeInTheDocument()
+ expect(wrapper.getByRole("option", { name: "true" }).selected).toBe(true)
})
})
describe("objects", function() {
@@ -199,15 +199,15 @@ describe("
", function(){
})
}
- let wrapper = mount(
)
+ let wrapper = render(
)
- updateQueue.forEach(newProps => wrapper.setProps(newProps))
+ updateQueue.forEach(newProps => wrapper.rerender(
))
- expect(wrapper.find("textarea").length).toEqual(1)
- expect(wrapper.find("textarea").text()).toEqual(`{\n "id": "abc123"\n}`)
+ expect(wrapper.getByRole("textbox")).toBeInTheDocument()
+ expect(wrapper.getByRole("textbox").value).toEqual(`{\n "id": "abc123"\n}`)
})
})
- describe("unknown types", function() {
+ describe.only("unknown types", function() {
it("should render unknown types as strings", function(){
let props = {
@@ -224,8 +224,8 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.length).toEqual(1)
- expect(wrapper.get(0).name).toEqual("input")
+ expect(wrapper.getByRole("textbox")).toBeInTheDocument()
+ expect(wrapper.getByRole("textbox").value).toEqual("yo")
// expect(wrapper.find("select input").length).toEqual(1)
// expect(wrapper.find("select option").first().text()).toEqual("true")
})
@@ -247,8 +247,8 @@ describe("
", function(){
let wrapper = render(
)
- expect(wrapper.length).toEqual(1)
- expect(wrapper.get(0).name).toEqual("input")
+ expect(wrapper.getByRole("textbox")).toBeInTheDocument()
+ expect(wrapper.getByRole("textbox").value).toEqual("yo")
// expect(wrapper.find("select input").length).toEqual(1)
// expect(wrapper.find("select option").first().text()).toEqual("true")
})
diff --git a/test/unit/core/plugins/json-schema-5/components/model-example.jsx b/test/unit/core/plugins/json-schema-5/components/model-example.jsx
index 737be87af9b..36e31ea83da 100644
--- a/test/unit/core/plugins/json-schema-5/components/model-example.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/model-example.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import ModelExample from "core/plugins/json-schema-5/components/model-example"
import ModelComponent from "core/plugins/json-schema-5/components/model-wrapper"
@@ -20,7 +20,8 @@ describe("
", function(){
beforeEach(() => {
components = {
- ModelWrapper: ModelComponent
+ ModelWrapper: ModelComponent,
+ Model: ({expandDepth}) =>
,
}
props = {
@@ -43,20 +44,20 @@ describe("
", function(){
it("renders model and example tabs", function(){
// When
- let wrapper = shallow(
)
+ let wrapper = render(
)
// Then should render tabs
- expect(wrapper.find("div > ul.tab").length).toEqual(1)
+ expect(wrapper.getByRole("tablist")).toBeInTheDocument()
- let tabs = wrapper.find("div > ul.tab").children()
+ let tabs = wrapper.getAllByRole("tab")
expect(tabs.length).toEqual(2)
tabs.forEach((node) => {
- expect(node.length).toEqual(1)
- expect(node.name()).toEqual("li")
- expect(node.hasClass("tabitem")).toEqual(true)
+ expect(node).toBeInTheDocument()
+ expect(node.tagName).toEqual("BUTTON")
+ expect(node).toHaveClass("tablinks")
})
- expect(tabs.at(0).text()).toEqual("Example Value")
- expect(tabs.at(1).text()).toEqual("Model")
+ expect(tabs[0]).toHaveTextContent("Example Value")
+ expect(tabs[1]).toHaveTextContent("Model")
})
exampleSelectedTestInputs.forEach(function(testInputs) {
@@ -67,18 +68,18 @@ describe("
", function(){
defaultModelRendering: testInputs.defaultModelRendering,
defaultModelExpandDepth: 1
})
- let wrapper = shallow(
)
+ let wrapper = render(
)
// Then
- let tabs = wrapper.find("div > ul.tab").children()
+ let tabs = wrapper.getAllByRole("tab")
- let exampleTab = tabs.at(0)
- expect(exampleTab.hasClass("active")).toEqual(true)
- let modelTab = tabs.at(1)
- expect(modelTab.hasClass("active")).toEqual(false)
+ let exampleTab = tabs[0]
+ expect(exampleTab.parentElement).toHaveClass("active")
+ let modelTab = tabs[1]
+ expect(modelTab.parentElement).not.toHaveClass("active")
- expect(wrapper.find("div > div").length).toEqual(1)
- expect(wrapper.find("div > div").text()).toEqual(props.example)
+ expect(wrapper.getByRole("tabpanel")).toBeInTheDocument()
+ expect(wrapper.getByRole("tabpanel")).toHaveTextContent(props.example)
})
})
@@ -90,18 +91,18 @@ describe("
", function(){
defaultModelRendering: testInputs.defaultModelRendering,
defaultModelExpandDepth: 1
})
- let wrapper = shallow(
)
+ let wrapper = render(
)
// Then
- let tabs = wrapper.find("div > ul.tab").children()
+ let tabs = wrapper.getAllByRole("tab")
- let exampleTab = tabs.at(0)
- expect(exampleTab.hasClass("active")).toEqual(false)
- let modelTab = tabs.at(1)
- expect(modelTab.hasClass("active")).toEqual(true)
+ let exampleTab = tabs[0]
+ expect(exampleTab.parentElement).not.toHaveClass("active")
+ let modelTab = tabs[1]
+ expect(modelTab.parentElement).toHaveClass("active")
- expect(wrapper.find("div > div").length).toEqual(1)
- expect(wrapper.find("div > div").find(ModelComponent).props().expandDepth).toBe(1)
+ expect(wrapper.getByRole("tabpanel")).toBeInTheDocument()
+ expect(wrapper.getByRole("tabpanel").querySelector("[data-expand-depth='1']")).toBeInTheDocument()
})
})
@@ -113,10 +114,10 @@ describe("
", function(){
defaultModelRendering: "model",
defaultModelExpandDepth: expandDepth
})
- let wrapper = shallow(
)
+ let wrapper = render(
)
// Then
- expect(wrapper.find("div > div").find(ModelComponent).props().expandDepth).toBe(expandDepth)
+ expect(wrapper.getByRole("tabpanel").querySelector("[data-expand-depth='0']")).toBeInTheDocument()
})
})
diff --git a/test/unit/core/plugins/json-schema-5/components/models.jsx b/test/unit/core/plugins/json-schema-5/components/models.jsx
index 3203f486376..6f65b3a2613 100644
--- a/test/unit/core/plugins/json-schema-5/components/models.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/models.jsx
@@ -1,17 +1,20 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS, Map } from "immutable"
import Models from "core/plugins/json-schema-5/components/models"
-import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
-import ModelComponent from "core/plugins/json-schema-5/components/model-wrapper"
describe("
", function(){
- const dummyComponent = () => null
+ const makeDummyComponent = (name) =>
+ ({children, expandDepth}) =>
{children}
// Given
let components = {
- Collapse: ModelCollapse,
- ModelWrapper: ModelComponent,
- JumpToPath: dummyComponent,
+ Collapse: makeDummyComponent("Collapse"),
+ ModelWrapper: makeDummyComponent("ModelWrapper"),
+ JumpToPath: makeDummyComponent("JumpToPath"),
+ Model: makeDummyComponent("Model"),
+ ModelCollapse: makeDummyComponent("ModelCollapse"),
+ ArrowUpIcon: makeDummyComponent("ArrowUpIcon"),
+ ArrowDownIcon: makeDummyComponent("ArrowDownIcon")
}
let props = {
getComponent: (c) => {
@@ -31,7 +34,9 @@ describe("
", function(){
layoutSelectors: {
isShown: jest.fn()
},
- layoutActions: {},
+ layoutActions: {
+ readyToScroll: jest.fn()
+ },
getConfigs: () => ({
docExpansion: "list",
defaultModelsExpandDepth: 0
@@ -41,13 +46,13 @@ describe("
", function(){
it("passes defaultModelsExpandDepth to ModelWrapper", function(){
// When
- let wrapper = shallow(
)
+ const { getAllByTestId } = render(
)
// Then should render tabs
- expect(wrapper.find("ModelCollapse").length).toEqual(1)
- expect(wrapper.find("ModelWrapper").length).toBeGreaterThan(0)
- wrapper.find("ModelComponent").forEach((modelWrapper) => {
- expect(modelWrapper.props().expandDepth).toBe(0)
+ expect(getAllByTestId("Collapse").length).toEqual(1)
+ expect(getAllByTestId("ModelWrapper").length).toBeGreaterThan(0)
+ getAllByTestId("ModelWrapper").forEach((modelWrapper) => {
+ expect(modelWrapper.getAttribute("data-expand-depth")).toBe("0")
})
})
diff --git a/test/unit/core/plugins/json-schema-5/components/object-model.jsx b/test/unit/core/plugins/json-schema-5/components/object-model.jsx
index 9f4c5f72382..4dd69b5d22e 100644
--- a/test/unit/core/plugins/json-schema-5/components/object-model.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/object-model.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import { List } from "immutable"
import ObjectModel from "core/plugins/json-schema-5/components/object-model"
// import ModelExample from "core/components/model-example"
@@ -9,6 +9,12 @@ import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
import Property from "core/components/property"
// import { inferSchema } from "core/plugins/samples/fn"
+jest.mock("core/plugins/json-schema-5/components/model-collapse", () => ({children}) =>
{children}
)
+jest.mock("core/plugins/json-schema-5/components/model", () =>
+ ({ schema }) =>
+)
+jest.mock("core/components/property", () => ({propKey, propVal}) =>
)
+
describe("
", function() {
const dummyComponent = () => null
const components = {
@@ -63,47 +69,47 @@ describe("
", function() {
}
it("renders a collapsible header", function(){
- const wrapper = shallow(
)
- const renderedModelCollapse = wrapper.find(ModelCollapse)
- expect(renderedModelCollapse.length).toEqual(1)
+ const { queryAllByTestId } = render(
)
+ expect(queryAllByTestId("model-collapse").length).toEqual(1)
})
it("renders the object properties in order", function() {
- const wrapper = shallow(
)
- const renderedModel = wrapper.find(Model)
+ const { queryAllByTestId } = render(
)
+ const renderedModel = queryAllByTestId("model")
expect(renderedModel.length).toEqual(3)
- expect(renderedModel.get(0).props.schema.get("name")).toEqual("c")
- expect(renderedModel.get(1).props.schema.get("name")).toEqual("b")
- expect(renderedModel.get(2).props.schema.get("name")).toEqual("a")
+ expect(renderedModel[0].getAttribute("data-name")).toEqual("c")
+ expect(renderedModel[1].getAttribute("data-name")).toEqual("b")
+ expect(renderedModel[2].getAttribute("data-name")).toEqual("a")
+
})
it("doesn't render `nullable` for model when it absent", function() {
- const wrapper = shallow(
)
- const renderProperties = wrapper.find(Property)
- expect(renderProperties.length).toEqual(0)
+ const { queryAllByTestId } = render(
)
+ const renderedProperties = queryAllByTestId("property")
+ expect(renderedProperties.length).toEqual(0)
})
it("renders `nullable` for model", function() {
- const wrapper = shallow(
)
- const renderProperties = wrapper.find(Property)
- expect(renderProperties.length).toEqual(1)
- expect(renderProperties.get(0).props.propKey).toEqual("nullable")
- expect(renderProperties.get(0).props.propVal).toEqual(true)
+ const { queryAllByTestId } = render(
)
+ const renderedProperties = queryAllByTestId("property")
+ expect(renderedProperties.length).toEqual(1)
+ expect(renderedProperties[0].getAttribute("data-propkey")).toEqual("nullable")
+ expect(renderedProperties[0].getAttribute("data-propval")).toEqual("true")
})
it("doesn't render `minProperties` and `maxProperties` if they are absent", function() {
- const wrapper = shallow(
)
- const renderProperties = wrapper.find(Property)
- expect(renderProperties.length).toEqual(0)
+ const { queryAllByTestId } = render(
)
+ const renderedProperties = queryAllByTestId("property")
+ expect(renderedProperties.length).toEqual(0)
})
it("renders `minProperties` and `maxProperties` if they are defined", function() {
- const wrapper = shallow(
)
- const renderProperties = wrapper.find(Property)
+ const { queryAllByTestId } = render(
)
+ const renderProperties = queryAllByTestId("property")
expect(renderProperties.length).toEqual(2)
- expect(renderProperties.get(0).props.propKey).toEqual("minProperties")
- expect(renderProperties.get(0).props.propVal).toEqual(1)
- expect(renderProperties.get(1).props.propKey).toEqual("maxProperties")
- expect(renderProperties.get(1).props.propVal).toEqual(5)
+ expect(renderProperties[0].getAttribute("data-propkey")).toEqual("minProperties")
+ expect(renderProperties[0].getAttribute("data-propval")).toEqual("1")
+ expect(renderProperties[1].getAttribute("data-propkey")).toEqual("maxProperties")
+ expect(renderProperties[1].getAttribute("data-propval")).toEqual("5")
})
})
diff --git a/test/unit/core/plugins/json-schema-5/components/primitive-model.jsx b/test/unit/core/plugins/json-schema-5/components/primitive-model.jsx
index 6fd3d529b2b..c0d293dc6a8 100644
--- a/test/unit/core/plugins/json-schema-5/components/primitive-model.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/primitive-model.jsx
@@ -1,9 +1,21 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS } from "immutable"
import PrimitiveModel from "core/plugins/json-schema-5/components/primitive-model"
import ModelCollapse from "core/plugins/json-schema-5/components/model-collapse"
+jest.mock(
+ "core/plugins/json-schema-5/components/model-collapse",
+ () => ({ children, title }) => (
+
+
+ {title}
+
+ {children}
+
+ )
+)
+
describe("
", function () {
const dummyComponent = () => null
const components = {
@@ -28,10 +40,11 @@ describe("
", function () {
it("renders the schema's title", function () {
// When
- const wrapper = shallow(
)
- const modelTitleEl = wrapper.find("ModelCollapse").prop("title").props.children.props.children
-
- expect(modelTitleEl).toEqual("Custom model title")
+ const { getByTestId } = render(
)
+ const renderedModelCollapse = getByTestId("model-collapse")
+ const renderedModelCollapseTitle = getByTestId("model-collapse-title")
+ expect(renderedModelCollapse).toContainElement(renderedModelCollapseTitle)
+ expect(renderedModelCollapseTitle).toHaveTextContent("Custom model title")
})
it("falls back to the passed-in `name` prop for the title", function () {
@@ -39,17 +52,17 @@ describe("
", function () {
props.schema = fromJS({
type: "string"
})
- const wrapper = shallow(
)
- const modelTitleEl = wrapper.find("ModelCollapse").prop("title").props.children.props.children
-
- // Then
- expect(modelTitleEl).toEqual("Name from props")
-
+ const { getByTestId } = render(
)
+ const renderedModelCollapse = getByTestId("model-collapse")
+ const renderedModelCollapseTitle = getByTestId("model-collapse-title")
+ expect(renderedModelCollapse).toContainElement(renderedModelCollapseTitle)
+ expect(renderedModelCollapseTitle).toHaveTextContent("Name from props")
})
it("renders a collapsible header", function(){
- const wrapper = shallow(
)
- const renderedModelCollapse = wrapper.find(ModelCollapse)
- expect(renderedModelCollapse.length).toEqual(1)
+ const { getByTestId } = render(
)
+ const renderedModelCollapse = getByTestId("model-collapse")
+
+ expect(renderedModelCollapse).toBeInTheDocument()
})
})
diff --git a/test/unit/core/plugins/json-schema-5/components/response.jsx b/test/unit/core/plugins/json-schema-5/components/response.jsx
index f5eed6a0edb..545fedd9b70 100644
--- a/test/unit/core/plugins/json-schema-5/components/response.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/response.jsx
@@ -2,7 +2,7 @@
* @prettier
*/
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS, List } from "immutable"
import Response from "core/components/response"
@@ -17,6 +17,10 @@ import makeGetJsonSampleSchema from "core/plugins/json-schema-5-samples/fn/get-j
import makeGetYamlSampleSchema from "core/plugins/json-schema-5-samples/fn/get-yaml-sample-schema"
import makeGetXmlSampleSchema from "core/plugins/json-schema-5-samples/fn/get-xml-sample-schema"
+jest.mock("core/plugins/json-schema-5/components/model-example", () => jest.fn(() => null))
+
+const MockModelExample = jest.requireMock("core/plugins/json-schema-5/components/model-example")
+
describe("
", function () {
const dummyComponent = () => null
const components = {
@@ -26,6 +30,14 @@ describe("
", function () {
Markdown: dummyComponent,
operationLink: dummyComponent,
contentType: dummyComponent,
+ ResponseExtension: dummyComponent,
+ Headers: dummyComponent,
+ HighlightCode: dummyComponent,
+ ModelExample: dummyComponent,
+ OperationLink: dummyComponent,
+ ContentType: dummyComponent,
+ ExamplesSelect: dummyComponent,
+ Example: dummyComponent,
}
const getSystem = () => ({
getComponent: (c) => components[c],
@@ -73,14 +85,15 @@ describe("
", function () {
}
it("renders the model-example schema properties in order", function () {
- const wrapper = shallow(
)
- const renderedModelExample = wrapper.find(ModelExample)
+ MockModelExample.mockImplementation(
+ ({ schema }) =>
+ )
+
+ const wrapper = render(
)
+ const renderedModelExample = wrapper.queryAllByTestId("model-example")
expect(renderedModelExample.length).toEqual(1)
// Assert the schema's properties have maintained their order
- const modelExampleSchemaProperties = renderedModelExample
- .props()
- .schema.toJS().properties
- expect(Object.keys(modelExampleSchemaProperties)).toEqual(["c", "b", "a"])
+ expect(renderedModelExample[0].getAttribute("data-schema-props")).toEqual("c,b,a")
})
})
diff --git a/test/unit/core/plugins/json-schema-5/components/schemes-wrapper.jsx b/test/unit/core/plugins/json-schema-5/components/schemes-wrapper.jsx
index 55352232286..4f45d95c202 100644
--- a/test/unit/core/plugins/json-schema-5/components/schemes-wrapper.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/schemes-wrapper.jsx
@@ -1,9 +1,12 @@
import React from "react"
-import { mount } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS } from "immutable"
import SchemesContainer from "core/plugins/json-schema-5/containers/schemes"
import Schemes from "core/plugins/json-schema-5/components/schemes"
import { Col } from "core/components/layout-utils"
+import { jest } from "@jest/globals"
+
+jest.mock("core/plugins/json-schema-5/components/schemes", () => () =>
)
describe("
", function(){
@@ -23,22 +26,6 @@ describe("
", function(){
},
getComponent: c => components[c]
}
- const twoSecurityDefinitions = {
- "petstore_auth": {
- "type": "oauth2",
- "authorizationUrl": "http://petstore.swagger.io/oauth/dialog",
- "flow": "implicit",
- "scopes": {
- "write:pets": "modify pets in your account",
- "read:pets": "read your pets"
- }
- },
- "api_key": {
- "type": "apiKey",
- "name": "api_key",
- "in": "header"
- }
- }
it("renders Schemes inside SchemesContainer if schemes are provided", function(){
@@ -49,11 +36,10 @@ describe("
", function(){
props.specSelectors.schemes = function() {return fromJS(["http", "https"])}
// When
- let wrapper = mount(
)
+ const { queryByTestId } = render(
)
// Then
- const renderedSchemes = wrapper.find(Schemes)
- expect(renderedSchemes.length).toEqual(1)
+ expect(queryByTestId("schemes")).toBeInTheDocument()
})
it("does not render Schemes inside SchemeWrapper if empty array of schemes is provided", function(){
@@ -64,11 +50,10 @@ describe("
", function(){
props.specSelectors.schemes = function() {return fromJS([])}
// When
- let wrapper = mount(
)
+ const { queryByTestId } = render(
)
// Then
- const renderedSchemes = wrapper.find(Schemes)
- expect(renderedSchemes.length).toEqual(0)
+ expect(queryByTestId("schemes")).not.toBeInTheDocument()
})
it("does not render Schemes inside SchemeWrapper if provided schemes are undefined", function(){
@@ -79,10 +64,9 @@ describe("
", function(){
props.specSelectors.schemes = function() {return undefined}
// When
- let wrapper = mount(
)
+ const { queryByTestId } = render(
)
// Then
- const renderedSchemes = wrapper.find(Schemes)
- expect(renderedSchemes.length).toEqual(0)
+ expect(queryByTestId("schemes")).not.toBeInTheDocument()
})
})
diff --git a/test/unit/core/plugins/json-schema-5/components/schemes.jsx b/test/unit/core/plugins/json-schema-5/components/schemes.jsx
index 9709419a765..b384d216dc4 100644
--- a/test/unit/core/plugins/json-schema-5/components/schemes.jsx
+++ b/test/unit/core/plugins/json-schema-5/components/schemes.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS } from "immutable"
import Schemes from "core/plugins/json-schema-5/components/schemes"
@@ -23,7 +23,7 @@ describe("
", function(){
}
// When
- let wrapper = shallow(
)
+ let wrapper = render(
)
// Then currentScheme should default to first scheme in options list
expect(props.specActions.setScheme).toHaveBeenCalledWith("http", "/test" , "get")
@@ -32,7 +32,7 @@ describe("
", function(){
props.schemes = fromJS([
"https"
])
- wrapper.setProps(props)
+ wrapper.rerender(
)
// Then currentScheme should default to first scheme in options list, again
expect(props.specActions.setScheme).toHaveBeenCalledWith("https", "/test", "get")
@@ -55,13 +55,13 @@ describe("
", function(){
}
// When
- let wrapper = shallow(
)
+ let wrapper = render(
)
// Should be called initially, to set the global state
expect(setSchemeSpy.mock.calls.length).toEqual(1)
// After an update
- wrapper.instance().UNSAFE_componentWillReceiveProps(props)
+ wrapper.rerender(
)
// Should not be called again, since `currentScheme` is in schemes
expect(setSchemeSpy.mock.calls.length).toEqual(1)
diff --git a/test/unit/core/plugins/oas3/servers-wrapper.jsx b/test/unit/core/plugins/oas3/servers-wrapper.jsx
index 7eb6724c061..e9a3465cdc6 100644
--- a/test/unit/core/plugins/oas3/servers-wrapper.jsx
+++ b/test/unit/core/plugins/oas3/servers-wrapper.jsx
@@ -1,10 +1,12 @@
-
import React from "react"
-import { mount } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS } from "immutable"
import ServersContainer from "core/plugins/oas3/components/servers-container"
import Servers from "core/plugins/oas3/components/servers"
import { Col } from "core/components/layout-utils"
+import { jest } from "@jest/globals"
+
+jest.mock("core/plugins/oas3/components/servers", () => () =>
)
describe("
", function(){
@@ -38,11 +40,10 @@ describe("
", function(){
props.oas3Selectors.selectedServer = function() {return "http://server1.com"}
// When
- let wrapper = mount(
)
+ const { queryByTestId } = render(
)
// Then
- const renderedServers = wrapper.find(Servers)
- expect(renderedServers.length).toEqual(1)
+ expect(queryByTestId("servers")).toBeInTheDocument()
})
it("does not render Servers inside ServersContainer if servers are empty", function(){
@@ -53,11 +54,10 @@ describe("
", function(){
props.specSelectors.servers = function() {return fromJS([])}
// When
- let wrapper = mount(
)
+ const { queryByTestId } = render(
)
// Then
- const renderedServers = wrapper.find(Servers)
- expect(renderedServers.length).toEqual(0)
+ expect(queryByTestId("servers")).not.toBeInTheDocument()
})
it("does not render Servers inside ServersContainer if servers are undefined", function(){
@@ -66,10 +66,9 @@ describe("
", function(){
let props = {...mockedProps}
// When
- let wrapper = mount(
)
+ const { queryByTestId } = render(
)
// Then
- const renderedServers = wrapper.find(Servers)
- expect(renderedServers.length).toEqual(0)
+ expect(queryByTestId("servers")).not.toBeInTheDocument()
})
})
diff --git a/test/unit/core/plugins/oas31/components/version-pragma-filter.jsx b/test/unit/core/plugins/oas31/components/version-pragma-filter.jsx
index b85b657c2b8..de99a393e1f 100644
--- a/test/unit/core/plugins/oas31/components/version-pragma-filter.jsx
+++ b/test/unit/core/plugins/oas31/components/version-pragma-filter.jsx
@@ -1,84 +1,79 @@
import React from "react"
-import { shallow } from "enzyme"
+import { render } from "@testing-library/react"
import VersionPragmaFilter from "core/plugins/oas31/components/version-pragma-filter"
describe("
", function(){
it("renders children for a Swagger 2 definition", function(){
// When
- let wrapper = shallow(
+ const { getByText } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(getByText("hello!")).toBeInTheDocument()
})
it("renders children for an OpenAPI 3.0.x definition", function(){
// When
- let wrapper = shallow(
+ const { getByText } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(getByText("hello!")).toBeInTheDocument()
})
it("renders children for an OpenAPI 3.1.0 definition", function(){
// When
- let wrapper = shallow(
+ const { getByText } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(getByText("hello!")).toBeInTheDocument()
})
it("renders children when a bypass prop is set", function(){
// When
- let wrapper = shallow(
+ const { getByText } = render(
hello!
)
// Then
- expect(wrapper.find("div").length).toEqual(1)
- expect(wrapper.find("div").text()).toEqual("hello!")
+ expect(getByText("hello!")).toBeInTheDocument()
})
it("renders the correct message for an ambiguous-version definition", function(){
// When
- let wrapper = shallow(
+ const { container } = render(
hello!
)
// Then
- expect(wrapper.find("div.version-pragma__message--ambiguous").length).toEqual(1)
- expect(wrapper.find("div.version-pragma__message--missing").length).toEqual(0)
+ expect(container.querySelector("div.version-pragma__message--ambiguous")).toBeInTheDocument()
+ expect(container.querySelector("div.version-pragma__message--missing")).not.toBeInTheDocument()
})
it("renders the correct message for a missing-version definition", function(){
// When
- let wrapper = shallow(
+ const { container } = render(
hello!
)
// Then
- expect(wrapper.find("div.version-pragma__message--missing").length).toEqual(1)
- expect(wrapper.find("div.version-pragma__message--ambiguous").length).toEqual(0)
+ expect(container.querySelector("div.version-pragma__message--missing")).toBeInTheDocument()
+ expect(container.querySelector("div.version-pragma__message--ambiguous")).not.toBeInTheDocument()
})
-
})
diff --git a/test/unit/core/plugins/safe-render/index.jsx b/test/unit/core/plugins/safe-render/index.jsx
index 34d2c69394a..12dc1e17bb6 100644
--- a/test/unit/core/plugins/safe-render/index.jsx
+++ b/test/unit/core/plugins/safe-render/index.jsx
@@ -1,9 +1,7 @@
import React from "react"
-import { mount } from "enzyme"
-import sinon from "sinon"
+import { render, screen } from "@testing-library/react"
import { Provider } from "react-redux"
import noop from "lodash/noop"
-
import System from "core/system"
import ViewPlugin from "core/plugins/view"
import SafeRenderPlugin from "core/plugins/safe-render"
@@ -18,7 +16,7 @@ describe("safe-render", function() {
it("should catch errors thrown inside of React Component class render method", function() {
class BrokenComponent extends React.Component {
render() {
- return null
+ throw new Error("broken")
}
}
const BrokenComponentPlugin = () => {
@@ -42,16 +40,14 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent")
- const wrapper = mount(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(wrapper.text()).toEqual("😱 Could not render BrokenComponent, see the console.")
+ const {container} = render(
)
+ expect(container).toHaveTextContent("😱 Could not render BrokenComponent, see the console.")
})
it("should catch errors thrown inside of PureComponent class render method", function() {
class BrokenComponent extends React.PureComponent {
render() {
- return null
+ throw new Error("broken")
}
}
const BrokenComponentPlugin = () => {
@@ -75,14 +71,12 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent")
- const wrapper = mount(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(wrapper.text()).toEqual("😱 Could not render BrokenComponent, see the console.")
+ const {container} = render(
)
+ expect(container).toHaveTextContent("😱 Could not render BrokenComponent, see the console.")
})
it("should catch errors thrown inside of function component", function() {
- const BrokenComponent = () => null
+ const BrokenComponent = () => { throw new Error("broken") }
const BrokenComponentPlugin = () => {
return {
components: {
@@ -104,16 +98,14 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent")
- const wrapper = mount(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(wrapper.text()).toEqual("😱 Could not render BrokenComponent, see the console.")
+ const {container} = render(
)
+ expect(container).toHaveTextContent("😱 Could not render BrokenComponent, see the console.")
})
it("should catch errors thrown inside of container created from React Component class", function() {
class BrokenComponent extends React.Component {
render() {
- return null
+ throw new Error("broken")
}
}
const BrokenComponentPlugin = () => {
@@ -137,18 +129,16 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent", true)
- const wrapper = mount(
+ const {container} = render(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(wrapper.text()).toEqual("😱 Could not render BrokenComponent, see the console.")
+ expect(container).toHaveTextContent("😱 Could not render BrokenComponent, see the console.")
})
it("should catch errors thrown inside of container created from function component", function() {
- const BrokenComponent = () => null
+ const BrokenComponent = () => { throw new Error("broken") }
const BrokenComponentPlugin = () => {
return {
components: {
@@ -170,18 +160,16 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent", true)
- const wrapper = mount(
+ const {container} = render(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(wrapper.text()).toEqual("😱 Could not render BrokenComponent, see the console.")
+ expect(container).toHaveTextContent("😱 Could not render BrokenComponent, see the console.")
})
it("should render custom Fallback component", function() {
- const BrokenComponent = () => null
+ const BrokenComponent = () => { throw new Error("broken") }
const BrokenComponentPlugin = () => {
return {
components: {
@@ -209,15 +197,13 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent")
- const wrapper = mount(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(wrapper.text()).toEqual("fallback component")
+ const {container} = render(
)
+ expect(container).toHaveTextContent("fallback component")
})
it("should call custom componentDidCatch hook", function() {
- const BrokenComponent = () => null
- const componentDidCatch = sinon.spy()
+ const BrokenComponent = () => { throw new Error("broken") }
+ const componentDidCatch = jest.fn()
const BrokenComponentPlugin = () => {
return {
@@ -245,9 +231,7 @@ describe("safe-render", function() {
})
const SafeBrokenComponent = system.getSystem().getComponent("BrokenComponent")
- const wrapper = mount(
)
- wrapper.find(BrokenComponent).simulateError(new Error("error"))
-
- expect(componentDidCatch.calledOnce).toBe(true)
+ render(
)
+ expect(componentDidCatch).toHaveBeenCalled()
})
})
diff --git a/test/unit/core/system/system.jsx b/test/unit/core/system/system.jsx
index 507983bc1df..1a21eac6e60 100644
--- a/test/unit/core/system/system.jsx
+++ b/test/unit/core/system/system.jsx
@@ -1,6 +1,6 @@
import React, { PureComponent } from "react"
import { fromJS } from "immutable"
-import { render, mount } from "enzyme"
+import { render } from "@testing-library/react"
import { Provider } from "react-redux"
import System from "core/system"
@@ -479,8 +479,8 @@ describe("bound system", function(){
// When
let Component = system.getSystem().getComponent("test")
- const renderedComponent = render(
)
- expect(renderedComponent.text()).toEqual("Test component")
+ const { getByText } = render(
)
+ expect(getByText("Test component")).toBeInTheDocument()
})
it("allows container components to provide their own `mapStateToProps` function", function() {
@@ -525,14 +525,14 @@ describe("bound system", function(){
// When
let Component = system.getSystem().getComponent("ContainerComponent", true)
- const renderedComponent = render(
+ const { getByText } = render(
)
// Then
- expect(renderedComponent.text()).toEqual("This came from mapStateToProps and this came from the system and this came from my own props")
+ expect(getByText("This came from mapStateToProps and this came from the system and this came from my own props")).toBeInTheDocument()
})
it("gives the system and own props as props to a container's `mapStateToProps` function", function() {
@@ -578,14 +578,14 @@ describe("bound system", function(){
// When
let Component = system.getSystem().getComponent("ContainerComponent", true)
- const renderedComponent = render(
+ const { getByText } = render(
)
// Then
- expect(renderedComponent.text()).toEqual("This came from mapStateToProps and this came from the system and this came from my own props")
+ expect(getByText("This came from mapStateToProps and this came from the system and this came from my own props")).toBeInTheDocument()
})
})
diff --git a/test/unit/core/system/wrapComponent.jsx b/test/unit/core/system/wrapComponent.jsx
index 8a5522e7f40..b15906f12bf 100644
--- a/test/unit/core/system/wrapComponent.jsx
+++ b/test/unit/core/system/wrapComponent.jsx
@@ -1,6 +1,6 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import System from "core/system"
describe("wrapComponents", () => {
@@ -31,12 +31,10 @@ describe("wrapComponents", () => {
let Component = system.getSystem().getComponents("wow")
const wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("container")
-
- const children = wrapper.children()
- expect(children.length).toEqual(2)
- expect(children.eq(0).text()).toEqual("Normal component")
- expect(children.eq(1).text()).toEqual("Wrapped component")
+ expect(wrapper.container.firstChild.nodeName).toEqual("CONTAINER")
+ expect(wrapper.container.firstChild.children.length).toEqual(2)
+ expect(wrapper.container.firstChild.children[0].textContent).toEqual("Normal component")
+ expect(wrapper.container.firstChild.children[1].textContent).toEqual("Wrapped component")
})
it("with React classes", function () {
@@ -75,12 +73,10 @@ describe("wrapComponents", () => {
let Component = system.getSystem().getComponents("wow")
const wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("container")
-
- const children = wrapper.children()
- expect(children.length).toEqual(2)
- expect(children.eq(0).text()).toEqual("Normal component")
- expect(children.eq(1).text()).toEqual("Wrapped component")
+ expect(wrapper.container.firstChild.nodeName).toEqual("CONTAINER")
+ expect(wrapper.container.firstChild.children.length).toEqual(2)
+ expect(wrapper.container.firstChild.children[0].textContent).toEqual("Normal component")
+ expect(wrapper.container.firstChild.children[1].textContent).toEqual("Wrapped component")
})
})
@@ -126,12 +122,12 @@ describe("wrapComponents", () => {
let Component = mySystem.getSystem().getComponents("wow")
const wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("container")
+ expect(wrapper.container.firstChild.nodeName).toEqual("CONTAINER")
- const children = wrapper.children()
+ const children = wrapper.container.firstChild.children
expect(children.length).toEqual(2)
- expect(children.eq(0).text()).toEqual("Original component")
- expect(children.eq(1).text()).toEqual("WOW much data")
+ expect(children[0].textContent).toEqual("Original component")
+ expect(children[1].textContent).toEqual("WOW much data")
})
it("should wrap correctly when registering more plugins", function () {
@@ -179,12 +175,12 @@ describe("wrapComponents", () => {
let Component = mySystem.getSystem().getComponents("wow")
const wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("container")
+ expect(wrapper.container.firstChild.nodeName).toEqual("CONTAINER")
- const children = wrapper.children()
+ const children = wrapper.container.firstChild.children
expect(children.length).toEqual(2)
- expect(children.eq(0).text()).toEqual("Original component")
- expect(children.eq(1).text()).toEqual("WOW much data")
+ expect(children[0].textContent).toEqual("Original component")
+ expect(children[1].textContent).toEqual("WOW much data")
})
it("should wrap component correctly when performing subsequent plugin registering targeting the same component", function () {
@@ -234,19 +230,19 @@ describe("wrapComponents", () => {
let Component = mySystem.getSystem().getComponents("wow")
const wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("container2")
+ expect(wrapper.container.firstChild.nodeName).toEqual("CONTAINER2")
- const children2 = wrapper.children()
+ const children2 = wrapper.container.firstChild.children
expect(children2.length).toEqual(2)
- expect(children2[0].name).toEqual("div")
- expect(children2.eq(0).text()).toEqual("Injected before")
- expect(children2[1].name).toEqual("container1")
+ expect(children2[0].nodeName).toEqual("DIV")
+ expect(children2[0].textContent).toEqual("Injected before")
+ expect(children2[1].nodeName).toEqual("CONTAINER1")
- const children1 = children2.children()
+ const children1 = children2[1].children
expect(children1.length).toEqual(2)
- expect(children1.eq(0).text()).toEqual("Original component")
- expect(children1[0].name).toEqual("div")
- expect(children1.eq(1).text()).toEqual("Injected after")
+ expect(children1[0].textContent).toEqual("Original component")
+ expect(children1[0].nodeName).toEqual("DIV")
+ expect(children1[1].textContent).toEqual("Injected after")
})
it("should wrap correctly when building a system twice", function () {
@@ -294,11 +290,11 @@ describe("wrapComponents", () => {
let Component = secondSystem.getSystem().getComponents("wow")
const wrapper = render(
)
- expect(wrapper.get(0).name).toEqual("container")
+ expect(wrapper.container.firstChild.nodeName).toEqual("CONTAINER")
- const children = wrapper.children()
+ const children = wrapper.container.firstChild.children
expect(children.length).toEqual(2)
- expect(children.eq(0).text()).toEqual("Original component")
- expect(children.eq(1).text()).toEqual("WOW much data")
+ expect(children[0].textContent).toEqual("Original component")
+ expect(children[1].textContent).toEqual("WOW much data")
})
})
diff --git a/test/unit/setup.js b/test/unit/setup.js
index 711d5bac1f5..157979ad438 100644
--- a/test/unit/setup.js
+++ b/test/unit/setup.js
@@ -1,10 +1,8 @@
import { JSDOM } from "jsdom"
-import Enzyme from "enzyme"
-const { default: Adapter } = require("@cfaester/enzyme-adapter-react-18")
+import "@testing-library/jest-dom"
import win from "../../src/core/window"
-Enzyme.configure({ adapter: new Adapter() })
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
@@ -37,5 +35,3 @@ function setUpDomEnvironment() {
}
setUpDomEnvironment()
-
-// configure({ adapter: new Adapter() }) // enzyme@3
diff --git a/test/unit/xss/anchor-target-rel/info.jsx b/test/unit/xss/anchor-target-rel/info.jsx
index fc3f88bcfa6..262ace1affb 100644
--- a/test/unit/xss/anchor-target-rel/info.jsx
+++ b/test/unit/xss/anchor-target-rel/info.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS } from "immutable"
import Info, { InfoUrl } from "core/components/info"
import Contact from "core/components/contact"
@@ -32,13 +32,13 @@ describe("
Anchor Target Safety", function(){
url: "http://google.com/"
})
}
- let wrapper = render(
)
- const anchor = wrapper.find("a")
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- expect(anchor.html()).toEqual("http://google.com/")
- expect(anchor.attr("target")).toEqual("_blank")
- expect(anchor.attr("rel") || "").toMatch("noopener")
- expect(anchor.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("renders Contact links with safe `rel` attributes", function () {
@@ -51,13 +51,13 @@ describe("
Anchor Target Safety", function(){
}
})
}
- let wrapper = render(
)
- const anchor = wrapper.find("a")
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- 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")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("renders License links with safe `rel` attributes", function () {
@@ -69,13 +69,13 @@ describe("
Anchor Target Safety", function(){
}
})
}
- let wrapper = render(
)
- const anchor = wrapper.find("a")
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- expect(anchor.attr("href")).toEqual("http://mit.edu/")
- expect(anchor.attr("target")).toEqual("_blank")
- expect(anchor.attr("rel") || "").toMatch("noopener")
- expect(anchor.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://mit.edu/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("renders termsOfService links with safe `rel` attributes", function () {
@@ -85,13 +85,13 @@ describe("
Anchor Target Safety", function(){
termsOfService: "http://smartbear.com/"
})
}
- let wrapper = render(
)
- const anchor = wrapper.find("a")
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- expect(anchor.attr("href")).toEqual("http://smartbear.com/")
- expect(anchor.attr("target")).toEqual("_blank")
- expect(anchor.attr("rel") || "").toMatch("noopener")
- expect(anchor.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://smartbear.com/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("renders definition URL links with safe `rel` attributes", function () {
@@ -99,12 +99,12 @@ describe("
Anchor Target Safety", function(){
...baseProps,
url: "http://petstore.swagger.io/v2/petstore.json"
}
- let wrapper = render(
)
- const anchor = wrapper.find("a")
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- expect(anchor.attr("href")).toEqual("http://petstore.swagger.io/v2/petstore.json")
- expect(anchor.attr("target")).toEqual("_blank")
- expect(anchor.attr("rel") || "").toMatch("noopener")
- expect(anchor.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://petstore.swagger.io/v2/petstore.json")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
})
diff --git a/test/unit/xss/anchor-target-rel/link.jsx b/test/unit/xss/anchor-target-rel/link.jsx
index 7c032c19b6d..3246b95b7cb 100644
--- a/test/unit/xss/anchor-target-rel/link.jsx
+++ b/test/unit/xss/anchor-target-rel/link.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import { Link } from "core/components/layout-utils"
describe("
Anchor Target Safety", function () {
@@ -16,11 +16,12 @@ describe("
Anchor Target Safety", function () {
...baseProps,
href: "http://google.com/"
}
- let wrapper = render(
)
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- expect(wrapper.attr("href")).toEqual("http://google.com/")
- expect(wrapper.attr("rel") || "").toMatch("noopener")
- expect(wrapper.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("enforces `noreferrer` and `noopener` on target=_blank links", function () {
@@ -29,11 +30,12 @@ describe("
Anchor Target Safety", function () {
href: "http://google.com/",
target: "_blank"
}
- let wrapper = render(
)
+ const { getByRole } = render(
)
+ const anchor = getByRole("link")
- 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")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
})
diff --git a/test/unit/xss/anchor-target-rel/markdown.jsx b/test/unit/xss/anchor-target-rel/markdown.jsx
index 362861ae6c0..d59edffcdfe 100644
--- a/test/unit/xss/anchor-target-rel/markdown.jsx
+++ b/test/unit/xss/anchor-target-rel/markdown.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import Markdown from "core/components/providers/markdown"
import { Markdown as OAS3Markdown } from "core/plugins/oas3/wrap-components/markdown.jsx"
@@ -7,58 +7,50 @@ describe("Markdown Link Anchor Safety", function () {
describe("Swagger 2.0", function () {
it("sanitizes Markdown links", function () {
const str = `Hello, [here](http://google.com/) is my link`
- const wrapper = render(
)
+ const { getByText } = render(
)
- const anchor = wrapper.find("a")
+ const anchor = getByText("here").closest("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")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("sanitizes raw HTML links", function () {
const str = `Hello,
here is my link`
- const wrapper = render(
)
+ const { getByText } = render(
)
- const anchor = wrapper.find("a")
+ const anchor = getByText("here").closest("a")
- expect(anchor.attr("href")).toEqual("http://google.com/")
- expect(anchor.attr("rel") || "").toMatch("noopener")
- expect(anchor.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
})
describe("OAS 3", function () {
it("sanitizes Markdown links", function () {
const str = `Hello, [here](http://google.com/) is my link`
- const wrapper = render(
)
+ const { getByText } = render(
)
- const anchor = wrapper.find("a")
+ const anchor = getByText("here").closest("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")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
it("sanitizes raw HTML links", function () {
const str = `Hello,
here is my link`
- const wrapper = render(
)
+ const { getByText } = render(
)
- const anchor = wrapper.find("a")
+ const anchor = getByText("here").closest("a")
- expect(anchor.attr("href")).toEqual("http://google.com/")
- expect(anchor.attr("rel") || "").toMatch("noopener")
- expect(anchor.attr("rel") || "").toMatch("noreferrer")
+ expect(anchor).toHaveAttribute("href", "http://google.com/")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
})
})
-
-function withMarkdownWrapper(str, { isOAS3 = false } = {}) {
- if(isOAS3) {
- return `
`
- }
-
- return `
`
-}
diff --git a/test/unit/xss/anchor-target-rel/online-validator-badge.jsx b/test/unit/xss/anchor-target-rel/online-validator-badge.jsx
index 856a850f2af..d87972ed489 100644
--- a/test/unit/xss/anchor-target-rel/online-validator-badge.jsx
+++ b/test/unit/xss/anchor-target-rel/online-validator-badge.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { mount } from "enzyme"
+import { render } from "@testing-library/react"
import OnlineValidatorBadge from "core/components/online-validator-badge"
describe("
Anchor Target Safety", function () {
@@ -12,18 +12,19 @@ describe("
Anchor Target Safety", function () {
url: () => "https://smartbear.com/swagger.json"
}
}
- const wrapper = mount(
+ const { getByRole } = render(
)
- const anchor = wrapper.find("a")
+ const anchor = getByRole("link")
// Then
- expect(anchor.props().href).toEqual(
+ expect(anchor).toHaveAttribute(
+ "href",
"https://validator.swagger.io/validator/debug?url=https%3A%2F%2Fsmartbear.com%2Fswagger.json"
)
- expect(anchor.props().target).toEqual("_blank")
- expect(anchor.props().rel || "").toContain("noopener")
- expect(anchor.props().rel || "").toContain("noreferrer")
+ expect(anchor).toHaveAttribute("target", "_blank")
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noopener"))
+ expect(anchor).toHaveAttribute("rel", expect.stringContaining("noreferrer"))
})
})
diff --git a/test/unit/xss/info-sanitization.jsx b/test/unit/xss/info-sanitization.jsx
index 718e202d059..f531041f022 100644
--- a/test/unit/xss/info-sanitization.jsx
+++ b/test/unit/xss/info-sanitization.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import { fromJS } from "immutable"
import Info from "core/components/info"
import Markdown from "core/components/providers/markdown"
@@ -21,12 +21,12 @@ describe("
Sanitization", function(){
}
it("renders sanitized .title content", function(){
- let wrapper = render(
)
- expect(wrapper.find(".title").html()).toEqual("Test Title **strong** <script>alert(1)</script>
")
+ const { container } = render(
)
+ expect(container.querySelector(".title").innerHTML).toEqual("Test Title **strong** <script>alert(1)</script>
")
})
it("renders sanitized .description content", function() {
- let wrapper = render(
)
- expect(wrapper.find(".description").html()).toEqual("
")
+ const { container } = render(
)
+ expect(container.querySelector(".description").innerHTML).toEqual("
")
})
})
diff --git a/test/unit/xss/markdown-script-sanitization.jsx b/test/unit/xss/markdown-script-sanitization.jsx
index 34ff2e24340..3336cef5838 100644
--- a/test/unit/xss/markdown-script-sanitization.jsx
+++ b/test/unit/xss/markdown-script-sanitization.jsx
@@ -1,5 +1,5 @@
import React from "react"
-import { render } from "enzyme"
+import { render } from "@testing-library/react"
import Markdown from "core/components/providers/markdown"
import { Markdown as OAS3Markdown } from "core/plugins/oas3/wrap-components/markdown.jsx"
@@ -7,40 +7,40 @@ describe("Markdown Script Sanitization", function() {
describe("Swagger 2.0", function() {
it("sanitizes `
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`
`)
+ const { container } = render(
)
+ expect(container.querySelector(".markdown").outerHTML).toEqual(`
`)
})
it("sanitizes
![]()
elements", function() {
const str = `

`
- const el = render(
)
- expect(el.prop("outerHTML")).toEqual(`

\n
`)
+ const { container } = render(
)
+ expect(container.querySelector(".markdown").outerHTML).toEqual(`

\n
`)
})
it("sanitizes