@@ -25,6 +25,40 @@ describe('runtime-dom: props patching', () => {
2525 expect ( ( el as any ) . _value ) . toBe ( obj )
2626 } )
2727
28+ test ( 'value for custom elements' , ( ) => {
29+ class TestElement extends HTMLElement {
30+ constructor ( ) {
31+ super ( )
32+ }
33+
34+ // intentionally uses _value because this is used in "normal" HTMLElement for storing the object of the set property value
35+ private _value : any
36+ get value ( ) {
37+ return this . _value
38+ }
39+
40+ set value ( val ) {
41+ this . _value = val
42+ this . setterCalled ++
43+ }
44+
45+ public setterCalled : number = 0
46+ }
47+ window . customElements . define ( 'test-element' , TestElement )
48+ const el = document . createElement ( 'test-element' ) as TestElement
49+ patchProp ( el , 'value' , null , 'foo' )
50+ expect ( el . value ) . toBe ( 'foo' )
51+ expect ( el . setterCalled ) . toBe ( 1 )
52+ patchProp ( el , 'value' , null , null )
53+ expect ( el . value ) . toBe ( '' )
54+ expect ( el . setterCalled ) . toBe ( 2 )
55+ expect ( el . getAttribute ( 'value' ) ) . toBe ( null )
56+ const obj = { }
57+ patchProp ( el , 'value' , null , obj )
58+ expect ( el . value ) . toBe ( obj )
59+ expect ( el . setterCalled ) . toBe ( 3 )
60+ } )
61+
2862 // For <input type="text">, setting el.value won't create a `value` attribute
2963 // so we need to add tests for other elements
3064 test ( 'value for non-text input' , ( ) => {
0 commit comments