Skip to content

Commit 40768d4

Browse files
committed
[fragment] Pass lookup options into the region's descendant search
1 parent 6de28c9 commit 40768d4

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎spec/unpoly/fragment_lookup_spec.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,30 @@ extendDescribe('up.fragment', function() {
329329
expect(up.fragment.get('#fragment', { destroying: true })).toBe(fragment)
330330
})
331331

332+
it('does find a destroying fragment in the region of the origin with { destroying: true }', async function() {
333+
// A descendant selector is matched in two steps: find the '.element' closest to
334+
// the origin, then look for '.sibling' inside it. The inner step must search with
335+
// the same options as the outer one.
336+
const [, farSibling, , origin, nearSibling] = htmlFixtureList(`
337+
<div class="element">
338+
<div class="child sibling">far sibling</div>
339+
</div>
340+
<div class="element">
341+
<div class="child">origin</div>
342+
<div class="child sibling">near sibling</div>
343+
</div>
344+
`)
345+
up.destroy(nearSibling, { animation: 'fade-out', duration: 200 })
346+
await wait()
347+
348+
const result = up.fragment.get('.element .sibling', { origin, destroying: true })
349+
350+
// If the inner step drops { destroying: true } it skips nearSibling, and the
351+
// lookup falls back to the first '.sibling' on the page, which is farSibling.
352+
expect(result).toBe(nearSibling)
353+
expect(result).not.toBe(farSibling)
354+
})
355+
332356
})
333357

334358
describe('expansion of :main', function() {

‎src/unpoly/classes/fragment_finder.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ up.FragmentFinder = class FragmentFinder {
4242
if (parts) {
4343
let parent = up.fragment.closest(this._origin, parts[1], this._options)
4444
if (parent) {
45-
return up.fragment.getFirstDescendant(parent, parts[2])
45+
return up.fragment.getFirstDescendant(parent, parts[2], this._options)
4646
}
4747
}
4848
})

0 commit comments

Comments
 (0)