From 277f0c7f793875823f1c07fba387eb656c8a0a90 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 8 Aug 2018 11:28:43 +0200 Subject: [PATCH] Add tests for registry types in guarded maps and sets --- test/registry.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) 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"); + }); }); });