summaryrefslogtreecommitdiffstatshomepage
path: root/www/static/test
diff options
context:
space:
mode:
Diffstat (limited to 'www/static/test')
-rw-r--r--www/static/test/core/internals.js5
-rw-r--r--www/static/test/core/regressions.js42
2 files changed, 47 insertions, 0 deletions
diff --git a/www/static/test/core/internals.js b/www/static/test/core/internals.js
index e3d4f96d..9b6d0b97 100644
--- a/www/static/test/core/internals.js
+++ b/www/static/test/core/internals.js
@@ -107,6 +107,11 @@ describe('Core htmx internals Tests', function() {
htmx._('shouldCancel')({ type: 'submit', target: anchorThatShouldNotCancel }, form).should.equal(false)
htmx._('shouldCancel')({ type: 'click', target: divThatShouldNotCancel }, form).should.equal(false)
+ // check elements inside links getting click events should cancel parent links
+ var anchorWithButton = make("<a href='/foo'><button></button></a>")
+ htmx._('shouldCancel')({ type: 'click', target: anchorWithButton.firstChild }, anchorWithButton).should.equal(true)
+ htmx._('shouldCancel')({ type: 'click', target: anchorWithButton.firstChild }, anchorWithButton.firstChild).should.equal(true)
+
form = make('<form id="f1">' +
'<input id="insideInput" type="submit">' +
'<button id="insideFormBtn"></button>' +
diff --git a/www/static/test/core/regressions.js b/www/static/test/core/regressions.js
index 015b5815..91a35a0e 100644
--- a/www/static/test/core/regressions.js
+++ b/www/static/test/core/regressions.js
@@ -291,4 +291,46 @@ describe('Core htmx Regression Tests', function() {
byId('datefield').click()
})
+
+ it('a button clicked inside an htmx enabled link will prevent the link from navigating on click', function(done) {
+ var defaultPrevented = 'unset'
+ var link = make('<a href="/foo" hx-get="/foo"><button>test</button></a>')
+ var button = link.firstChild
+
+ htmx.on(link, 'click', function(evt) {
+ // we need to wait so the state of the evt is finalized
+ setTimeout(() => {
+ defaultPrevented = evt.defaultPrevented
+ try {
+ defaultPrevented.should.equal(true)
+ done()
+ } catch (err) {
+ done(err)
+ }
+ }, 0)
+ })
+
+ button.click()
+ })
+
+ it('a htmx enabled button clicked inside a link will prevent the link from navigating on click', function(done) {
+ var defaultPrevented = 'unset'
+ var link = make('<a href="/foo"><button hx-get="/foo">test</button></a>')
+ var button = link.firstChild
+
+ htmx.on(link, 'click', function(evt) {
+ // we need to wait so the state of the evt is finalized
+ setTimeout(() => {
+ defaultPrevented = evt.defaultPrevented
+ try {
+ defaultPrevented.should.equal(true)
+ done()
+ } catch (err) {
+ done(err)
+ }
+ }, 0)
+ })
+
+ button.click()
+ })
})