describe('hx-on:* attribute', function() { beforeEach(function() { this.server = makeServer() clearWorkArea() }) afterEach(function() { this.server.restore() clearWorkArea() }) it('can handle basic events w/ no other attributes', function() { var btn = make("") btn.click() window.foo.should.equal(true) delete window.foo }) it('can use dashes rather than colons', function() { var btn = make("") btn.click() window.foo.should.equal(true) delete window.foo }) it('can modify a parameter via htmx:configRequest', function() { this.server.respondWith('POST', '/test', function(xhr) { var params = parseParams(xhr.requestBody) xhr.respond(200, {}, params.foo) }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('bar') }) it('can modify a parameter via htmx:configRequest with dashes', function() { this.server.respondWith('POST', '/test', function(xhr) { var params = parseParams(xhr.requestBody) xhr.respond(200, {}, params.foo) }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('bar') }) it('expands :: shorthand into htmx:', function() { this.server.respondWith('POST', '/test', function(xhr) { var params = parseParams(xhr.requestBody) xhr.respond(200, {}, params.foo) }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('bar') }) it('expands -- shorthand into htmx:', function() { this.server.respondWith('POST', '/test', function(xhr) { var params = parseParams(xhr.requestBody) xhr.respond(200, {}, params.foo) }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('bar') }) it('can cancel an event via preventDefault for htmx:config-request', function() { this.server.respondWith('POST', '/test', function(xhr) { xhr.respond(200, {}, '') }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('Foo') }) it('can respond to data-hx-on', function() { this.server.respondWith('POST', '/test', function(xhr) { var params = parseParams(xhr.requestBody) xhr.respond(200, {}, params.foo) }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('bar') }) it('has the this symbol set to the element', function() { this.server.respondWith('POST', '/test', function(xhr) { xhr.respond(200, {}, 'foo') }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('foo') btn.should.equal(window.elt) delete window.elt }) it('can handle multi-line JSON', function() { this.server.respondWith('POST', '/test', function(xhr) { xhr.respond(200, {}, 'foo') }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('foo') var obj = { foo: true, bar: false } obj.should.deep.equal(window.elt) delete window.elt }) it('can handle multiple event handlers in the presence of multi-line JSON', function() { this.server.respondWith('POST', '/test', function(xhr) { xhr.respond(200, {}, 'foo') }) var btn = make("") btn.click() this.server.respond() btn.innerText.should.equal('foo') var obj = { foo: true, bar: false } obj.should.deep.equal(window.elt) delete window.elt window.foo.should.equal(true) delete window.foo }) it('de-initializes hx-on-* content properly', function() { window.tempCount = 0 this.server.respondWith('POST', '/test', function(xhr) { xhr.respond(200, {}, "") }) var div = make("