Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fcd51f6

Browse files
committed
test: add assertion that elem is still connected during load event
1 parent 01b82f7 commit fcd51f6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

test/test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,33 @@ suite('include-fragment-element', function() {
429429
test('loading events fire in guaranteed order', function() {
430430
const elem = document.createElement('include-fragment')
431431
const order = []
432+
const connected = []
432433
const events = [
433-
when(elem, 'loadend').then(() => order.push('loadend')),
434-
when(elem, 'load').then(() => order.push('load')),
435-
when(elem, 'loadstart').then(() => order.push('loadstart'))
434+
when(elem, 'loadend').then(() => {
435+
order.push('loadend')
436+
connected.push(elem.isConnected)
437+
}),
438+
when(elem, 'load').then(() => {
439+
order.push('load')
440+
connected.push(elem.isConnected)
441+
}),
442+
when(elem, 'loadstart').then(() => {
443+
order.push('loadstart')
444+
connected.push(elem.isConnected)
445+
})
436446
]
437447
elem.src = '/hello'
448+
449+
// Emulate some kind of timer clamping
438450
const originalSetTimeout = window.setTimeout
439451
let i = 60
440452
window.setTimeout = (fn, ms, ...rest) => originalSetTimeout.call(window, fn, ms + (i -= 20), ...rest)
441-
elem.load()
453+
454+
document.body.appendChild(elem)
442455
return Promise.all(events).then(() => {
443456
window.setTimeout = originalSetTimeout
444457
assert.deepStrictEqual(order, ['loadstart', 'load', 'loadend'])
458+
assert.deepStrictEqual(connected, [true, false, false])
445459
})
446460
})
447461

0 commit comments

Comments
 (0)