;; AUTO-GENERATED from spec/tests/hyperscript-upstream-tests.json
;; DO NOT EDIT — regenerate with:
;;   python3 tests/playwright/generate-sx-tests.py --emit-pages

(defcomp ()
  (~docs/page :title "Hyperscript: on (63 tests — 54 runnable)"
    (p :style "color:#57534e;margin-bottom:1rem" "Live cards for the upstream on tests. 54 of 63 are reproducible in-browser; the remainder show their source for reference.")
    (p :style "color:#78716c;font-size:0.875rem;margin-bottom:1rem"
      "Theme: " (a :href "/sx/(applications.(hyperscript.gallery-events))"
        :style "color:#7c3aed" "events"))
    (div :style "display:flex;flex-direction:column"
      (~hyperscript/hs-test-card
  :name "can respond to events with dots in names"
  :html "<div _='on click send example.event to #d1'></div> | <div id='d1' _='on example.event add .called'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click send example.event to #d1\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on example.event add .called\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (hs-activate! _el-d1)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "can respond to events with colons in names"
  :html "<div _='on click send example:event to #d1'></div> | <div id='d1' _='on example:event add .called'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click send example:event to #d1\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on example:event add .called\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (hs-activate! _el-d1)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "can respond to events with minus in names"
  :html "<div _='on click send \"a-b\" to #d1'></div> | <div id='d1' _='on \"a-b\" add .called'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"called\").should.equal(false) && div.classList.contains(\"called\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click send \\\"a-b\\\" to #d1\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on \\\"a-b\\\" add .called\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-d1)
    (hs-activate! _el-div)
    (hs-activate! _el-d1)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"called\"))
  ))")
(~hyperscript/hs-test-card
  :name "can respond to events on other elements"
  :html "<div id='bar'></div> | <div _='on click from #bar add .clicked'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"clicked\").should.equal(false) && div.classList.contains(\"clicked\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-bar (dom-create-element \"div\")) (_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-bar \"id\" \"bar\")
    (dom-set-attr _el-div \"_\" \"on click from #bar add .clicked\")
    (dom-append sandbox _el-bar)
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-bar \"click\" nil)
    (assert (dom-has-class? _el-div \"clicked\"))
  ))")
(~hyperscript/hs-test-card
  :name "listeners on other elements are removed when the registering element is removed"
  :html "<div id='bar'></div> | <div _='on click from #bar set #bar.innerHTML to #bar.innerHTML + \"a\"'></div>"
  :action "bar.click(); bar.click()"
  :check "bar.innerHTML.should.equal(\"\") && bar.innerHTML.should.equal(\"a\") && bar.innerHTML.should.equal(\"a\")"
  :run-src "(fn (sandbox)
  (let ((_el-bar (dom-create-element \"div\")) (_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-bar \"id\" \"bar\")
    (dom-set-attr _el-div \"_\" \"on click from #bar set #bar.innerHTML to #bar.innerHTML + \\\"a\\\"\")
    (dom-append sandbox _el-bar)
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-bar \"click\" nil)
    (dom-dispatch _el-bar \"click\" nil)
    (assert= (dom-inner-html _el-bar) \"a\")
  ))")
(~hyperscript/hs-test-card
  :name "listeners on self are not removed when the element is removed"
  :html "<div _='on someCustomEvent put 1 into me'></div>"
  :action "div.remove(); div.dispatchEvent(new Event(\"someCustomEvent\")"
  :check "div.innerHTML.should.equal(\"1\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "supports \"elsewhere\" modifier"
  :html "<div _='on click elsewhere add .clicked'></div>"
  :action "div.click(); body.click()"
  :check "div.classList.contains(\"clicked\").should.equal(false) && div.classList.contains(\"clicked\").should.equal(false) && div.classList.contains(\"clicked\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click elsewhere add .clicked\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"clicked\"))
  ))")
(~hyperscript/hs-test-card
  :name "supports \"from elsewhere\" modifier"
  :html "<div _='on click from elsewhere add .clicked'></div>"
  :action "div.click(); body.click()"
  :check "div.classList.contains(\"clicked\").should.equal(false) && div.classList.contains(\"clicked\").should.equal(false) && div.classList.contains(\"clicked\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click from elsewhere add .clicked\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (assert (dom-has-class? _el-div \"clicked\"))
  ))")
(~hyperscript/hs-test-card
  :name "can pick detail fields out by name"
  :html "<div id='d1' _='on click send custom(foo:\"fromBar\") to #d2'></div> | <div id='d2' _='on custom(foo) call me.classList.add(foo)'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"fromBar\").should.equal(false) && div.classList.contains(\"fromBar\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")) (_el-d2 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click send custom(foo:\\\"fromBar\\\") to #d2\")
    (dom-set-attr _el-d2 \"id\" \"d2\")
    (dom-set-attr _el-d2 \"_\" \"on custom(foo) call me.classList.add(foo)\")
    (dom-append sandbox _el-d1)
    (dom-append sandbox _el-d2)
    (hs-activate! _el-d1)
    (hs-activate! _el-d2)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert (dom-has-class? _el-d1 \"fromBar\"))
  ))")
(~hyperscript/hs-test-card
  :name "can pick event properties out by name"
  :html "<div id='d1' _='on click send fromBar to #d2'></div> | <div id='d2' _='on fromBar(type) call me.classList.add(type)'></div>"
  :action "bar.click()"
  :check "div.classList.contains(\"fromBar\").should.equal(false) && div.classList.contains(\"fromBar\").should.equal(true)"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")) (_el-d2 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click send fromBar to #d2\")
    (dom-set-attr _el-d2 \"id\" \"d2\")
    (dom-set-attr _el-d2 \"_\" \"on fromBar(type) call me.classList.add(type)\")
    (dom-append sandbox _el-d1)
    (dom-append sandbox _el-d2)
    (hs-activate! _el-d1)
    (hs-activate! _el-d2)
    (dom-dispatch _el-d1 \"click\" nil)
    (assert (dom-has-class? _el-d1 \"fromBar\"))
  ))")
(~hyperscript/hs-test-card
  :name "can fire an event on load"
  :html "<div id='d1' _='on load put \"Loaded\" into my.innerHTML'></div>"
  :action "(see body)"
  :check "div.innerText.should.equal(\"Loaded\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can be in a top level script tag"
  :html "<script type='text/hyperscript'>on load put \"Loaded\" into #loadedDemo.innerHTML</script><div id='loadedDemo'></div>"
  :action "(see body)"
  :check "byId(\"loadedDemo\").innerText.should.equal(\"Loaded\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can have a simple event filter"
  :html "<div id='d1' _='on click[false] log event then put \"Clicked\" into my.innerHTML'></div>"
  :action "div.click()"
  :check "byId(\"d1\").innerText.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d1 \"_\" \"on click[false] log event then put \\\"Clicked\\\" into my.innerHTML\")
    (dom-append sandbox _el-d1)
    (hs-activate! _el-d1)
    (dom-dispatch _el-d1 \"click\" nil)
    ;; SKIP check: skip byId(\"d1\").innerText.should.equal(\"\")
  ))")
(~hyperscript/hs-test-card
  :name "can refer to event properties directly in filter"
  :html "<div _='on click[buttons==0] log event then put \"Clicked\" into my.innerHTML'></div> | <div _='on click[buttons==1] log event then put \"Clicked\" into my.innerHTML'></div> | <div _='on click[buttons==1 and buttons==0] log event then put \"Clicked\" into my.innerHTML'></div>"
  :action "div.click(); div.click(); div.click()"
  :check "div.innerText.should.equal(\"Clicked\") && div.innerText.should.equal(\"\") && div.innerText.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-div1 (dom-create-element \"div\")) (_el-div2 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click[buttons==0] log event then put \\\"Clicked\\\" into my.innerHTML\")
    (dom-set-attr _el-div1 \"_\" \"on click[buttons==1] log event then put \\\"Clicked\\\" into my.innerHTML\")
    (dom-set-attr _el-div2 \"_\" \"on click[buttons==1 and buttons==0] log event then put \\\"Clicked\\\" into my.innerHTML\")
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-div1)
    (dom-append sandbox _el-div2)
    (hs-activate! _el-div)
    (hs-activate! _el-div1)
    (hs-activate! _el-div2)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"Clicked\")
    ;; SKIP check: skip div.innerText.should.equal(\"\")
  ))")
(~hyperscript/hs-test-card
  :name "can refer to event detail properties directly in filter"
  :html "<div _='on example[foo] increment @count then put it into me'></div>"
  :action "div.dispatchEvent(event); div.dispatchEvent(event); div.dispatchEvent(event)"
  :check "div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"2\")"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can click after a positive event filter"
  :html "<div _='on foo(bar)[bar] put \"triggered\" into my.innerHTML'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\", { detail: { bar: false } }); div.dispatchEvent(new CustomEvent(\"foo\", { detail: { bar: true } })"
  :check "div.innerText.should.equal(\"\") && div.innerText.should.equal(\"triggered\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo(bar)[bar] put \\\"triggered\\\" into my.innerHTML\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"\")
    ;; SKIP check: skip div.innerText.should.equal(\"triggered\")
  ))")
(~hyperscript/hs-test-card
  :name "multiple event handlers at a time are allowed to execute with the every keyword"
  :html "<div _='on every click put increment() into my.innerHTML then wait for a customEvent'></div>"
  :action "div.click(); div.click(); div.click()"
  :check "div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"2\") && div.innerText.should.equal(\"3\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on every click put increment() into my.innerHTML then wait for a customEvent\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"1\")
    ;; SKIP check: skip div.innerText.should.equal(\"2\")
    ;; SKIP check: skip div.innerText.should.equal(\"3\")
  ))")
(~hyperscript/hs-test-card
  :name "can have multiple event handlers"
  :html "<div _='on foo put increment() into my.innerHTML end                          on bar put increment() into my.innerHTML'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"foo\")"
  :check "div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"2\") && div.innerText.should.equal(\"3\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo put increment() into my.innerHTML end on bar put increment() into my.innerHTML\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"1\")
    ;; SKIP check: skip div.innerText.should.equal(\"2\")
    ;; SKIP check: skip div.innerText.should.equal(\"3\")
  ))")
(~hyperscript/hs-test-card
  :name "can have multiple event handlers, no end"
  :html "<div _='on foo put increment() into my.innerHTML                          on bar put increment() into my.innerHTML'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"foo\")"
  :check "div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"2\") && div.innerText.should.equal(\"3\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo put increment() into my.innerHTML on bar put increment() into my.innerHTML\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"1\")
    ;; SKIP check: skip div.innerText.should.equal(\"2\")
    ;; SKIP check: skip div.innerText.should.equal(\"3\")
  ))")
(~hyperscript/hs-test-card
  :name "can queue events"
  :html "<div _='on foo wait for bar then call increment()'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\")"
  :check "i.should.equal(0) && i.should.equal(0) && i.should.equal(0) && i.should.equal(1) && i.should.equal(2) && i.should.equal(2)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo wait for bar then call increment()\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    ;; SKIP check: skip i.should.equal(0)
    ;; SKIP check: skip i.should.equal(1)
    ;; SKIP check: skip i.should.equal(2)
  ))")
(~hyperscript/hs-test-card
  :name "can queue first event"
  :html "<div _='on foo queue first wait for bar then call increment()'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\")"
  :check "i.should.equal(0) && i.should.equal(0) && i.should.equal(0) && i.should.equal(1) && i.should.equal(2) && i.should.equal(2)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo queue first wait for bar then call increment()\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    ;; SKIP check: skip i.should.equal(0)
    ;; SKIP check: skip i.should.equal(1)
    ;; SKIP check: skip i.should.equal(2)
  ))")
(~hyperscript/hs-test-card
  :name "can queue last event"
  :html "<div _='on foo queue last wait for bar then call increment()'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\")"
  :check "i.should.equal(0) && i.should.equal(0) && i.should.equal(0) && i.should.equal(1) && i.should.equal(2) && i.should.equal(2)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo queue last wait for bar then call increment()\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    ;; SKIP check: skip i.should.equal(0)
    ;; SKIP check: skip i.should.equal(1)
    ;; SKIP check: skip i.should.equal(2)
  ))")
(~hyperscript/hs-test-card
  :name "can queue all events"
  :html "<div _='on foo queue all wait for bar then call increment()'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"foo\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\"); div.dispatchEvent(new CustomEvent(\"bar\")"
  :check "i.should.equal(0) && i.should.equal(0) && i.should.equal(0) && i.should.equal(1) && i.should.equal(2) && i.should.equal(3)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on foo queue all wait for bar then call increment()\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    (dom-dispatch _el-div \"bar\" nil)
    ;; SKIP check: skip i.should.equal(0)
    ;; SKIP check: skip i.should.equal(1)
    ;; SKIP check: skip i.should.equal(2)
    ;; SKIP check: skip i.should.equal(3)
  ))")
(~hyperscript/hs-test-card
  :name "queue none does not allow future queued events"
  :html "<div _='on click queue none put increment() into my.innerHTML then wait for a customEvent'></div>"
  :action "div.click(); div.click(); div.dispatchEvent(new CustomEvent(\"customEvent\"); div.click()"
  :check "div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"1\") && div.innerText.should.equal(\"2\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click queue none put increment() into my.innerHTML then wait for a customEvent\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"customEvent\" nil)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip div.innerText.should.equal(\"1\")
    ;; SKIP check: skip div.innerText.should.equal(\"2\")
  ))")
(~hyperscript/hs-test-card
  :name "can invoke on multiple events"
  :html "<div _='on click or foo call increment()'></div>"
  :action "div.click(); div.dispatchEvent(new CustomEvent(\"foo\")"
  :check "i.should.equal(1) && i.should.equal(2)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click or foo call increment()\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"foo\" nil)
    ;; SKIP check: skip i.should.equal(1)
    ;; SKIP check: skip i.should.equal(2)
  ))")
(~hyperscript/hs-test-card
  :name "can listen for events in another element (lazy)"
  :html "<div _='on click in #d1 put it into window.tmp'>                    <div id='d1'></div>                    <div id='d2'></div>               </div>"
  :action "div1.click()"
  :check "div1.should.equal(window.tmp)"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")) (_el-d1 (dom-create-element \"div\")) (_el-d2 (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click in #d1 put it into window.tmp\")
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d2 \"id\" \"d2\")
    (dom-append sandbox _el-div)
    (dom-append _el-div _el-d1)
    (dom-append _el-div _el-d2)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    ;; SKIP check: skip div1.should.equal(window.tmp)
  ))")
(~hyperscript/hs-test-card
  :name "can filter events based on count"
  :html "<div _='on click 1 put 1 + my.innerHTML as Int into my.innerHTML'>0</div>"
  :action "div.click(); div.click(); div.click()"
  :check "div.innerHTML.should.equal(\"1\") && div.innerHTML.should.equal(\"1\") && div.innerHTML.should.equal(\"1\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click 1 put 1 + my.innerHTML as Int into my.innerHTML\")
    (dom-set-inner-html _el-div \"0\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"1\")
  ))")
(~hyperscript/hs-test-card
  :name "can filter events based on count range"
  :html "<div _='on click 1 to 2 put 1 + my.innerHTML as Int into my.innerHTML'>0</div>"
  :action "div.click(); div.click(); div.click()"
  :check "div.innerHTML.should.equal(\"1\") && div.innerHTML.should.equal(\"2\") && div.innerHTML.should.equal(\"2\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click 1 to 2 put 1 + my.innerHTML as Int into my.innerHTML\")
    (dom-set-inner-html _el-div \"0\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"2\")
  ))")
(~hyperscript/hs-test-card
  :name "can filter events based on unbounded count range"
  :html "<div _='on click 2 and on put 1 + my.innerHTML as Int into my.innerHTML'>0</div>"
  :action "div.click(); div.click(); div.click()"
  :check "div.innerHTML.should.equal(\"0\") && div.innerHTML.should.equal(\"1\") && div.innerHTML.should.equal(\"2\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click 2 and on put 1 + my.innerHTML as Int into my.innerHTML\")
    (dom-set-inner-html _el-div \"0\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"2\")
  ))")
(~hyperscript/hs-test-card
  :name "can mix ranges"
  :html "<div _='on click 1 put \"one\" into my.innerHTML                           on click 3 put \"three\" into my.innerHTML                           on click 2 put \"two\" into my.innerHTML '>0</div>"
  :action "div.click(); div.click(); div.click(); div.click()"
  :check "div.innerHTML.should.equal(\"one\") && div.innerHTML.should.equal(\"two\") && div.innerHTML.should.equal(\"three\") && div.innerHTML.should.equal(\"three\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on click 1 put \\\"one\\\" into my.innerHTML on click 3 put \\\"three\\\" into my.innerHTML on click 2 put \\\"two\\\" into my.innerHTML\")
    (dom-set-inner-html _el-div \"0\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (dom-dispatch _el-div \"click\" nil)
    (assert= (dom-inner-html _el-div) \"three\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for general mutations"
  :html "<div _='on mutation put \"Mutated\" into me then wait for hyperscript:mutation'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation put \\\"Mutated\\\" into me then wait for hyperscript:mutation\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for attribute mutations"
  :html "<div _='on mutation of attributes put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of attributes put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for specific attribute mutations"
  :html "<div _='on mutation of @foo put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of @foo put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for specific attribute mutations and filter out other attribute mutations"
  :html "<div _='on mutation of @bar put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of @bar put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for childList mutations"
  :html "<div _='on mutation of childList put \"Mutated\" into me then wait for hyperscript:mutation'></div>"
  :action "div.appendChild(document.createElement(\"P\")"
  :check "div.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of childList put \\\"Mutated\\\" into me then wait for hyperscript:mutation\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-append _el-div (dom-create-element \"P\"))
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for childList mutation filter out other mutations"
  :html "<div _='on mutation of childList put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of childList put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for characterData mutation filter out other mutations"
  :html "<div _='on mutation of characterData put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of characterData put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for multiple mutations"
  :html "<div _='on mutation of @foo or @bar put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"foo\", \"bar\")"
  :check "div.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of @foo or @bar put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for multiple mutations 2"
  :html "<div _='on mutation of @foo or @bar put \"Mutated\" into me'></div>"
  :action "div.setAttribute(\"bar\", \"bar\")"
  :check "div.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-div \"_\" \"on mutation of @foo or @bar put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-div \"bar\" \"bar\")
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "can listen for attribute mutations on other elements"
  :html "<div id='d1'></div> | <div _='on mutation of attributes from #d1 put \"Mutated\" into me'></div>"
  :action "div1.setAttribute(\"foo\", \"bar\")"
  :check "div2.innerHTML.should.equal(\"Mutated\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")) (_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-div \"_\" \"on mutation of attributes from #d1 put \\\"Mutated\\\" into me\")
    (dom-append sandbox _el-d1)
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-set-attr _el-d1 \"foo\" \"bar\")
    (assert= (dom-inner-html _el-div) \"Mutated\")
  ))")
(~hyperscript/hs-test-card
  :name "each behavior installation has its own event queue"
  :html "<script type=text/hyperscript>behavior DemoBehavior on foo wait 10ms then set my innerHTML to 'behavior'</script> | <div _='install DemoBehavior'></div> | <div _='install DemoBehavior'></div> | <div _='install DemoBehavior'></div>"
  :action "div.dispatchEvent(new CustomEvent(\"foo\"); div2.dispatchEvent(new CustomEvent(\"foo\"); div3.dispatchEvent(new CustomEvent(\"foo\")"
  :check "div.innerHTML.should.equal(\"behavior\") && div2.innerHTML.should.equal(\"behavior\") && div3.innerHTML.should.equal(\"behavior\")"
  :run-src "(fn (sandbox)
  (let ((_el-script (dom-create-element \"script\")) (_el-div (dom-create-element \"div\")) (_el-div2 (dom-create-element \"div\")) (_el-div3 (dom-create-element \"div\")))
    (dom-set-attr _el-script \"type\" \"text/hyperscript\")
    (dom-set-inner-html _el-script \"behavior DemoBehavior on foo wait 10ms then set my innerHTML to 'behavior'\")
    (dom-set-attr _el-div \"_\" \"install DemoBehavior\")
    (dom-set-attr _el-div2 \"_\" \"install DemoBehavior\")
    (dom-set-attr _el-div3 \"_\" \"install DemoBehavior\")
    (dom-append sandbox _el-script)
    (dom-append sandbox _el-div)
    (dom-append sandbox _el-div2)
    (dom-append sandbox _el-div3)
    (hs-activate! _el-div)
    (hs-activate! _el-div2)
    (hs-activate! _el-div3)
    (dom-dispatch _el-div \"foo\" nil)
    (dom-dispatch _el-div2 \"foo\" nil)
    (dom-dispatch _el-div3 \"foo\" nil)
    (assert= (dom-inner-html _el-div) \"behavior\")
    (assert= (dom-inner-html _el-div2) \"behavior\")
    (assert= (dom-inner-html _el-div3) \"behavior\")
  ))")
(~hyperscript/hs-test-card
  :name "can catch exceptions thrown in js functions"
  :html "<button _='on click throwBar() catch e put e into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click throwBar() catch e put e into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "can catch exceptions thrown in hyperscript functions"
  :html "<script type='text/hyperscript'>  def throwBar()    throw 'bar'  end</script>s | <button _='on click throwBar() catch e put e into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click throwBar() catch e put e into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "can catch top-level exceptions"
  :html "<button _='on click throw \"bar\" catch e put e into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click throw \\\"bar\\\" catch e put e into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "can catch async top-level exceptions"
  :html "<button _='on click wait 1ms then throw \"bar\" catch e put e into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click wait 1ms then throw \\\"bar\\\" catch e put e into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "async exceptions don't kill the event queue"
  :html "<button _='on click                     increment :x                      if :x is 1                       wait 1ms then throw \"bar\"                     otherwise                       put \"success\" into me                    end                     catch e                       put e into me'></button>"
  :action "btn.click(); btn.click()"
  :check "btn.innerHTML.should.equal(\"success\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click  increment :x then if :x is 1 then wait 1ms then throw \\\"bar\\\" otherwise then put \\\"success\\\" into me end catch e then put e into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"success\")
  ))")
(~hyperscript/hs-test-card
  :name "exceptions in catch block don't kill the event queue"
  :html "<button _='on click                     increment :x                      if :x is 1                       throw \"bar\"                     otherwise                       put \"success\" into me                    end                   catch e                       put e into me then throw e'></button>"
  :action "btn.click(); btn.click()"
  :check "btn.innerHTML.should.equal(\"success\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click  increment :x then if :x is 1 then throw \\\"bar\\\" otherwise then put \\\"success\\\" into me end catch e then put e into me then throw e\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"success\")
  ))")
(~hyperscript/hs-test-card
  :name "uncaught exceptions trigger 'exception' event"
  :html "<button _='on click put \"foo\" into me then throw \"bar\"                  on exception(error) put error into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click put \\\"foo\\\" into me then throw \\\"bar\\\" on exception(error) put error into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "caught exceptions do not trigger 'exception'  event"
  :html "<button _='on click put \"foo\" into me then throw \"bar\"                     catch e log e                  on exception(error) put error into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"foo\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click put \\\"foo\\\" into me then throw \\\"bar\\\" catch e log e on exception(error) put error into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"foo\")
  ))")
(~hyperscript/hs-test-card
  :name "rethrown exceptions trigger 'exception'  event"
  :html "<button _='on click put \"foo\" into me then throw \"bar\"                     catch e throw e                  on exception(error) put error into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click put \\\"foo\\\" into me then throw \\\"bar\\\" catch e throw e on exception(error) put error into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "basic finally blocks work"
  :html "<button _='on click throw \"bar\"             finally put \"bar\" into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click throw \\\"bar\\\" finally put \\\"bar\\\" into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "finally blocks work when exception thrown in catch"
  :html "<button _='on click throw \"bar\"            catch e throw e            finally put \"bar\" into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click throw \\\"bar\\\" catch e throw e finally put \\\"bar\\\" into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "async basic finally blocks work"
  :html "<button _='on click wait a tick then throw \"bar\"             finally put \"bar\" into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"bar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click wait a tick then throw \\\"bar\\\" finally put \\\"bar\\\" into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"bar\")
  ))")
(~hyperscript/hs-test-card
  :name "async finally blocks work when exception thrown in catch"
  :html "<button _='on click wait a tick then throw \"bar\"            catch e set :foo to \"foo\" then throw e            finally put :foo + \"bar\" into me'></button>"
  :action "btn.click()"
  :check "btn.innerHTML.should.equal(\"foobar\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click wait a tick then throw \\\"bar\\\" catch e set :foo to \\\"foo\\\" then throw e finally put :foo + \\\"bar\\\" into me\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"foobar\")
  ))")
(~hyperscript/hs-test-card
  :name "async exceptions in finally block don't kill the event queue"
  :html "<button _='on click                     increment :x                  finally                      if :x is 1                       wait 1ms then throw \"bar\"                     otherwise                       put \"success\" into me                    end                     '></button>"
  :action "btn.click(); btn.click()"
  :check "btn.innerHTML.should.equal(\"success\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click  increment :x finally then if :x is 1 then wait 1ms then throw \\\"bar\\\" otherwise then put \\\"success\\\" into me end\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"success\")
  ))")
(~hyperscript/hs-test-card
  :name "exceptions in finally block don't kill the event queue"
  :html "<button _='on click                     increment :x                    finally                      if :x is 1                       throw \"bar\"                     otherwise                       put \"success\" into me                    end                   '></button>"
  :action "btn.click(); btn.click()"
  :check "btn.innerHTML.should.equal(\"success\")"
  :run-src "(fn (sandbox)
  (let ((_el-button (dom-create-element \"button\")))
    (dom-set-attr _el-button \"_\" \"on click  increment :x finally then if :x is 1 then throw \\\"bar\\\" otherwise then put \\\"success\\\" into me end\")
    (dom-append sandbox _el-button)
    (hs-activate! _el-button)
    (dom-dispatch _el-button \"click\" nil)
    (dom-dispatch _el-button \"click\" nil)
    (assert= (dom-inner-html _el-button) \"success\")
  ))")
(~hyperscript/hs-test-card
  :name "can ignore when target doesn't exist"
  :html "<div id='#d1' _=' 	on click from #doesntExist 		throw \"bar\" 	on click 		put \"clicked\" into me	'></div>"
  :action "div.click()"
  :check "div.innerHTML.should.equal(\"clicked\")"
  :run-src "(fn (sandbox)
  (let ((_el-#d1 (dom-create-element \"div\")))
    (dom-set-attr _el-#d1 \"id\" \"#d1\")
    (dom-set-attr _el-#d1 \"_\" \"on click from #doesntExist then throw \\\"bar\\\" on click  put \\\"clicked\\\" into me\")
    (dom-append sandbox _el-#d1)
    (hs-activate! _el-#d1)
    (dom-dispatch _el-#d1 \"click\" nil)
    (assert= (dom-inner-html _el-#d1) \"clicked\")
  ))")
(~hyperscript/hs-test-card
  :name "can handle an or after a from clause"
  :html "<div id='d1'></div> | <div id='d2'></div> | <div _=' 	on click from #d1 or click from #d2 		 increment @count then put @count into me	'></div>"
  :action "d1.click(); d2.click()"
  :check "div.innerHTML.should.equal(\"1\") && div.innerHTML.should.equal(\"2\")"
  :run-src "(fn (sandbox)
  (let ((_el-d1 (dom-create-element \"div\")) (_el-d2 (dom-create-element \"div\")) (_el-div (dom-create-element \"div\")))
    (dom-set-attr _el-d1 \"id\" \"d1\")
    (dom-set-attr _el-d2 \"id\" \"d2\")
    (dom-set-attr _el-div \"_\" \"on click from #d1 or click from #d2 then increment @count then put @count into me\")
    (dom-append sandbox _el-d1)
    (dom-append sandbox _el-d2)
    (dom-append sandbox _el-div)
    (hs-activate! _el-div)
    (dom-dispatch _el-d1 \"click\" nil)
    (dom-dispatch _el-d2 \"click\" nil)
    (assert= (dom-inner-html _el-div) \"2\")
  ))")
(~hyperscript/hs-test-card
  :name "handles custom events with null detail"
  :html "<div id='d1' _='on myEvent(foo) if foo put foo into me else put \\\"no-detail\\\" into me'></div>"
  :action "evaluate({...})"
  :check "toHaveText('no-detail')"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "on first click fires only once"
  :html "<div _='on first click put 1 + my.innerHTML as Int into my.innerHTML'>0</div>"
  :action "find('div').dispatchEvent('click'); find('div').dispatchEvent('click')"
  :check "toHaveText('1'); toHaveText('1')"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "caught exceptions do not trigger 'exception' event"
  :html "<button _='on click put \\\"foo\\\" into me then throw \\\"bar\\\"                     catch e log e                  on exception(error) put error into me'></button>"
  :action "find('button').dispatchEvent('click')"
  :check "toHaveText('foo')"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "rethrown exceptions trigger 'exception' event"
  :html "<button _='on click put \\\"foo\\\" into me then throw \\\"bar\\\"                     catch e throw e                  on exception(error) put error into me'></button>"
  :action "find('button').dispatchEvent('click')"
  :check "toHaveText('bar')"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))")
(~hyperscript/hs-test-card
  :name "can ignore when target doesn\\'t exist"
  :html "<div _=' 	on click from #doesntExist 		throw \\\"bar\\\" 	on click 		put \\\"clicked\\\" into me	'></div>"
  :action "find('div').dispatchEvent('click')"
  :check "toHaveText('clicked')"
  :run-src "(fn (sandbox) (error \"not yet runnable in gallery — see test suite\"))"))))
