diff --git a/test/registry.js b/test/registry.js index 93e55e7..e7bd790 100644 --- a/test/registry.js +++ b/test/registry.js @@ -144,6 +144,62 @@ describe("registry", () => { value: "bar42" }); }).to.throw("Value for property 'value' failed `matches` condition"); - }) + }); + + it("should work correctly for guarded maps and sets", () => { + let SomeType = registry.createType("SomeType", { + value: dm.string() + }); + + let SomeOtherType = registry.createType("SomeOtherType", { + things: dm.setOf(registry.type("SomeType")), + thingsMap: dm.mapOf(dm.string(), registry.type("SomeType")) + }); + + let thingOne = SomeType({ + value: "one" + }); + + let thingTwo = SomeType({ + value: "two" + }); + + let collection = SomeOtherType({ + things: new Set([ + thingOne, + thingTwo + ]), + thingsMap: new Map([ + ["one", thingOne], + ["two", thingTwo] + ]) + }); + + expect(() => { + SomeOtherType({ + things: new Set([ + "not", + "things" + ]), + thingsMap: new Map([ + ["one", thingOne], + ["two", thingTwo] + ]) + }); + }).to.throw("Expected an instance of SomeType, got a string instead"); + + expect(() => { + SomeOtherType({ + things: new Set([ + thingOne, + thingTwo + ]), + thingsMap: new Map([ + ["one", "not"], + ["two", "things"] + ]) + }); + }).to.throw("Expected an instance of SomeType, got a string instead"); + }); }); });