new afterOnLoad and afterRequest tests

To make sure these are fired when using outerHTML swapping
This commit is contained in:
Alejandro Schmeichler 2020-09-01 19:49:56 -04:00 committed by GitHub
parent 8983448b33
commit da1707b5a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -189,6 +189,42 @@ describe("Core htmx Events", function() {
htmx.off("htmx:sendError", handler);
}
});
it("htmx:afterRequest is called when replacing outerHTML", function () {
var called = false;
var handler = htmx.on("htmx:afterRequest", function (evt) {
called = true;
});
try {
this.server.respondWith("POST", "/test", function (xhr) {
xhr.respond(200, {}, "<button>Bar</button>");
});
var div = make("<button hx-post='/test' hx-swap='outerHTML'>Foo</button>");
div.click();
this.server.respond();
should.equal(called, true);
} finally {
htmx.off("htmx:afterRequest", handler);
}
});
it("htmx:afterOnLoad is called when replacing outerHTML", function () {
var called = false;
var handler = htmx.on("htmx:afterOnLoad", function (evt) {
called = true;
});
try {
this.server.respondWith("POST", "/test", function (xhr) {
xhr.respond(200, {}, "<button>Bar</button>");
});
var div = make("<button hx-post='/test' hx-swap='outerHTML'>Foo</button>");
div.click();
this.server.respond();
should.equal(called, true);
} finally {
htmx.off("htmx:afterOnLoad", handler);
}
});
});