Skip to content

Commit ec3906d

Browse files
committed
Fix indenting and add tests
1 parent a7672f7 commit ec3906d

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

test/attributes/hx-swap.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,11 @@ describe('hx-swap attribute', function() {
318318
)
319319
div.click()
320320
this.server.respond()
321+
div.innerText.should.equal('')
321322
setTimeout(function() {
322323
div.innerText.should.equal('Clicked!')
323324
done()
324-
}, 100)
325+
}, 30)
325326
})
326327

327328
it('works with a settle delay', function(done) {
@@ -538,8 +539,9 @@ describe('hx-swap attribute', function() {
538539

539540
it('swapError fires if swap throws exception', function() {
540541
try {
541-
htmx._('htmx.backupSwap = swap')
542-
htmx._('swap = function() { throw new Error("throw") }')
542+
// override makeSettleInfo to cause swap function to throw exception
543+
htmx._('htmx.backupMakeSettleInfo = makeSettleInfo')
544+
htmx._('makeSettleInfo = function() { throw new Error("throw") }')
543545
var error = false
544546
var handler = htmx.on('htmx:swapError', function(evt) {
545547
error = true
@@ -554,7 +556,7 @@ describe('hx-swap attribute', function() {
554556
div.innerHTML.should.equal('')
555557
error.should.equal(true)
556558
htmx.off('htmx:swapError', handler)
557-
htmx._('swap = htmx.backupSwap')
559+
htmx._('makeSettleInfo = htmx.backupMakeSettleInfo')
558560
}
559561
})
560562
})

test/core/api.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,17 @@ describe('Core htmx API test', function() {
494494
}, 30)
495495
})
496496

497+
it('swap works with a view transition', function(done) {
498+
var div = make("<div hx-get='/test'></div>")
499+
div.innerText.should.equal('')
500+
htmx.swap(div, 'jsswapped', { transition: true })
501+
div.innerText.should.equal('')
502+
setTimeout(function() {
503+
div.innerText.should.equal('jsswapped')
504+
done()
505+
}, 30)
506+
})
507+
497508
it('swaps content properly (with select)', function() {
498509
var output = make('<output id="output"/>')
499510
htmx.swap('#output', '<div><p id="select-me">Swapped!</p></div>', { swapStyle: 'innerHTML' }, { select: '#select-me' })

0 commit comments

Comments
 (0)