← Recipe: synchronize Browser and system Back

4. Replace tests/smoke.luau

luastra/navigation · luastra/host · navigation.history · about 20 minutes
valid and invalid history restoration

The test supplies encoded router state directly and proves malformed history cannot replace the current route.

When to use it

Replace the generated smoke test to verify atomic history restoration before opening a browser.

Focused example

--!strict

local app = require("app/main")
local Navigation = require("luastra/navigation")

local routes = Navigation.compile {
    { name = "home", path = "/" },
    { name = "detail", path = "/detail" },
}
local source = Navigation.createRouter {
    compiler = routes,
    initial = { name = "home", params = {}, query = {} },
}
assert(source.push { name = "detail", params = {}, query = {} }.success)
app.handle("history", "app", source.encode())
assert(app.snapshot().location == "#/detail", "detail history was not restored")
app.handle("history", "app", "invalid")
assert(app.snapshot().location == "#/detail", "malformed history was accepted")
assert(app.snapshot().location == "#/detail", "failed restore changed the route")
assert(Navigation.decideBack { modalOpen = false, canBack = true } == "history")

return true

Complete inventory

View all pages in Recipe: synchronize Browser and system Back
← Previous: 3. Replace src/main.luauNext: 5. Check and run →