diff --git a/test/core/api.js b/test/core/api.js index 28f21a41c..8a6f000fe 100644 --- a/test/core/api.js +++ b/test/core/api.js @@ -8,64 +8,6 @@ describe("Core htmx API test", function(){ clearWorkArea(); }); - it('onLoad is called... onLoad', function(done){ - // also tests on/off - this.server.respondWith("GET", "/test", "
") - var helper = htmx.onLoad(function (elt) { - elt.setAttribute("foo", "bar"); - }); - var server = this.server; - setTimeout(function() { - try { - var div = make("
"); - div.click(); - server.respond(); - byId("d1").getAttribute("foo").should.equal("bar"); - done(); - } finally { - htmx.off("htmx:load", helper); - } - }, 10) - }); - - it('triggers properly', function () { - var div = make("
"); - var myEventCalled = false; - var detailStr = ""; - htmx.on("myEvent", function(evt){ - myEventCalled = true; - detailStr = evt.detail.str; - }) - htmx.trigger(div, "myEvent", {str:"foo"}) - - myEventCalled.should.equal(true); - detailStr.should.equal("foo"); - }); - - it('triggers properly w/ selector', function () { - var div = make("
"); - var myEventCalled = false; - var detailStr = ""; - htmx.on("myEvent", function(evt){ - myEventCalled = true; - detailStr = evt.detail.str; - }) - htmx.trigger("#div1", "myEvent", {str:"foo"}) - - myEventCalled.should.equal(true); - detailStr.should.equal("foo"); - }); - - it('triggers with no details properly', function () { - var div = make("
"); - var myEventCalled = false; - htmx.on("myEvent", function(evt){ - myEventCalled = true; - }) - htmx.trigger(div, "myEvent") - myEventCalled.should.equal(true); - }); - it('should find properly', function(){ var div = make("
"); div.should.equal(htmx.find("#d1")); @@ -340,4 +282,62 @@ describe("Core htmx API test", function(){ div.innerHTML.should.equal("delete"); }) + it('onLoad is called... onLoad', function(){ + // also tests on/off + this.server.respondWith("GET", "/test", "
") + var helper = htmx.onLoad(function (elt) { + elt.setAttribute("foo", "bar"); + }); + + try { + var div = make("
"); + div.click(); + this.server.respond(); + byId("d1").getAttribute("foo").should.equal("bar"); + htmx.off("htmx:load", helper); + } catch (error) { + // Clean up the event if the test fails, then throw it again + htmx.off("htmx:load", helper); + throw error; + } + }); + + it('triggers properly', function () { + var div = make("
"); + var myEventCalled = false; + var detailStr = ""; + htmx.on("myEvent", function(evt){ + myEventCalled = true; + detailStr = evt.detail.str; + }) + htmx.trigger(div, "myEvent", {str:"foo"}) + + myEventCalled.should.equal(true); + detailStr.should.equal("foo"); + }); + + it('triggers properly w/ selector', function () { + var div = make("
"); + var myEventCalled = false; + var detailStr = ""; + htmx.on("myEvent", function(evt){ + myEventCalled = true; + detailStr = evt.detail.str; + }) + htmx.trigger("#div1", "myEvent", {str:"foo"}) + + myEventCalled.should.equal(true); + detailStr.should.equal("foo"); + }); + + it('triggers with no details properly', function () { + var div = make("
"); + var myEventCalled = false; + htmx.on("myEvent", function(evt){ + myEventCalled = true; + }) + htmx.trigger(div, "myEvent") + myEventCalled.should.equal(true); + }); + })