@@ -121,4 +121,56 @@ jsdomDescribe('inert middleware', () => {
121
121
assert . strictEqual ( childTwo . inert , false ) ;
122
122
assert . strictEqual ( childThree . inert , false ) ;
123
123
} ) ;
124
+
125
+ it ( 'should only set inert state when properties change' , ( ) => {
126
+ const parent = global . document . createElement ( 'div' ) ;
127
+ const childOne = global . document . createElement ( 'div' ) ;
128
+ const childTwo = global . document . createElement ( 'div' ) ;
129
+ const childThree = global . document . createElement ( 'div' ) ;
130
+ const childFour = global . document . createElement ( 'div' ) ;
131
+ const node = global . document . createElement ( 'div' ) ;
132
+ parent . appendChild ( childOne ) ;
133
+ parent . appendChild ( childTwo ) ;
134
+ parent . appendChild ( childThree ) ;
135
+ parent . appendChild ( node ) ;
136
+ let _inert = false ;
137
+ const inertStub = stub ( ) ;
138
+ Object . defineProperty ( childFour , 'inert' , {
139
+ get ( ) {
140
+ return _inert ;
141
+ } ,
142
+ set ( value : boolean ) {
143
+ _inert = value ;
144
+ inertStub ( ) ;
145
+ }
146
+ } ) ;
147
+ const destroyStub = stub ( ) ;
148
+ const inert = inertMiddleware ( ) . callback ( {
149
+ id : 'test' ,
150
+ middleware : {
151
+ icache,
152
+ destroy : destroyStub ,
153
+ node : {
154
+ get ( ) {
155
+ return node ;
156
+ }
157
+ }
158
+ } ,
159
+ properties : ( ) => ( { } ) ,
160
+ children : ( ) => [ ]
161
+ } ) ;
162
+ inert . set ( 'key' , true , true ) ;
163
+ assert . strictEqual ( node . inert , false ) ;
164
+ assert . strictEqual ( childOne . inert , true ) ;
165
+ assert . strictEqual ( childTwo . inert , true ) ;
166
+ assert . strictEqual ( childThree . inert , true ) ;
167
+ assert . strictEqual ( inertStub . callCount , 0 ) ;
168
+ parent . appendChild ( childFour ) ;
169
+ inert . set ( 'key' , true , true ) ;
170
+ assert . strictEqual ( node . inert , false ) ;
171
+ assert . strictEqual ( childOne . inert , true ) ;
172
+ assert . strictEqual ( childTwo . inert , true ) ;
173
+ assert . strictEqual ( childThree . inert , true ) ;
174
+ assert . strictEqual ( inertStub . callCount , 0 ) ;
175
+ } ) ;
124
176
} ) ;
0 commit comments