Skip to content

Prevent race conditions when testing with playwright #2360

Answered by Telroshan
languitar asked this question in Q&A
Discussion options

You must be logged in to vote

I'm also using playwright for htmx-based tests, though I'm not using boosting so I may be off the mark in this situation, let me know.
I have 2 "tricks"

  • Check that htmx has been initialized before moving on with the actual tests
const htmx = await page.evaluate("window.htmx")
expect(htmx).not.toEqual(null)

You could use this in a beforeEach hook for example to avoid repetition

  • Define a simple utility function to ensure things were settled between 2 actions where the second action would require the first one to be completed before moving on, such as
async function htmxReady(page: Page) {
    await expect(page.locator('.htmx-request, .htmx-settling, .htmx-swapping, .htmx-added')).toHave…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@languitar
Comment options

Answer selected by languitar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants