mirror of
https://github.com/bigskysoftware/htmx.git
synced 2026-03-06 22:19:17 +00:00
Handle situation when there are no extensions that add custom swaps gracefully
This commit is contained in:
parent
b1dec6a349
commit
eef2379c8b
@ -1323,7 +1323,7 @@ var htmx = (() => {
|
||||
this.__insertNodes(parentNode, target.nextSibling, fragment);
|
||||
}
|
||||
} else {
|
||||
let methods = this.__extMethods.get('handle_swap')
|
||||
let methods = this.__extMethods.get('handle_swap') || []
|
||||
let handled = false;
|
||||
for (const method of methods) {
|
||||
let result = method(swapStyle, target, fragment, swapSpec);
|
||||
|
||||
@ -258,4 +258,22 @@ describe('__issueRequest unit tests', function() {
|
||||
assert.isTrue(ctx.request.signal.aborted)
|
||||
})
|
||||
|
||||
it('throws clean error for unknown swap style with no extensions', async function () {
|
||||
let div = createProcessedHTML('<div hx-get="/test" hx-swap="foobar"></div>')
|
||||
let ctx = htmx.__createRequestContext(div, new Event('click'))
|
||||
|
||||
ctx.fetch = async () => ({
|
||||
status: 200,
|
||||
headers: new Headers(),
|
||||
text: async () => '<div>Response</div>'
|
||||
})
|
||||
|
||||
let capturedError = null
|
||||
div.addEventListener('htmx:error', (e) => capturedError = e.detail.error)
|
||||
|
||||
await htmx.__issueRequest(ctx)
|
||||
assert.isNotNull(capturedError)
|
||||
assert.include(capturedError.message, 'Unknown swap style')
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user