@@ -110,6 +110,40 @@ describe('getValueFromElement', () => {
110
110
111
111
expect ( getValueFromElement ( div , createStore ( ) ) ) . toEqual ( 'the_value_from_attribute' ) ;
112
112
} ) ;
113
+
114
+ it ( 'Returns empty string for data-value=""' , ( ) => {
115
+ const btn = document . createElement ( 'button' ) ;
116
+ // simulate the attribute explicitly present but empty
117
+ btn . dataset . value = '' ;
118
+ // also set a value on the button to ensure data-value takes precedence
119
+ btn . value = 'should_not_be_used' ;
120
+ expect ( getValueFromElement ( btn , createStore ( ) ) ) . toBe ( '' ) ;
121
+ } ) ;
122
+
123
+ it ( 'Returns "0" for data-value="0" (falsy but valid)' , ( ) => {
124
+ const el = document . createElement ( 'div' ) ;
125
+ el . dataset . value = '0' ;
126
+ expect ( getValueFromElement ( el , createStore ( ) ) ) . toBe ( '0' ) ;
127
+ } ) ;
128
+
129
+ it ( 'Prefers data-value over value attribute when both are present' , ( ) => {
130
+ const el = document . createElement ( 'div' ) ;
131
+ el . dataset . value = 'from_data_value' ;
132
+ el . setAttribute ( 'value' , 'from_value_attribute' ) ;
133
+ expect ( getValueFromElement ( el , createStore ( ) ) ) . toBe ( 'from_data_value' ) ;
134
+ } ) ;
135
+
136
+ it ( 'Falls back to value attribute when data-value is absent' , ( ) => {
137
+ const el = document . createElement ( 'div' ) ;
138
+ el . setAttribute ( 'value' , '' ) ;
139
+ // No data-value set
140
+ expect ( getValueFromElement ( el , createStore ( ) ) ) . toBe ( '' ) ;
141
+ } ) ;
142
+
143
+ it ( 'Returns null when neither data-value nor value attribute nor value property is present' , ( ) => {
144
+ const el = document . createElement ( 'div' ) ;
145
+ expect ( getValueFromElement ( el , createStore ( ) ) ) . toBe ( null ) ;
146
+ } ) ;
113
147
} ) ;
114
148
115
149
describe ( 'setValueOnElement' , ( ) => {
0 commit comments