mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 23:35:13 +00:00
bump to 0.1.2 and add test for namespaced event and extension
This commit is contained in:
parent
e088280f01
commit
7d49d5ab58
@ -5,7 +5,7 @@
|
|||||||
"AJAX",
|
"AJAX",
|
||||||
"HTML"
|
"HTML"
|
||||||
],
|
],
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"homepage": "https://htmx.org/",
|
"homepage": "https://htmx.org/",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/bigskysoftware/htmx/issues"
|
"url": "https://github.com/bigskysoftware/htmx/issues"
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
describe("hx-ext attribute", function() {
|
describe("hx-ext attribute", function() {
|
||||||
|
|
||||||
var ext1Calls, ext2Calls, ext3Calls;
|
var ext1Calls, ext2Calls, ext3Calls, ext4Calls;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
ext1Calls = ext2Calls = ext3Calls = 0;
|
ext1Calls = ext2Calls = ext3Calls = ext4Calls = 0;
|
||||||
this.server = makeServer();
|
this.server = makeServer();
|
||||||
clearWorkArea();
|
clearWorkArea();
|
||||||
htmx.defineExtension("ext-1", {
|
htmx.defineExtension("ext-1", {
|
||||||
@ -27,6 +27,13 @@ describe("hx-ext attribute", function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
htmx.defineExtension("ext-4", {
|
||||||
|
onEvent : function(name, evt) {
|
||||||
|
if(name === "namespace:example"){
|
||||||
|
ext4Calls++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@ -94,5 +101,16 @@ describe("hx-ext attribute", function() {
|
|||||||
ext3Calls.should.equal(0);
|
ext3Calls.should.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('A simple extension is invoked properly when an HX-Trigger event w/ a namespace fires', function () {
|
||||||
|
this.server.respondWith("GET", "/test", [200, {"HX-Trigger":"namespace:example"}, ""]);
|
||||||
|
var btn = make('<button data-hx-get="/test" data-hx-ext="ext-4">Click Me!</button>')
|
||||||
|
btn.click();
|
||||||
|
this.server.respond();
|
||||||
|
ext1Calls.should.equal(0);
|
||||||
|
ext2Calls.should.equal(0);
|
||||||
|
ext3Calls.should.equal(0);
|
||||||
|
ext4Calls.should.equal(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
@ -61,6 +61,19 @@ describe("Core htmx AJAX headers", function() {
|
|||||||
invokedEvent.should.equal(true);
|
invokedEvent.should.equal(true);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle a namespaced HX-Trigger response header properly", function(){
|
||||||
|
this.server.respondWith("GET", "/test", [200, {"HX-Trigger" : "namespace:foo"}, ""]);
|
||||||
|
|
||||||
|
var div = make('<div hx-get="/test"></div>');
|
||||||
|
var invokedEvent = false;
|
||||||
|
div.addEventListener("namespace:foo", function (evt) {
|
||||||
|
invokedEvent = true;
|
||||||
|
});
|
||||||
|
div.click();
|
||||||
|
this.server.respond();
|
||||||
|
invokedEvent.should.equal(true);
|
||||||
|
})
|
||||||
|
|
||||||
it("should handle basic JSON HX-Trigger response header properly", function(){
|
it("should handle basic JSON HX-Trigger response header properly", function(){
|
||||||
this.server.respondWith("GET", "/test", [200, {"HX-Trigger" : "{\"foo\":null}"}, ""]);
|
this.server.respondWith("GET", "/test", [200, {"HX-Trigger" : "{\"foo\":null}"}, ""]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user