Skip to content

Commit

Permalink
[Tests] Fix test pipeline timing issues (#1818)
Browse files Browse the repository at this point in the history
Fix test pipeline timing issues
  • Loading branch information
Telroshan authored Sep 21, 2023
1 parent 8da65b9 commit bb5413d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
6 changes: 3 additions & 3 deletions test/core/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<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>");
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;
}
Expand Down
28 changes: 18 additions & 10 deletions test/core/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<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 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('<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 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 () {
Expand Down
4 changes: 4 additions & 0 deletions test/core/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 (){
Expand All @@ -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();
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ <h2>Mocha Test Suite</h2>
<div id="mocha"></div>

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

0 comments on commit bb5413d

Please sign in to comment.