mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-30 22:41:23 +00:00

* `timeout` - the request timeout * `credentials` - send credentials w/ the request * `noHeaders` - do not send any non-standard headers with the request We also support the `htmx.config.timeout` configuration value for setting the default timeout
39 lines
1.3 KiB
JavaScript
39 lines
1.3 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;
|
|
this.server.respondWith("GET", "/test", "Clicked!");
|
|
var div = make("<div hx-post='/vars' hx-request='\"timeout\":1'></div>")
|
|
htmx.on(div, 'htmx:timeout', function(){
|
|
timedOut = true;
|
|
})
|
|
div.click();
|
|
setTimeout(function(){
|
|
div.innerHTML.should.equal("");
|
|
// unfortunately it looks like sinon.js doesn't implement the timeout functionality
|
|
// timedOut.should.equal(true);
|
|
done();
|
|
}, 400)
|
|
});
|
|
|
|
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!");
|
|
});
|
|
|
|
|
|
}); |