htmx/test/attributes/hx-request.js
MichaelWest22 24a0106f76
Update testing framework to web-test-runner and improve code coverage (#3273)
* Fix old npm dependencies

* implement web-test-runner tests for headless alongside Mocha browser tests

* Increase test and code coverage

* update to 100% coverage and impove eslint

* Update testing Doco

* revert all htmx changes and updates/disable tests needed

* fix browser mocha test

* Default testing to use playwrite only instead of puppeter

* playwright install fix

* Imporve test summary reporting

* flatten false looks closer to original
2025-04-17 17:55:43 -06:00

39 lines
1.1 KiB
JavaScript

describe('hx-request attribute', function() {
beforeEach(function() {
this.server = makeServer()
clearWorkArea()
})
afterEach(function() {
this.server.restore()
clearWorkArea()
})
it('basic hx-request timeout works', function(done) {
var timedOut = false
htmx.config.selfRequestsOnly = false
var div = make("<div hx-post='https://hypermedia.systems/www/test' hx-request='\"timeout\":1'></div>")
htmx.on(div, 'htmx:timeout', function() {
timedOut = true
})
this.server.restore() // use real xhrs
div.click()
setTimeout(function() {
htmx.config.selfRequestsOnly = true
div.innerHTML.should.equal('')
timedOut.should.equal(true)
done()
}, 30)
})
it('hx-request header works', function() {
this.server.respondWith('POST', '/vars', function(xhr) {
should.equal(xhr.requestHeaders['HX-Request'], undefined)
xhr.respond(200, {}, 'Clicked!')
})
var div = make("<div hx-post='/vars' hx-request='{\"noHeaders\":true}'></div>")
div.click()
this.server.respond()
div.innerHTML.should.equal('Clicked!')
})
})