| 1 |
describe('hx-request attribute', function() { |
| 2 |
beforeEach(function() { |
| 3 |
this.server = makeServer() |
| 4 |
clearWorkArea() |
| 5 |
}) |
| 6 |
afterEach(function() { |
| 7 |
this.server.restore() |
| 8 |
clearWorkArea() |
| 9 |
}) |
| 10 |
|
| 11 |
it('basic hx-request timeout works', function(done) { |
| 12 |
var timedOut = false |
| 13 |
htmx.config.selfRequestsOnly = false |
| 14 |
var div = make("<div hx-post='https://hypermedia.systems/www/test' hx-request='\"timeout\":1'></div>") |
| 15 |
htmx.on(div, 'htmx:timeout', function() { |
| 16 |
timedOut = true |
| 17 |
}) |
| 18 |
this.server.restore() |
| 19 |
div.click() |
| 20 |
setTimeout(function() { |
| 21 |
htmx.config.selfRequestsOnly = true |
| 22 |
div.innerHTML.should.equal('') |
| 23 |
timedOut.should.equal(true) |
| 24 |
done() |
| 25 |
}, 30) |
| 26 |
}) |
| 27 |
|
| 28 |
it('hx-request header works', function() { |
| 29 |
this.server.respondWith('POST', '/vars', function(xhr) { |
| 30 |
should.equal(xhr.requestHeaders['HX-Request'], undefined) |
| 31 |
xhr.respond(200, {}, 'Clicked!') |
| 32 |
}) |
| 33 |
var div = make("<div hx-post='/vars' hx-request='{\"noHeaders\":true}'></div>") |
| 34 |
div.click() |
| 35 |
this.server.respond() |
| 36 |
div.innerHTML.should.equal('Clicked!') |
| 37 |
}) |
| 38 |
}) |