test: consolidate unit tests (#9588)
All mocha tests have been migrated to Jest tests. Closes #9564
This commit is contained in:
30
test/unit/components/highlight-code.jsx
Normal file
30
test/unit/components/highlight-code.jsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import React from "react"
|
||||
import expect from "expect"
|
||||
import { shallow, mount } from "enzyme"
|
||||
import HighlightCode from "core/components/highlight-code"
|
||||
|
||||
const fakeGetConfigs = () => ({syntaxHighlight: {activated: true, theme: "agate"}})
|
||||
|
||||
describe("<HighlightCode />", () => {
|
||||
it("should render a Download button if downloadable", () => {
|
||||
const props = {downloadable: true, getConfigs: fakeGetConfigs }
|
||||
const wrapper = shallow(<HighlightCode {...props} />)
|
||||
expect(wrapper.find(".download-contents").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should render a Copy To Clipboard button if copyable", () => {
|
||||
const props = {canCopy: true, getConfigs: fakeGetConfigs }
|
||||
const wrapper = shallow(<HighlightCode {...props} />)
|
||||
expect(wrapper.find("CopyToClipboard").length).toEqual(1)
|
||||
})
|
||||
|
||||
it("should render values in a preformatted element", () => {
|
||||
const value = "test text"
|
||||
const props = {value: value, getConfigs: fakeGetConfigs}
|
||||
const wrapper = mount(<HighlightCode {...props} />)
|
||||
const preTag = wrapper.find("pre")
|
||||
|
||||
expect(preTag.length).toEqual(1)
|
||||
expect(preTag.text()).toEqual(value)
|
||||
})
|
||||
})
|
||||
@@ -48,8 +48,8 @@ describe("<LiveResponse/>", function(){
|
||||
duration: 50
|
||||
})
|
||||
|
||||
let mutatedRequestForSpy = jest.fn().mockImplementation(function(mutatedRequest) { return mutatedRequest })
|
||||
let requestForSpy = jest.fn().mockImplementation(function(request) { return request })
|
||||
let mutatedRequestForSpy = jest.fn().mockImplementation(function() { return mutatedRequest })
|
||||
let requestForSpy = jest.fn().mockImplementation(function() { return request })
|
||||
|
||||
let components = {
|
||||
curl: Curl,
|
||||
@@ -74,8 +74,8 @@ describe("<LiveResponse/>", function(){
|
||||
let wrapper = shallow(<LiveResponse {...props}/>)
|
||||
|
||||
// Then
|
||||
expect(mutatedRequestForSpy.calls.length).toEqual(test.expected.mutatedRequestForCalls)
|
||||
expect(requestForSpy.calls.length).toEqual(test.expected.requestForCalls)
|
||||
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)
|
||||
@@ -84,13 +84,13 @@ describe("<LiveResponse/>", function(){
|
||||
const expectedUrl = requests[test.expected.request].get("url")
|
||||
expect(wrapper.find("div.request-url pre.microlight").text()).toEqual(expectedUrl)
|
||||
|
||||
let duration = wrapper.find("Duration")
|
||||
const duration = wrapper.find("Duration")
|
||||
expect(duration.length).toEqual(1)
|
||||
expect(duration.props().duration).toEqual(50)
|
||||
expect(duration.html())
|
||||
.toEqual("<div><h5>Request duration</h5><pre class=\"microlight\">50 ms</pre></div>")
|
||||
|
||||
let responseHeaders = wrapper.find("Headers")
|
||||
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")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React from "react"
|
||||
import { mount } from "enzyme"
|
||||
import OnlineValidatorBadge from "core/components/online-validator-badge"
|
||||
import expect from "expect"
|
||||
|
||||
describe("<OnlineValidatorBadge/>", function () {
|
||||
it("should render a validator link and image correctly for the default validator", function () {
|
||||
@@ -9,7 +10,7 @@ describe("<OnlineValidatorBadge/>", function () {
|
||||
getConfigs: () => ({}),
|
||||
getComponent: () => null,
|
||||
specSelectors: {
|
||||
url: () => "swagger.json"
|
||||
url: () => "https://smartbear.com/swagger.json"
|
||||
}
|
||||
}
|
||||
const wrapper = mount(
|
||||
@@ -18,13 +19,11 @@ describe("<OnlineValidatorBadge/>", function () {
|
||||
|
||||
// Then
|
||||
expect(wrapper.find("a").props().href).toEqual(
|
||||
"https://validator.swagger.io/validator/debug?url=swagger.json"
|
||||
"https://validator.swagger.io/validator/debug?url=https%3A%2F%2Fsmartbear.com%2Fswagger.json"
|
||||
)
|
||||
expect(wrapper.find("ValidatorImage").length).toEqual(1)
|
||||
expect(wrapper.find("ValidatorImage").props().src).toEqual(
|
||||
"https://validator.swagger.io/validator?url=swagger.json"
|
||||
)
|
||||
})
|
||||
|
||||
it("should encode a definition URL correctly", function () {
|
||||
// When
|
||||
const props = {
|
||||
@@ -47,7 +46,8 @@ describe("<OnlineValidatorBadge/>", function () {
|
||||
"https://validator.swagger.io/validator?url=http%3A%2F%2Fgoogle.com%2Fswagger.json"
|
||||
)
|
||||
})
|
||||
it.skip("should resolve a definition URL against the browser's location", function () {
|
||||
|
||||
it("should resolve a definition URL against the browser's location", function () {
|
||||
// TODO: mock `window`
|
||||
// When
|
||||
|
||||
@@ -72,5 +72,4 @@ describe("<OnlineValidatorBadge/>", function () {
|
||||
)
|
||||
})
|
||||
// should resolve a definition URL against the browser's location
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user