From a2f390af85cb700029b99090a25b6fe831f66eee Mon Sep 17 00:00:00 2001 From: Alexander Petros Date: Sat, 5 Aug 2023 14:10:25 -0400 Subject: [PATCH] Move load tests to the bottom of the core file This "resolves" a timing bug that was ocurring in the CI, where these tests would run before htmx was loaded (only in the GitHub actions servers). Not proud of this as a fix but I would like the CI to work again ASAP. --- test/core/api.js | 116 +++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 58 deletions(-) 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); + }); + })