From bb5413dfd2fc5842eda7a29a1bdc53aa92e177c4 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 21 Sep 2023 23:43:49 +0200 Subject: [PATCH] [Tests] Fix test pipeline timing issues (#1818) Fix test pipeline timing issues --- test/core/ajax.js | 6 +++--- test/core/parameters.js | 28 ++++++++++++++++++---------- test/core/security.js | 4 ++++ test/index.html | 6 ++++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/test/core/ajax.js b/test/core/ajax.js index ae33fd53d..3f4e740bb 100644 --- a/test/core/ajax.js +++ b/test/core/ajax.js @@ -969,15 +969,15 @@ describe("Core htmx AJAX Tests", function(){ it('scripts w/ src attribute are properly loaded', function(done) { try { - this.server.respondWith("GET", "/test", ""); + this.server.respondWith("GET", "/test", ""); var div = make("
"); div.click(); this.server.respond(); - setTimeout(function () { + byId("setGlobalScript").addEventListener("load", function () { window.globalWasCalled.should.equal(true); delete window.globalWasCalled; done(); - }, 400); + }) } finally { delete window.globalWasCalled; } diff --git a/test/core/parameters.js b/test/core/parameters.js index b7d74ba3e..fa6f62579 100644 --- a/test/core/parameters.js +++ b/test/core/parameters.js @@ -123,26 +123,34 @@ describe("Core htmx Parameter Handling", function() { htmx._("urlEncode")({"foo": "bar", "do" : ["rey", "blah"]}).should.equal("foo=bar&do=rey&do=blah"); }); - it('form includes last focused button', function () { + it('form includes last focused button', function (done) { var form = make('
'); var input = byId('i1'); var button = byId('b1'); + // Listen for focusin on form as it'll bubble up from the button, and htmx binds on the form itself + form.addEventListener("focusin", function () { + var vals = htmx._('getInputValues')(form).values; + vals['foo'].should.equal('bar'); + vals['do'].should.equal('rey'); + vals['btn'].should.equal('bar'); + done(); + }); button.focus(); - var vals = htmx._('getInputValues')(form).values; - vals['foo'].should.equal('bar'); - vals['do'].should.equal('rey'); - vals['btn'].should.equal('bar'); }) - it('form includes last focused submit', function () { + it('form includes last focused submit', function (done) { var form = make('
'); var input = byId('i1'); var button = byId('s1'); + // Listen for focusin on form as it'll bubble up from the button, and htmx binds on the form itself + form.addEventListener("focusin", function () { + var vals = htmx._('getInputValues')(form).values; + vals['foo'].should.equal('bar'); + vals['do'].should.equal('rey'); + vals['s1'].should.equal('bar'); + done(); + }); button.focus(); - var vals = htmx._('getInputValues')(form).values; - vals['foo'].should.equal('bar'); - vals['do'].should.equal('rey'); - vals['s1'].should.equal('bar'); }) it('form does not include button when focus is lost', function () { diff --git a/test/core/security.js b/test/core/security.js index 241c45264..95f173502 100644 --- a/test/core/security.js +++ b/test/core/security.js @@ -107,6 +107,7 @@ describe("security options", function() { }) it("can make egress cross site requests when htmx.config.selfRequestsOnly is enabled", function(done){ + this.timeout(4000) // should trigger send error, rather than reject var listener = htmx.on("htmx:sendError", function (){ htmx.off("htmx:sendError", listener); @@ -119,6 +120,7 @@ describe("security options", function() { }) it("can't make egress cross site requests when htmx.config.selfRequestsOnly is enabled", function(done){ + this.timeout(4000) // should trigger send error, rather than reject htmx.config.selfRequestsOnly = true; var listener = htmx.on("htmx:invalidPath", function (){ @@ -133,6 +135,7 @@ describe("security options", function() { }) it("can cancel egress request based on htmx:validateUrl event", function(done){ + this.timeout(4000) // should trigger send error, rather than reject var pathVerifier = htmx.on("htmx:validateUrl", function (evt){ evt.preventDefault(); @@ -149,6 +152,7 @@ describe("security options", function() { }) it("can cancel egress request based on htmx:validateUrl event, sameHost is false", function(done){ + this.timeout(4000) // should trigger send error, rather than reject var pathVerifier = htmx.on("htmx:validateUrl", function (evt){ if (evt.detail.sameHost === false) { diff --git a/test/index.html b/test/index.html index 6da68a49a..f747775b6 100644 --- a/test/index.html +++ b/test/index.html @@ -161,8 +161,10 @@

Mocha Test Suite

Work Area