From 633f9725e378e8076598a66f14797b023a8dd881 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Fri, 11 Mar 2022 21:51:56 -0600 Subject: [PATCH] Add #set test close #161 --- test/index.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 795183e..0bcb551 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -483,6 +483,40 @@ describe('Unit | Utility | changeset', () => { expect(dummyChangeset.isDirty).toBe(false); }); + it('#set works with native getters and setters', function() { + class DogTag { + _name = ''; + _years = 1; + + get name() { + return this._name; + } + set name(value) { + this._name = value; + } + get age() { + return 7 * this._years; + } + set age(value) { + this._years = value; + } + } + + const dog = new DogTag(); + + const c = Changeset(dog); + + c.set('name', 'good boy'); + expect(c.get('name')).toEqual('good boy'); + + expect(c.get('age')).toEqual(7); + expect(c.age).toEqual(7); + c.set('age', 2); + expect(c.get('age')).toEqual(2); + c.execute(); + expect(c.get('age')).toEqual(14); + }); + /** * #get */