Skip to content

Commit

Permalink
Wait on turbo:load events during History visits
Browse files Browse the repository at this point in the history
When navigating with `this.goBack()` and `this.goForward()`, synchronize
the timing by waiting on `turbo:load` events instead of the
`this.nextBody` hook firing.

During a restoration visit (triggered by `this.goBack()` or
`this.goForward()`), the [`turbo:render`][render] event will fire once
when restoring the cached snapshot, and a second time when the contents
are refreshed from a request to the server.

By waiting on the `turbo:load` event, the test won't proceed until that
process is complete, which will hopefully limit the possibility of
referencing stale elements.

[render]: https://turbo.hotwired.dev/reference/events
  • Loading branch information
seanpdoyle committed Nov 14, 2021
1 parent ca1117b commit 59074f0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/tests/functional/frame_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export class FrameTests extends TurboDriveTestCase {
await this.clickSelector("#link-frame")
await this.nextEventNamed("turbo:load")
await this.goBack()
await this.nextBody
await this.nextEventNamed("turbo:load")

const title = await this.querySelector("h1")
const frameTitle = await this.querySelector("#frame h2")
Expand All @@ -395,9 +395,9 @@ export class FrameTests extends TurboDriveTestCase {
await this.clickSelector("#link-frame")
await this.nextEventNamed("turbo:load")
await this.goBack()
await this.nextBody
await this.nextEventNamed("turbo:load")
await this.goForward()
await this.nextBody
await this.nextEventNamed("turbo:load")

const title = await this.querySelector("h1")
const frameTitle = await this.querySelector("#frame h2")
Expand Down

0 comments on commit 59074f0

Please sign in to comment.