diff --git a/src/htmx.js b/src/htmx.js index 916203b58..8df147ef2 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -527,7 +527,7 @@ var htmx = (() => { }) if (!this.__trigger(elt, "htmx:config:request", {ctx: ctx})) return - if (!this.#verbs.includes(ctx.request.method.toLowerCase())) return + if (ctx.request.method === 'DIALOG') return let javascriptContent = this.__extractJavascriptContent(ctx.request.action); if (javascriptContent != null) { diff --git a/test/lib/fetch-mock.js b/test/lib/fetch-mock.js index 52372ac3f..b2e74ed22 100644 --- a/test/lib/fetch-mock.js +++ b/test/lib/fetch-mock.js @@ -85,7 +85,7 @@ class FetchMock { // Mock a response for a specific URL pattern mockResponse(method, urlPattern, response, options = {}) { let upperCasedMethod = method.toUpperCase(); - if (['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].indexOf(upperCasedMethod) < 0) { + if (['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'QUERY'].indexOf(upperCasedMethod) < 0) { throw Error("Invalid HTTP method: " + method) } if (typeof response === 'string') { diff --git a/test/tests/attributes/hx-action.js b/test/tests/attributes/hx-action.js index 1c2834199..f0030ba72 100644 --- a/test/tests/attributes/hx-action.js +++ b/test/tests/attributes/hx-action.js @@ -53,4 +53,13 @@ describe('hx-action attribute', function() { playground().innerHTML.should.equal('Put!') }) + it('hx-action with hx-method QUERY issues a QUERY request', async function() { + mockResponse('QUERY', '/test', 'Queried!') + let btn = createProcessedHTML('') + btn.click() + await forRequest() + fetchMock.calls[0].request.method.should.equal('QUERY') + btn.innerHTML.should.equal('Queried!') + }) + }) diff --git a/test/tests/unit/__handleTriggerEvent.js b/test/tests/unit/__handleTriggerEvent.js index 8f74e30f1..d53cf8304 100644 --- a/test/tests/unit/__handleTriggerEvent.js +++ b/test/tests/unit/__handleTriggerEvent.js @@ -107,14 +107,6 @@ describe('__handleTriggerEvent unit tests', function() { assert.isUndefined(window.testExecuted) }) - it('returns early if method not in verbs list', async function () { - let div = createProcessedHTML('
') - let ctx = htmx.__createRequestContext(div, new Event('click')) - ctx.request.method = 'INVALID' - await htmx.__handleTriggerEvent(ctx) - assert.isUndefined(window.testExecuted) - }) - it('executes javascript when action starts with js:', async function () { let div = createProcessedHTML('') let ctx = htmx.__createRequestContext(div, new Event('click'))