@@ -37,10 +37,29 @@ test('custom event listeners and properties are ignored', function (t) {
3737 el . click ( )
3838} )
3939
40- test ( 'input values get copied' , function ( t ) {
40+ test ( 'input value gets copied from mutating element ' , function ( t ) {
4141 t . plan ( 1 )
4242 var el = yo `<input type="text" />`
43- el . value = 'hi'
43+ var newEl = yo `<input type="text" />`
44+ newEl . setAttribute ( 'value' , 'hi' )
45+ yo . update ( el , newEl )
46+ t . equal ( el . value , 'hi' )
47+ } )
48+
49+ test ( 'input value can be cleared from mutating element' , function ( t ) {
50+ t . plan ( 1 )
51+ var el = yo `<input type="text" />`
52+ el . setAttribute ( 'value' , 'hi' )
53+ var newEl = yo `<input type="text" />`
54+ newEl . setAttribute ( 'value' , '' )
55+ yo . update ( el , newEl )
56+ t . equal ( el . value , '' )
57+ } )
58+
59+ test ( 'input value is kept if mutating element doesn\'t have one' , function ( t ) {
60+ t . plan ( 1 )
61+ var el = yo `<input type="text" />`
62+ el . setAttribute ( 'value' , 'hi' )
4463 var newEl = yo `<input type="text" />`
4564 yo . update ( el , newEl )
4665 t . equal ( el . value , 'hi' )
@@ -55,3 +74,12 @@ test('textarea values get copied', function (t) {
5574 yo . update ( el , textarea ( 'bar' ) )
5675 t . equal ( el . value , 'bar' )
5776} )
77+
78+ test ( 'select element selection state gets copied' , function ( t ) {
79+ t . plan ( 1 )
80+ var el = yo `<select><option>0</option><option>1</option></select>`
81+ var newEl = yo `<select><option>0</option><option selected>1</option></select>`
82+
83+ yo . update ( el , newEl )
84+ t . equal ( el . selectedIndex , 1 )
85+ } )
0 commit comments