From 5f8d9daa26ba97c984e35de31772c8a08298312e Mon Sep 17 00:00:00 2001 From: fatboy Date: Mon, 31 Oct 2022 18:54:11 +0100 Subject: [PATCH] Add failing test for default-valued properties @attrable properties with a default value specified using a getter method incorrectly have their setter method called with an empty string. This incorrect behaviour does not happen if: - the property is in the html definition - the property does not have a default value supplied by a getter method --- test/attrable.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/attrable.ts b/test/attrable.ts index 8b4f52f3..7a9521a3 100644 --- a/test/attrable.ts +++ b/test/attrable.ts @@ -19,6 +19,16 @@ describe('Attrable', () => { this.setCount += 1 this.#bing = value } + lastSetHasFoo: any + @attr get hasFoo() { + return false + } + set hasFoo(v: boolean) { + this.lastSetHasFoo = v + } + connectedCallback() { + this.hasFoo = true + } } window.customElements.define('initialize-attr-test', InitializeAttrTest) @@ -104,6 +114,10 @@ describe('Attrable', () => { instance.bingBaz = 'universe' expect(instance).to.have.property('bingBaz', 'universe') }) + + it('updates default-valued properties in the connected callback', async () => { + expect(instance).to.have.property('lastSetHasFoo', true) + }) } describe('types', () => {