feat: migrate unit tests to Jest (#6353)
* config(jest): updated setup * config(jest): update testMatch to include jsx files * config(jest): add transformIgnorePatterns * config(jest): update ignore files that do not work in jest yet * config: add test:unit-jest to test script * fix(jest): lint with eslint-plugin-jest * refactor(jest): move unit test directory * refactor(mocha): restore mocha tests that fail in jest * docs(jest): update helpful scripts with test:unit-jest
This commit is contained in:
60
test/unit/components/response.jsx
Normal file
60
test/unit/components/response.jsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import React from "react"
|
||||
import { shallow } from "enzyme"
|
||||
import { fromJS, List } from "immutable"
|
||||
import Response from "components/response"
|
||||
import ModelExample from "components/model-example"
|
||||
import { inferSchema } from "corePlugins/samples/fn"
|
||||
|
||||
describe("<Response />", function () {
|
||||
const dummyComponent = () => null
|
||||
const components = {
|
||||
headers: dummyComponent,
|
||||
highlightCode: dummyComponent,
|
||||
modelExample: ModelExample,
|
||||
Markdown: dummyComponent,
|
||||
operationLink: dummyComponent,
|
||||
contentType: dummyComponent
|
||||
}
|
||||
const props = {
|
||||
getComponent: c => components[c],
|
||||
specSelectors: {
|
||||
isOAS3() {
|
||||
return false
|
||||
}
|
||||
},
|
||||
fn: {
|
||||
inferSchema
|
||||
},
|
||||
contentType: "application/json",
|
||||
className: "for-test",
|
||||
specPath: List(),
|
||||
response: fromJS({
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
// Note reverse order: c, b, a
|
||||
"c": {
|
||||
type: "integer"
|
||||
},
|
||||
"b": {
|
||||
type: "boolean"
|
||||
},
|
||||
"a": {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
code: "200"
|
||||
}
|
||||
|
||||
it("renders the model-example schema properties in order", function () {
|
||||
const wrapper = shallow(<Response {...props} />)
|
||||
const renderedModelExample = wrapper.find(ModelExample)
|
||||
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"])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user