Skip to content

Commit

Permalink
add test for blocking: true
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenDE committed Feb 17, 2025
1 parent 1bc308a commit 55226c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/js/phoenix_live_view/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let JS = {
const promise = new Promise((resolve, _reject) => {
detail.done = resolve
})
liveSocket.asyncTransition(promise)
view.liveSocket.asyncTransition(promise)
}
DOM.dispatchEvent(el, event, {detail, bubbles})
},
Expand Down
23 changes: 23 additions & 0 deletions assets/test/js_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,29 @@ describe("JS", () => {

JS.exec(event, "close", close.getAttribute("phx-click"), view, close)
})

test("blocking blocks DOM updates until done", done => {
let view = setupView(`
<div id="modal">modal</div>
<div id="click" phx-click='[["dispatch", {"to": "#modal", "event": "custom", "blocking": true}]]'></div>
`)
let modal = simulateVisibility(document.querySelector("#modal"))
let click = document.querySelector("#click")
let doneCalled = false

modal.addEventListener("custom", (e) => {
expect(e.detail).toEqual({done: expect.any(Function), dispatcher: click})
expect(view.liveSocket.transitions.size()).toBe(1)
view.liveSocket.requestDOMUpdate(() => {
expect(doneCalled).toBe(true)
done()
})
// now we unblock the transition
e.detail.done()
doneCalled = true
})
JS.exec(event, "click", click.getAttribute("phx-click"), view, click)
})
})

describe("exec_add_class and exec_remove_class", () => {
Expand Down

0 comments on commit 55226c4

Please sign in to comment.