support unset to, well, unset attributes

This commit is contained in:
carson 2021-09-19 16:41:31 -06:00
parent 7a858fab42
commit e3cb9b591a
2 changed files with 31 additions and 1 deletions

View File

@ -128,8 +128,10 @@ return (function () {
getClosestMatch(elt, function (e) { getClosestMatch(elt, function (e) {
return closestAttr = getAttributeValue(e, attributeName); return closestAttr = getAttributeValue(e, attributeName);
}); });
if (closestAttr !== "unset") {
return closestAttr; return closestAttr;
} }
}
function matches(elt, selector) { function matches(elt, selector) {
// noinspection JSUnresolvedVariable // noinspection JSUnresolvedVariable

View File

@ -1,5 +1,14 @@
describe("Core htmx internals Tests", function() { describe("Core htmx internals Tests", function() {
beforeEach(function () {
this.server = makeServer();
clearWorkArea();
});
afterEach(function () {
this.server.restore();
clearWorkArea();
});
it("makeFragment works with janky stuff", function(){ it("makeFragment works with janky stuff", function(){
htmx._("makeFragment")("<html></html>").tagName.should.equal("BODY"); htmx._("makeFragment")("<html></html>").tagName.should.equal("BODY");
htmx._("makeFragment")("<html><body></body></html>").tagName.should.equal("BODY"); htmx._("makeFragment")("<html><body></body></html>").tagName.should.equal("BODY");
@ -35,6 +44,7 @@ describe("Core htmx internals Tests", function() {
} }
}) })
it("makeFragment works with template wrapping and funky combos", function(){ it("makeFragment works with template wrapping and funky combos", function(){
htmx.config.useTemplateFragments = true; htmx.config.useTemplateFragments = true;
try { try {
@ -98,4 +108,22 @@ describe("Core htmx internals Tests", function() {
}) })
it("unset properly unsets a given attribute", function(){
make("<div foo='1'><div foo='2'><div foo='unset' id='d1'></div></div></div>");
var div = byId("d1");
should.equal(undefined, htmx._("getClosestAttributeValue")(div, "foo"));
})
it("unset properly unsets a given attribute on a parent", function(){
make("<div foo='1'><div foo='unset'><div id='d1'></div></div></div>");
var div = byId("d1");
should.equal(undefined, htmx._("getClosestAttributeValue")(div, "foo"));
})
it("unset does not unset a value below it in the hierarchy", function(){
make("<div foo='unset'><div foo='2'><div id='d1'></div></div></div>");
var div = byId("d1");
should.equal("2", htmx._("getClosestAttributeValue")(div, "foo"));
})
}); });