Skip to content

Commit

Permalink
Add failing test for default-valued properties
Browse files Browse the repository at this point in the history
@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
  • Loading branch information
ryecroft committed Oct 31, 2022
1 parent a874af9 commit 5f8d9da
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/attrable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit 5f8d9da

Please sign in to comment.