From fbd9ce87e963913a82be27e6d1bc2a8aea6eb949 Mon Sep 17 00:00:00 2001 From: scott-newcomer Date: Sun, 9 May 2021 14:51:21 -0500 Subject: [PATCH] [Test]: add deep key get when not defined on underlying content --- test/index.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 5879785..39a202a 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -661,6 +661,28 @@ describe('Unit | Utility | changeset', () => { expect((dummyChangeset.users as Array).length).toBe(2); }); + it('#get works if content is undefined for nested key', () => { + class Dog { + breed: string; + constructor(b: string) { + this.breed = b; + } + + bark() { + return `woof i'm a ${this.breed}`; + } + } + + const model: Record = {}; + + const c = Changeset(model); + c.set('foo.bar.cat', { + color: 'red' + }); + const cat = c.get('foo.bar.cat'); + expect(cat.color).toEqual('red'); + }); + /** * #set */