[Tests] Fix test pipeline timing issues (#1818)

Fix test pipeline timing issues
This commit is contained in:
Vincent 2023-09-21 23:43:49 +02:00 committed by GitHub
parent 8da65b94e5
commit bb5413dfd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 15 deletions

View File

@ -969,15 +969,15 @@ describe("Core htmx AJAX Tests", function(){
it('scripts w/ src attribute are properly loaded', function(done) it('scripts w/ src attribute are properly loaded', function(done)
{ {
try { try {
this.server.respondWith("GET", "/test", "<script src='setGlobal.js'></script>"); this.server.respondWith("GET", "/test", "<script id='setGlobalScript' src='setGlobal.js'></script>");
var div = make("<div hx-get='/test'></div>"); var div = make("<div hx-get='/test'></div>");
div.click(); div.click();
this.server.respond(); this.server.respond();
setTimeout(function () { byId("setGlobalScript").addEventListener("load", function () {
window.globalWasCalled.should.equal(true); window.globalWasCalled.should.equal(true);
delete window.globalWasCalled; delete window.globalWasCalled;
done(); done();
}, 400); })
} finally { } finally {
delete window.globalWasCalled; delete window.globalWasCalled;
} }

View File

@ -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"); 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('<form hx-get="/foo"><input id="i1" name="foo" value="bar"/><input id="i2" name="do" value="rey"/><button id="b1" name="btn" value="bar"></button></form>'); var form = make('<form hx-get="/foo"><input id="i1" name="foo" value="bar"/><input id="i2" name="do" value="rey"/><button id="b1" name="btn" value="bar"></button></form>');
var input = byId('i1'); var input = byId('i1');
var button = byId('b1'); 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(); 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('<form hx-get="/foo"><input id="i1" name="foo" value="bar"/><input id="i2" name="do" value="rey"/><input type="submit" id="s1" name="s1" value="bar"/></form>'); var form = make('<form hx-get="/foo"><input id="i1" name="foo" value="bar"/><input id="i2" name="do" value="rey"/><input type="submit" id="s1" name="s1" value="bar"/></form>');
var input = byId('i1'); var input = byId('i1');
var button = byId('s1'); 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(); 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 () { it('form does not include button when focus is lost', function () {

View File

@ -107,6 +107,7 @@ describe("security options", function() {
}) })
it("can make egress cross site requests when htmx.config.selfRequestsOnly is enabled", function(done){ 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 // should trigger send error, rather than reject
var listener = htmx.on("htmx:sendError", function (){ var listener = htmx.on("htmx:sendError", function (){
htmx.off("htmx:sendError", listener); 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){ 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 // should trigger send error, rather than reject
htmx.config.selfRequestsOnly = true; htmx.config.selfRequestsOnly = true;
var listener = htmx.on("htmx:invalidPath", function (){ 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){ it("can cancel egress request based on htmx:validateUrl event", function(done){
this.timeout(4000)
// should trigger send error, rather than reject // should trigger send error, rather than reject
var pathVerifier = htmx.on("htmx:validateUrl", function (evt){ var pathVerifier = htmx.on("htmx:validateUrl", function (evt){
evt.preventDefault(); 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){ 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 // should trigger send error, rather than reject
var pathVerifier = htmx.on("htmx:validateUrl", function (evt){ var pathVerifier = htmx.on("htmx:validateUrl", function (evt){
if (evt.detail.sameHost === false) { if (evt.detail.sameHost === false) {

View File

@ -161,8 +161,10 @@
<div id="mocha"></div> <div id="mocha"></div>
<script class="mocha-exec"> <script class="mocha-exec">
mocha.setup({globals: ['$0', '$1', '$2', '$3', '$4', 'performance', 'requestAnimationFrame', 'cancelAnimationFrame']}); <!-- IE11 --> document.addEventListener("DOMContentLoaded", function () {
mocha.run(); mocha.setup({globals: ['$0', '$1', '$2', '$3', '$4', 'performance', 'requestAnimationFrame', 'cancelAnimationFrame']}); <!-- IE11 -->
mocha.run();
})
</script> </script>
<em>Work Area</em> <em>Work Area</em>
<hr/> <hr/>