describe('hx-swap-oob', function() {
beforeEach(() => {
setupTest()
})
afterEach(() => {
cleanupTest()
})
it('swaps oob element by id with default outerHTML', async function () {
mockResponse('GET', '/test', '
Main
OOB Content
')
createProcessedHTML('Click
Original
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('#oob1', 'OOB Content')
})
it('swaps oob element with innerHTML', async function () {
mockResponse('GET', '/test', 'Main
New Inner
')
createProcessedHTML('Click
Old
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('#oob2', 'New Inner')
})
it('swaps oob element with custom selector', async function () {
mockResponse('GET', '/test', 'Main
OOB Target
')
createProcessedHTML('Click
Original Target
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('#x', 'OOB Target')
})
it('swaps multiple oob elements', async function () {
mockResponse('GET', '/test', 'Main
A
B
')
createProcessedHTML('Click
Old A
Old B
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('#a', 'A')
assertTextContentIs('#b', 'B')
})
it('swaps oob with target: modifier', async function () {
mockResponse('GET', '/test', 'Main
Target Content
')
createProcessedHTML('Click
Original
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('#custom', 'Target Content')
})
it('swaps oob with target: modifier and multi-word selector', async function () {
mockResponse('GET', '/test', 'Main
Multi Selector
')
createProcessedHTML('Click
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('.foo .bar', 'Multi Selector')
})
it('swaps oob with legacy colon format', async function () {
mockResponse('GET', '/test', 'Main
Legacy Format
')
createProcessedHTML('Click
Original
');
find('[hx-get]').click()
await forRequest()
assertTextContentIs('#legacy', 'Legacy Format')
})
it('swaps oob to all elements matching a class selector', async function () {
mockResponse('GET', '/test', 'Main
Updated
')
createProcessedHTML('Click
A
B
');
find('[hx-get]').click()
await forRequest()
playground().querySelectorAll('.target').forEach(el => el.innerText.should.equal('Updated'))
})
})