Skip to content

Commit

Permalink
test + test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
carson committed May 26, 2020
1 parent 1159d13 commit d144742
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ return (function () {
}

// resolve with both hx and data-hx prefixes
function hasAttribute(elt, qualifiedName) {
return elt.hasAttribute && (elt.hasAttribute(qualifiedName) ||
elt.hasAttribute("data-" + qualifiedName));
}

function getAttributeValue(elt, qualifiedName) {
return getRawAttribute(elt, qualifiedName) || getRawAttribute(elt, "data-" + qualifiedName);
}
Expand Down Expand Up @@ -825,7 +830,7 @@ return (function () {
function processVerbs(elt, nodeData, triggerSpecs) {
var explicitAction = false;
forEach(VERBS, function (verb) {
if (elt.hasAttribute('hx-' + verb)) {
if (hasAttribute(elt,'hx-' + verb)) {
var path = getAttributeValue(elt, 'hx-' + verb);
explicitAction = true;
nodeData.path = path;
Expand Down Expand Up @@ -1334,9 +1339,11 @@ return (function () {
unfilteredParameters:rawParameters,
headers:headers,
target:target,
verb:verb
verb:verb,
path:path
};
if(!triggerEvent(elt, 'configRequest.htmx', requestConfig)) return endRequestLock();
path = requestConfig.path;

var splitPath = path.split("#");
var pathNoAnchor = splitPath[0];
Expand Down
25 changes: 25 additions & 0 deletions test/core/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ describe("Core htmx AJAX Tests", function(){
window.callGlobal = function() {
globalWasCalled = true;
}

it('script nodes evaluate', function()
{
try {
Expand All @@ -425,5 +426,29 @@ describe("Core htmx AJAX Tests", function(){
}
});

it('allows empty verb values', function()
{
var path = null;
var div = make("<div hx-get=''/>");
htmx.on(div, "configRequest.htmx", function (evt) {
path = evt.detail.path;
return false;
});
div.click();
path.should.not.be.null;
});

it('allows blank verb values', function()
{
var path = null;
var div = make("<div hx-get/>");
htmx.on(div, "configRequest.htmx", function (evt) {
path = evt.detail.path;
return false;
});
div.click();
path.should.not.be.null;
});


})

0 comments on commit d144742

Please sign in to comment.