can trigger an event for a given response code4ms ‣
var originalResponseHandling = htmx.config.responseHandling
var myEventWasTriggered = false
var handler = htmx.on('myEvent', function() {
myEventWasTriggered = true
})
try {
htmx.config.responseHandling = originalResponseHandling.slice()
htmx.config.responseHandling.unshift({ code: '444', swap: false, error: false, event: 'myEvent' })
var responseCode = null
this.server.respondWith('GET', '/test', function(xhr, id) {
xhr.respond(responseCode, { 'Content-Type': 'text/html' }, '' + responseCode)
})
responseCode = 444
var btn = make('<button hx-get="/test">Click Me!</button>')
btn.click()
this.server.respond()
btn.innerHTML.should.equal('Click Me!')
myEventWasTriggered.should.equal(true)
} finally {
htmx.off('htmx:responseError', handler)
htmx.config.responseHandling = originalResponseHandling
}