@@ -176,6 +176,30 @@ asyncTest('replaces element on 200 status', 2, function() {
176
176
} ) ;
177
177
} ) ;
178
178
179
+ asyncTest ( 'does not replace element if it has no parent' , 2 , function ( ) {
180
+ var div = document . createElement ( 'div' ) ;
181
+ div . innerHTML = '<include-fragment src="/hello">loading</include-fragment>' ;
182
+ document . getElementById ( 'qunit-fixture' ) . appendChild ( div ) ;
183
+
184
+ var fragment = div . firstChild ;
185
+ fragment . remove ( ) ;
186
+
187
+ window . addEventListener ( 'unhandledrejection' , function ( ) {
188
+ ok ( false ) ;
189
+ } ) ;
190
+
191
+ fragment . addEventListener ( 'load' , function ( ) {
192
+ equal ( document . querySelector ( '#replaced' ) , null ) ;
193
+ start ( ) ;
194
+
195
+ div . appendChild ( fragment ) ;
196
+
197
+ setTimeout ( function ( ) {
198
+ equal ( document . querySelector ( '#replaced' ) . textContent , 'hello' ) ;
199
+ } , 10 ) ;
200
+ } ) ;
201
+ } ) ;
202
+
179
203
asyncTest ( 'replaces with several new elements on 200 status' , 3 , function ( ) {
180
204
var div = document . createElement ( 'div' ) ;
181
205
div . innerHTML = '<include-fragment src="/one-two">loading</include-fragment>' ;
@@ -206,7 +230,7 @@ asyncTest('adds is-error class on 500 status', 1, function() {
206
230
div . innerHTML = '<include-fragment src="/boom">loading</include-fragment>' ;
207
231
document . getElementById ( 'qunit-fixture' ) . appendChild ( div ) ;
208
232
209
- div . firstChild . addEventListener ( 'error' , function ( event ) {
233
+ div . firstChild . addEventListener ( 'error' , function ( ) {
210
234
ok ( document . querySelector ( 'include-fragment' ) . classList . contains ( 'is-error' ) ) ;
211
235
start ( ) ;
212
236
} ) ;
@@ -217,7 +241,7 @@ asyncTest('adds is-error class on mising Content-Type', 1, function() {
217
241
div . innerHTML = '<include-fragment src="/blank-type">loading</include-fragment>' ;
218
242
document . getElementById ( 'qunit-fixture' ) . appendChild ( div ) ;
219
243
220
- div . firstChild . addEventListener ( 'error' , function ( event ) {
244
+ div . firstChild . addEventListener ( 'error' , function ( ) {
221
245
ok ( document . querySelector ( 'include-fragment' ) . classList . contains ( 'is-error' ) ) ;
222
246
start ( ) ;
223
247
} ) ;
0 commit comments