Skip to content

Commit

Permalink
test: add test for oneOf default values
Browse files Browse the repository at this point in the history
  • Loading branch information
qingqi-spotify committed Mar 23, 2021
1 parent 982f217 commit b2eb250
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/core/test/oneOf_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,43 @@ describe("oneOf", () => {
expect(node.querySelector("input#root").value).eql("");
});

it("should use only the selected option when generating default values", () => {
const schema = {
type: "object",
oneOf: [
{
additionalProperties: false,
properties: { lorem: { type: "object" } },
},
{
additionalProperties: false,
properties: { ipsum: { type: "object" } },
},
{
additionalProperties: false,
properties: { pyot: { type: "object" } },
},
],
};

const { node, onChange } = createFormComponent({
schema,
formData: { lorem: {} },
});

const $select = node.querySelector("select");

Simulate.change($select, {
target: { value: $select.options[1].value },
});

expect($select.value).eql("1");

sinon.assert.calledWithMatch(onChange.lastCall, {
formData: { lorem: undefined, ipsum: {} },
});
});

describe("Arrays", () => {
it("should correctly render mixed types for oneOf inside array items", () => {
const schema = {
Expand Down

0 comments on commit b2eb250

Please sign in to comment.