fix(examples): properly update memoized value in non-schema case (#6641)

This commit is contained in:
Tim Lai
2020-11-19 13:55:32 -08:00
committed by GitHub
parent 451da70f7e
commit d2ef8f31b9
2 changed files with 64 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
import { fromJS } from "immutable"
import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
import { createXMLExample, sampleFromSchema, memoizedCreateXMLExample, memoizedSampleFromSchema } from "corePlugins/samples/fn"
describe("sampleFromSchema", () => {
it("handles Immutable.js objects for nested schemas", function () {
@@ -1457,3 +1457,64 @@ describe("createXMLExample", function () {
})
})
})
describe("memoizedSampleFromSchema", () => {
it("should sequentially update memoized overrideExample", () => {
const definition = {
type: "object",
properties: {
foo: {
type: "string"
}
},
example: {
foo: null
}
}
const expected = {
foo: "override"
}
expect(memoizedSampleFromSchema(definition, {}, expected)).toEqual(expected)
const updatedExpected = {
foo: "cat"
}
expect(memoizedSampleFromSchema(definition, {}, updatedExpected)).toEqual(updatedExpected)
})
})
describe("memoizedCreateXMLExample", () => {
it("should sequentially update memoized overrideExample", () => {
const expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bar>\n\t<foo>override</foo>\n</bar>"
const definition = {
type: "object",
properties: {
foo: {
type: "string",
xml: {
name: "foo"
}
}
},
example: {
foo: null
},
xml: {
name: "bar"
}
}
const overrideExample = {
foo: "override"
}
expect(memoizedCreateXMLExample(definition, {}, overrideExample)).toEqual(expected)
const updatedOverrideExample = {
foo: "cat"
}
const updatedExpected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bar>\n\t<foo>cat</foo>\n</bar>"
expect(memoizedCreateXMLExample(definition, {}, updatedOverrideExample)).toEqual(updatedExpected)
})
})