fix test - had to turn off the sinon fake server and issue a real garbage request, and rewrite it as an async test

This commit is contained in:
carson
2020-09-01 18:05:36 -06:00
parent 8983448b33
commit 43cee3156e

View File

@@ -172,22 +172,19 @@ describe("Core htmx Events", function() {
}
});
it("htmx:sendError is called after a failed request", function () {
it("htmx:sendError is called after a failed request", function (done) {
var called = false;
var handler = htmx.on("htmx:sendError", function (evt) {
called = true;
});
try {
this.server.respondWith("POST", "/test", function (xhr) {
xhr.respond(200, {}, "");
});
var div = make("<button hx-post='/test'>Foo</button>");
div.click();
this.server.respond();
should.equal(called, true);
} finally {
this.server.restore(); // turn off server mock so connection doesn't work
var div = make("<button hx-post='file://foo'>Foo</button>");
div.click();
setTimeout(function () {
htmx.off("htmx:sendError", handler);
}
should.equal(called, true);
done();
}, 30);
});
});