Skip to content

Commit

Permalink
Add a test that stream actions rendered into the HTML are executed
Browse files Browse the repository at this point in the history
As a consequence of the fundamental way in which Stream actions are implemented,
they can also be executed by rendering them within any HTML that's included on
the dom.

Since this is already being used as the feature in the community, adding this
test will ensure this keeps working.
  • Loading branch information
radanskoric committed Jul 23, 2024
1 parent f88bfe4 commit 8dfce21
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 8dfce21

Please sign in to comment.