You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is really hard to explain in words, but the reproduction should help explain. If you are validating an array of objects and those objects have optional properties which themselves have optional properties, the validation fails to take into account the optionality of the nested fields.
reproduction
import{expect}from"chai"importchaiJsonPatternfrom"chai-json-pattern"describe.only("failing check against arrays of objects with optional fields which have optional sub fields",()=>{constjsonPattern=`{ "data": [{ "id": String, "optional_object"?: { "required_string_field": String, "optional_string_field"?: String, "optional_sub_object"?: { "required_string_field": String, "optional_string_field"?: String, } } }] }`describe("without optional sub object",()=>{it("should pass when array contains element with optional object ",()=>{expect({data: [{id: "1",},],}).to.matchPattern(jsonPattern)})it("should pass when array contains element without optional object",()=>{expect({data: [{id: "1",optional_object: {required_string_field: "1",optional_string_field: "1",},},],}).to.matchPattern(jsonPattern)})it("should pass when array contains elements with and without optional object",()=>{expect({data: [{id: "1",optional_object: {required_string_field: "1",optional_string_field: "1",},},{id: "1",},],}).to.matchPattern(jsonPattern)})})describe("with optional sub object",()=>{it("should pass when array contains element with optional object with optional sub object",()=>{expect({data: [{id: "1",optional_object: {required_string_field: "1",optional_string_field: "1",optional_sub_object: {required_string_field: "1",optional_string_field: "1",},},},],}).to.matchPattern(jsonPattern)})it("should pass when array contains 2 elements with optional object, where one contains the optional sub object and the other doesn't",()=>{expect({data: [{id: "1",optional_object: {required_string_field: "1",optional_string_field: "1",},},{id: "1",optional_object: {required_string_field: "1",optional_string_field: "1",optional_sub_object: {required_string_field: "1",optional_string_field: "1",},},},],}).to.matchPattern(jsonPattern)})})})
The text was updated successfully, but these errors were encountered:
This is really hard to explain in words, but the reproduction should help explain. If you are validating an array of objects and those objects have optional properties which themselves have optional properties, the validation fails to take into account the optionality of the nested fields.
reproduction
The text was updated successfully, but these errors were encountered: