@@ -33,6 +33,93 @@ it('renders ok, updates on attr change', () => {
33
33
document . body . removeChild ( root ) ;
34
34
} ) ;
35
35
36
+ it ( 'passes property changes to props' , ( ) => {
37
+ const root = document . createElement ( 'div' ) ;
38
+ const el = document . createElement ( 'x-clock' ) ;
39
+
40
+ el . time = '10:28:57 PM' ;
41
+ assert . equal ( el . time , '10:28:57 PM' ) ;
42
+
43
+ root . appendChild ( el ) ;
44
+ document . body . appendChild ( root ) ;
45
+ assert . equal (
46
+ root . innerHTML ,
47
+ '<x-clock time="10:28:57 PM"><span>10:28:57 PM</span></x-clock>'
48
+ ) ;
49
+
50
+ el . time = '11:01:10 AM' ;
51
+ assert . equal ( el . time , '11:01:10 AM' ) ;
52
+
53
+ assert . equal (
54
+ root . innerHTML ,
55
+ '<x-clock time="11:01:10 AM"><span>11:01:10 AM</span></x-clock>'
56
+ ) ;
57
+
58
+ document . body . removeChild ( root ) ;
59
+ } ) ;
60
+
61
+ function DummyButton ( { onClick, text = 'click' } ) {
62
+ return < button onClick = { onClick } > { text } </ button > ;
63
+ }
64
+
65
+ registerElement ( DummyButton , 'x-dummy-button' , [ 'onClick' , 'text' ] ) ;
66
+
67
+ it ( 'passes simple properties changes to props' , ( ) => {
68
+ const root = document . createElement ( 'div' ) ;
69
+ const el = document . createElement ( 'x-dummy-button' ) ;
70
+
71
+ el . text = 'foo' ;
72
+ assert . equal ( el . text , 'foo' ) ;
73
+
74
+ root . appendChild ( el ) ;
75
+ document . body . appendChild ( root ) ;
76
+ assert . equal (
77
+ root . innerHTML ,
78
+ '<x-dummy-button text="foo"><button>foo</button></x-dummy-button>'
79
+ ) ;
80
+
81
+ // Update
82
+ el . text = 'bar' ;
83
+ assert . equal (
84
+ root . innerHTML ,
85
+ '<x-dummy-button text="bar"><button>bar</button></x-dummy-button>'
86
+ ) ;
87
+
88
+ document . body . removeChild ( root ) ;
89
+ } ) ;
90
+
91
+ it ( 'passes complex properties changes to props' , ( ) => {
92
+ const root = document . createElement ( 'div' ) ;
93
+ const el = document . createElement ( 'x-dummy-button' ) ;
94
+
95
+ let clicks = 0 ;
96
+ const onClick = ( ) => clicks ++ ;
97
+ el . onClick = onClick ;
98
+ assert . equal ( el . onClick , onClick ) ;
99
+
100
+ root . appendChild ( el ) ;
101
+ document . body . appendChild ( root ) ;
102
+ assert . equal (
103
+ root . innerHTML ,
104
+ '<x-dummy-button><button>click</button></x-dummy-button>'
105
+ ) ;
106
+
107
+ act ( ( ) => {
108
+ el . querySelector ( 'button' ) . click ( ) ;
109
+ } ) ;
110
+ assert . equal ( clicks , 1 ) ;
111
+
112
+ // Update
113
+ let other = 0 ;
114
+ el . onClick = ( ) => other ++ ;
115
+ act ( ( ) => {
116
+ el . querySelector ( 'button' ) . click ( ) ;
117
+ } ) ;
118
+ assert . equal ( other , 1 ) ;
119
+
120
+ document . body . removeChild ( root ) ;
121
+ } ) ;
122
+
36
123
function Foo ( { text, children } ) {
37
124
return (
38
125
< span class = "wrapper" >
0 commit comments