Skip to content
This repository was archived by the owner on Sep 22, 2022. It is now read-only.

Commit 34db9c9

Browse files
muanbnjamin
authored andcommitted
Ensure feature works when element was constructed in script
This is a workaround test case for src/preload not working for _elements upgraded before parsed_. The cause is that at the time of `attributeChangedCallback`, element does not have access to parentElemet as they haven't been fully parsed and is not yet connected to the DOM. The parsing order is difficult to re-create in test, and even harder to make explicit, so this test reproduce the issue by creating "a upgraded details-dialog, not connected to the DOM at the time of attribute setting". Note: `attributeChangedCallback` always happens before `connectedCallback`, therefore this test will pass if the attribute is set after `connectedCallback`, triggering another `attributeChangedCallback` which binds the events.
1 parent c1ebbba commit 34db9c9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,36 @@ describe('details-dialog-element', function() {
233233
assert.equal(includeFragment.getAttribute('src'), '/404')
234234
})
235235
})
236+
237+
describe('with inlcude-fragment works for script made dialogs', function() {
238+
let includeFragment
239+
beforeEach(function() {
240+
dialog.remove()
241+
dialog = document.createElement('details-dialog')
242+
dialog.src = '/404'
243+
dialog.preload = true
244+
includeFragment = document.createElement('include-fragment')
245+
dialog.append(includeFragment)
246+
details.append(dialog)
247+
includeFragment = document.querySelector('include-fragment')
248+
})
249+
250+
it('transfers src on toggle', async function() {
251+
assert(!details.open)
252+
assert.notOk(includeFragment.getAttribute('src'))
253+
dialog.toggle(true)
254+
await waitForToggleEvent(details)
255+
assert(details.open)
256+
assert.equal(includeFragment.getAttribute('src'), '/404')
257+
})
258+
259+
it('transfers src on mouseover', async function() {
260+
assert(!details.open)
261+
assert.notOk(includeFragment.getAttribute('src'))
262+
triggerEvent(details, 'mouseover')
263+
assert.equal(includeFragment.getAttribute('src'), '/404')
264+
})
265+
})
236266
})
237267
})
238268

0 commit comments

Comments
 (0)