Skip to content

Commit

Permalink
Merge pull request #1263 from radanskoric/test-stream-elements-inside…
Browse files Browse the repository at this point in the history
…-html

Add a test that stream actions rendered into the HTML are executed
  • Loading branch information
brunoprietog authored Jan 8, 2025
2 parents a79516d + 8dfce21 commit ae14a60
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/tests/functional/stream_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ test("preventing a turbo:before-morph-element prevents the morph", async ({ page
await expect(page.locator("#message_1")).toHaveText("Morph me")
})

test("rendering a stream message into the HTML executes it", async ({ page }) => {
await page.evaluate(() => {
document.body.insertAdjacentHTML(
"afterbegin",
`
<turbo-stream action="append" target="messages">
<template>
<div class="message">Hello world!</div>
</template>
</turbo-stream>
`
)
})
await nextBeat()

const messages = await page.locator("#messages .message")
assert.deepEqual(await messages.allTextContents(), ["First", "Hello world!"])
})

async function getReadyState(page, id) {
return page.evaluate((id) => {
const element = document.getElementById(id)
Expand Down

0 comments on commit ae14a60

Please sign in to comment.