diff --git a/package.json b/package.json
index 214ddee8e..486c15bc2 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,6 @@
"@web/test-runner-playwright": "^0.9.0",
"arg": "^5.0.1",
"body-parser": "^1.20.1",
- "chai": "~4.3.4",
"eslint": "^8.13.0",
"express": "^4.18.2",
"multer": "^1.4.2",
diff --git a/src/tests/functional/async_script_tests.js b/src/tests/functional/async_script_tests.js
index f2e27a3a9..a0d1a35a8 100644
--- a/src/tests/functional/async_script_tests.js
+++ b/src/tests/functional/async_script_tests.js
@@ -1,5 +1,4 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
+import { expect, test } from "@playwright/test"
import { readEventLogs, visitAction } from "../helpers/page"
test.beforeEach(async ({ page }) => {
@@ -10,11 +9,11 @@ test.beforeEach(async ({ page }) => {
test("does not emit turbo:load when loaded asynchronously after DOMContentLoaded", async ({ page }) => {
const events = await readEventLogs(page)
- assert.deepEqual(events, [])
+ expect(events).toEqual([])
})
test("following a link when loaded asynchronously after DOMContentLoaded", async ({ page }) => {
await page.click("#async-link")
- assert.equal(await visitAction(page), "advance")
+ expect(await visitAction(page)).toEqual("advance")
})
diff --git a/src/tests/functional/autofocus_tests.js b/src/tests/functional/autofocus_tests.js
index 011562ceb..67183e0e6 100644
--- a/src/tests/functional/autofocus_tests.js
+++ b/src/tests/functional/autofocus_tests.js
@@ -1,150 +1,88 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
-import { hasSelector, nextBeat } from "../helpers/page"
+import { expect, test } from "@playwright/test"
test.beforeEach(async ({ page }) => {
await page.goto("/src/tests/fixtures/autofocus.html")
})
test("autofocus first autofocus element on load", async ({ page }) => {
- await nextBeat()
- assert.ok(
- await hasSelector(page, "#first-autofocus-element:focus"),
+ await expect(
+ page.locator("#first-autofocus-element"),
"focuses the first [autofocus] element on the page"
- )
- assert.notOk(
- await hasSelector(page, "#second-autofocus-element:focus"),
+ ).toBeFocused()
+ await expect(
+ page.locator("#second-autofocus-element"),
"focuses the first [autofocus] element on the page"
- )
+ ).not.toBeFocused()
})
test("autofocus first [autofocus] element on visit", async ({ page }) => {
await page.goto("/src/tests/fixtures/navigation.html")
await page.click("#autofocus-link")
- await nextBeat()
- assert.ok(
- await hasSelector(page, "#first-autofocus-element:focus"),
- "focuses the first [autofocus] element on the page"
- )
- assert.notOk(
- await hasSelector(page, "#second-autofocus-element:focus"),
- "focuses the first [autofocus] element on the page"
- )
+ await expect(page.locator("#first-autofocus-element")).toBeFocused()
+ await expect(page.locator("#second-autofocus-element")).not.toBeFocused()
})
test("navigating a frame with a descendant link autofocuses [autofocus]:first-of-type", async ({ page }) => {
await page.click("#frame-inner-link")
- await nextBeat()
-
- assert.ok(
- await hasSelector(page, "#frames-form-first-autofocus-element:focus"),
- "focuses the first [autofocus] element in frame"
- )
- assert.notOk(
- await hasSelector(page, "#frames-form-second-autofocus-element:focus"),
- "focuses the first [autofocus] element in frame"
- )
+
+ await expect(page.locator("#frames-form-first-autofocus-element")).toBeFocused()
+ await expect(page.locator("#frames-form-second-autofocus-element")).not.toBeFocused()
})
test("autofocus visible [autofocus] element on visit with inert elements", async ({ page }) => {
await page.click("#autofocus-inert-link")
- await nextBeat()
-
- assert.notOk(
- await hasSelector(page, "#dialog-autofocus-element:focus"),
- "autofocus element is ignored in a closed dialog"
- )
- assert.notOk(
- await hasSelector(page, "#details-autofocus-element:focus"),
- "autofocus element is ignored in a closed details"
- )
- assert.notOk(
- await hasSelector(page, "#hidden-autofocus-element:focus"),
- "autofocus element is ignored in a hidden div"
- )
- assert.notOk(
- await hasSelector(page, "#inert-autofocus-element:focus"),
- "autofocus element is ignored in an inert div"
- )
- assert.notOk(
- await hasSelector(page, "#disabled-autofocus-element:focus"),
- "autofocus element is ignored when disabled"
- )
- assert.ok(
- await hasSelector(page, "#visible-autofocus-element:focus"),
- "focuses the visible [autofocus] element on the page"
- )
+
+ await expect(page.locator("#dialog-autofocus-element")).not.toBeFocused()
+ await expect(page.locator("#details-autofocus-element")).not.toBeFocused()
+ await expect(page.locator("#hidden-autofocus-element")).not.toBeFocused()
+ await expect(page.locator("#inert-autofocus-element")).not.toBeFocused()
+ await expect(page.locator("#disabled-autofocus-element")).not.toBeFocused()
+ await expect(page.locator("#visible-autofocus-element")).toBeFocused()
})
test("navigating a frame with a link targeting the frame autofocuses [autofocus]:first-of-type", async ({
page
}) => {
await page.click("#frame-outer-link")
- await nextBeat()
-
- assert.ok(
- await hasSelector(page, "#frames-form-first-autofocus-element:focus"),
- "focuses the first [autofocus] element in frame"
- )
- assert.notOk(
- await hasSelector(page, "#frames-form-second-autofocus-element:focus"),
- "focuses the first [autofocus] element in frame"
- )
+
+ await expect(page.locator("#frames-form-first-autofocus-element")).toBeFocused()
+ await expect(page.locator("#frames-form-second-autofocus-element")).not.toBeFocused()
})
test("navigating a frame with a turbo-frame targeting the frame autofocuses [autofocus]:first-of-type", async ({
page
}) => {
await page.click("#drives-frame-target-link")
- await nextBeat()
-
- assert.ok(
- await hasSelector(page, "#frames-form-first-autofocus-element:focus"),
- "focuses the first [autofocus] element in frame"
- )
- assert.notOk(
- await hasSelector(page, "#frames-form-second-autofocus-element:focus"),
- "focuses the first [autofocus] element in frame"
- )
+
+ await expect(page.locator("#frames-form-first-autofocus-element")).toBeFocused()
+ await expect(page.locator("#frames-form-second-autofocus-element")).not.toBeFocused()
})
test("receiving a Turbo Stream message with an [autofocus] element when the activeElement is the document", async ({ page }) => {
await page.evaluate(() => {
- if (document.activeElement instanceof HTMLElement) {
- document.activeElement.blur()
- }
+ document.activeElement.blur()
window.Turbo.renderStreamMessage(`
`)
})
- await nextBeat()
- assert.ok(
- await hasSelector(page, "#autofocus-from-stream:focus"),
- "focuses the [autofocus] element in from the turbo-stream"
- )
+ await expect(page.locator("#autofocus-from-stream")).toBeFocused()
})
test("autofocus from a Turbo Stream message does not leak a placeholder [id]", async ({ page }) => {
await page.evaluate(() => {
- if (document.activeElement instanceof HTMLElement) {
- document.activeElement.blur()
- }
+ document.activeElement.blur()
window.Turbo.renderStreamMessage(`
`)
})
- await nextBeat()
- assert.ok(
- await hasSelector(page, "#container-from-stream input:focus"),
- "focuses the [autofocus] element in from the turbo-stream"
- )
+ await expect(page.locator("#container-from-stream input")).toBeFocused()
})
test("receiving a Turbo Stream message with an [autofocus] element when an element within the document has focus", async ({ page }) => {
@@ -155,10 +93,6 @@ test("receiving a Turbo Stream message with an [autofocus] element when an eleme
`)
})
- await nextBeat()
- assert.ok(
- await hasSelector(page, "#first-autofocus-element:focus"),
- "focuses the first [autofocus] element on the page"
- )
+ await expect(page.locator("#first-autofocus-element")).toBeFocused()
})
diff --git a/src/tests/functional/cache_observer_tests.js b/src/tests/functional/cache_observer_tests.js
index 64d3c8c5d..c6d1422f9 100644
--- a/src/tests/functional/cache_observer_tests.js
+++ b/src/tests/functional/cache_observer_tests.js
@@ -1,37 +1,33 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
-import { hasSelector, nextBody } from "../helpers/page"
+import { expect, test } from "@playwright/test"
+import { nextEventNamed } from "../helpers/page"
test("removes temporary elements", async ({ page }) => {
await page.goto("/src/tests/fixtures/cache_observer.html")
- assert.equal(await page.textContent("#temporary"), "data-turbo-temporary")
+ await expect(page.locator("#temporary")).toHaveText("data-turbo-temporary")
await page.click("#link")
- await nextBody(page)
+ await nextEventNamed(page, "turbo:load")
await page.goBack()
- await nextBody(page)
- assert.notOk(await hasSelector(page, "#temporary"))
+ await expect(page.locator("#temporary")).not.toBeVisible()
})
test("removes temporary elements with deprecated turbo-cache=false selector", async ({ page }) => {
await page.goto("/src/tests/fixtures/cache_observer.html")
- assert.equal(await page.textContent("#temporary-with-deprecated-selector"), "data-turbo-cache=false")
+ await expect(page.locator("#temporary-with-deprecated-selector")).toHaveText("data-turbo-cache=false")
await page.click("#link")
- await nextBody(page)
+ await nextEventNamed(page, "turbo:load")
await page.goBack()
- await nextBody(page)
- assert.notOk(await hasSelector(page, "#temporary-with-deprecated-selector"))
+ await expect(page.locator("#temporary-with-deprecated-selector")).not.toBeVisible()
})
test("following a redirect renders [data-turbo-temporary] elements before the cache removes", async ({ page }) => {
await page.goto("/src/tests/fixtures/navigation.html")
await page.click("#redirect-to-cache-observer")
- await nextBody(page)
- assert.equal(await page.textContent("#temporary"), "data-turbo-temporary")
+ await expect(page.locator("#temporary")).toHaveText("data-turbo-temporary")
})
diff --git a/src/tests/functional/drive_disabled_tests.js b/src/tests/functional/drive_disabled_tests.js
index 1b4181bae..5a7919464 100644
--- a/src/tests/functional/drive_disabled_tests.js
+++ b/src/tests/functional/drive_disabled_tests.js
@@ -1,8 +1,8 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
+import { expect, test } from "@playwright/test"
import {
getFromLocalStorage,
- nextBody,
+ nextBeat,
+ nextEventNamed,
nextEventOnTarget,
pathname,
searchParams,
@@ -18,30 +18,30 @@ test.beforeEach(async ({ page }) => {
test("drive disabled by default; click normal link", async ({ page }) => {
await page.click("#drive_disabled")
- await nextBody(page)
+ await nextEventNamed(page, "turbo:load")
- assert.equal(pathname(page.url()), path)
- assert.equal(await visitAction(page), "load")
+ expect(pathname(page.url())).toEqual(path)
+ expect(await visitAction(page)).toEqual("load")
})
test("drive disabled by default; click link inside data-turbo='true'", async ({ page }) => {
await page.click("#drive_enabled")
- await nextBody(page)
+ await nextEventNamed(page, "turbo:load")
- assert.equal(pathname(page.url()), path)
- assert.equal(await visitAction(page), "advance")
+ expect(pathname(page.url())).toEqual(path)
+ expect(await visitAction(page)).toEqual("advance")
})
test("drive disabled by default; submit form inside data-turbo='true'", async ({ page }) => {
await setLocalStorageFromEvent(page, "turbo:submit-start", "formSubmitted", "true")
await page.click("#no_submitter_drive_enabled a#requestSubmit")
- await nextBody(page)
+ await nextBeat()
- assert.ok(await getFromLocalStorage(page, "formSubmitted"))
- assert.equal(pathname(page.url()), "/src/tests/fixtures/form.html")
- assert.equal(await visitAction(page), "advance")
- assert.equal(await searchParams(page.url()).get("greeting"), "Hello from a redirect")
+ expect(await getFromLocalStorage(page, "formSubmitted")).toEqual("true")
+ expect(pathname(page.url())).toEqual("/src/tests/fixtures/form.html")
+ expect(await visitAction(page)).toEqual("advance")
+ expect(await searchParams(page.url()).get("greeting")).toEqual("Hello from a redirect")
})
test("drive disabled by default; links within navigate with Turbo", async ({ page }) => {
diff --git a/src/tests/functional/drive_tests.js b/src/tests/functional/drive_tests.js
index 68980aa80..909778af9 100644
--- a/src/tests/functional/drive_tests.js
+++ b/src/tests/functional/drive_tests.js
@@ -1,6 +1,5 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
-import { nextBody, pathname, visitAction } from "../helpers/page"
+import { expect, test } from "@playwright/test"
+import { nextEventNamed, pathname, visitAction } from "../helpers/page"
const path = "/src/tests/fixtures/drive.html"
@@ -10,8 +9,8 @@ test.beforeEach(async ({ page }) => {
test("drive enabled by default; click normal link", async ({ page }) => {
await page.click("#drive_enabled")
- await nextBody(page)
- assert.equal(pathname(page.url()), path)
+ await nextEventNamed(page, "turbo:load")
+ expect(pathname(page.url())).toEqual(path)
})
test("drive to external link", async ({ page }) => {
@@ -20,16 +19,14 @@ test("drive to external link", async ({ page }) => {
})
await page.click("#drive_enabled_external")
- await nextBody(page)
- assert.equal(await page.evaluate(() => window.location.href), "https://example.com/")
- assert.equal(await page.textContent("body"), "Hello from the outside world")
+ await expect(page).toHaveURL("https://example.com/")
+ await expect(page.locator("body")).toHaveText("Hello from the outside world")
})
test("drive enabled by default; click link inside data-turbo='false'", async ({ page }) => {
await page.click("#drive_disabled")
- await nextBody(page)
- assert.equal(pathname(page.url()), path)
- assert.equal(await visitAction(page), "load")
+ await expect(page).toHaveURL(path)
+ expect(await visitAction(page)).toEqual("load")
})
diff --git a/src/tests/functional/drive_view_transition_tests.js b/src/tests/functional/drive_view_transition_tests.js
index e4c9f48fd..ecce54d7b 100644
--- a/src/tests/functional/drive_view_transition_tests.js
+++ b/src/tests/functional/drive_view_transition_tests.js
@@ -1,11 +1,12 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
-import { nextBody } from "../helpers/page"
+import { expect, test } from "@playwright/test"
+import { nextBeat } from "../helpers/page"
test.beforeEach(async ({ page }) => {
await page.goto("/src/tests/fixtures/transitions/left.html")
await page.evaluate(`
+ window.startViewTransitionCalled = false
+
document.startViewTransition = (callback) => {
window.startViewTransitionCalled = true
callback()
@@ -14,17 +15,17 @@ test.beforeEach(async ({ page }) => {
})
test("navigating triggers the view transition", async ({ page }) => {
- await page.locator("#go-right").click()
- await nextBody(page)
+ await page.click("#go-right")
+ await nextBeat()
const called = await page.evaluate(`window.startViewTransitionCalled`)
- assert.isTrue(called)
+ expect(called).toEqual(true)
})
test("navigating does not trigger a view transition when meta tag not present", async ({ page }) => {
- await page.locator("#go-other").click()
- await nextBody(page)
+ await page.click("#go-other")
+ await nextBeat()
const called = await page.evaluate(`window.startViewTransitionCalled`)
- assert.isUndefined(called)
+ expect(called).toEqual(false)
})
diff --git a/src/tests/functional/form_mode_tests.js b/src/tests/functional/form_mode_tests.js
index e642c2905..878cbd62e 100644
--- a/src/tests/functional/form_mode_tests.js
+++ b/src/tests/functional/form_mode_tests.js
@@ -1,68 +1,67 @@
-import { test } from "@playwright/test"
+import { expect, test } from "@playwright/test"
import { getFromLocalStorage, setLocalStorageFromEvent } from "../helpers/page"
-import { assert } from "chai"
test("form submission with form mode off", async ({ page }) => {
await gotoPageWithFormMode(page, "off")
await page.click("#turbo-enabled-form button")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toBe()
})
test("form submission without submitter with form mode off", async ({ page }) => {
await gotoPageWithFormMode(page, "off")
await page.press("#turbo-enabled-form-without-submitter [type=text]", "Enter")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toBe()
})
test("form submission with form mode off from submitter outside form", async ({ page }) => {
await gotoPageWithFormMode(page, "off")
await page.click("button[form=turbo-enabled-form]")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toBe()
})
test("form submission with form mode optin and form not enabled", async ({ page }) => {
await gotoPageWithFormMode(page, "optin")
await page.click("#form button")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toBe()
})
test("form submission without submitter with form mode optin and form not enabled", async ({ page }) => {
await gotoPageWithFormMode(page, "optin")
await page.press("#form-without-submitter [type=text]", "Enter")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toBe()
})
test("form submission with form mode optin and form not enabled from submitter outside form", async ({ page }) => {
await gotoPageWithFormMode(page, "optin")
await page.click("button[form=form]")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toBe()
})
test("form submission with form mode optin and form enabled", async ({ page }) => {
await gotoPageWithFormMode(page, "optin")
await page.click("#turbo-enabled-form button")
- assert.ok(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).toEqual("true")
})
test("form submission without submitter with form mode optin and form enabled", async ({ page }) => {
await gotoPageWithFormMode(page, "optin")
await page.press("#turbo-enabled-form-without-submitter [type=text]", "Enter")
- assert.ok(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).toEqual("true")
})
test("form submission with form mode optin and form enabled from submitter outside form", async ({ page }) => {
await gotoPageWithFormMode(page, "optin")
await page.click("button[form=turbo-enabled-form]")
- assert.ok(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).toEqual("true")
})
async function gotoPageWithFormMode(page, formMode) {
diff --git a/src/tests/functional/form_submission_tests.js b/src/tests/functional/form_submission_tests.js
index 987038448..ab8ff3947 100644
--- a/src/tests/functional/form_submission_tests.js
+++ b/src/tests/functional/form_submission_tests.js
@@ -1,5 +1,4 @@
-import { test } from "@playwright/test"
-import { assert } from "chai"
+import { expect, test } from "@playwright/test"
import {
getFromLocalStorage,
getSearchParam,
@@ -18,9 +17,7 @@ import {
search,
searchParams,
setLocalStorageFromEvent,
- visitAction,
- waitUntilSelector,
- waitUntilNoSelector
+ visitAction
} from "../helpers/page"
test.beforeEach(async ({ page }) => {
@@ -34,115 +31,110 @@ test("standard form submission renders a progress bar", async ({ page }) => {
await page.evaluate(() => window.Turbo.setProgressBarDelay(0))
await page.click("#standard form.sleep input[type=submit]")
- await waitUntilSelector(page, ".turbo-progress-bar")
- assert.ok(await hasSelector(page, ".turbo-progress-bar"), "displays progress bar")
-
- await nextBody(page)
- await waitUntilNoSelector(page, ".turbo-progress-bar")
-
- assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "hides progress bar")
+ await expect(page.locator(".turbo-progress-bar")).toBeVisible()
+ await expect(page.locator(".turbo-progress-bar")).not.toBeVisible()
})
test("form submission with confirmation confirmed", async ({ page }) => {
page.on("dialog", (alert) => {
- assert.equal(alert.message(), "Are you sure?")
+ expect(alert.message()).toEqual("Are you sure?")
alert.accept()
})
await page.click("#standard form.confirm input[type=submit]")
await nextEventNamed(page, "turbo:load")
- assert.ok(await formSubmitStarted(page))
- assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
+ expect(await formSubmitStarted(page)).toEqual("true")
+ expect(pathname(page.url())).toEqual("/src/tests/fixtures/one.html")
})
test("form submission with confirmation cancelled", async ({ page }) => {
page.on("dialog", (alert) => {
- assert.equal(alert.message(), "Are you sure?")
+ expect(alert.message()).toEqual("Are you sure?")
alert.dismiss()
})
await page.click("#standard form.confirm input[type=submit]")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toEqual("true")
})
test("form submission with secondary submitter click - confirmation confirmed", async ({ page }) => {
page.on("dialog", (alert) => {
- assert.equal(alert.message(), "Are you really sure?")
+ expect(alert.message()).toEqual("Are you really sure?")
alert.accept()
})
await page.click("#standard form.confirm #secondary_submitter")
await nextEventNamed(page, "turbo:load")
- assert.ok(await formSubmitStarted(page))
- assert.equal(await pathname(page.url()), "/src/tests/fixtures/one.html")
- assert.equal(await visitAction(page), "advance")
- assert.equal(getSearchParam(page.url(), "greeting"), "secondary_submitter")
+ expect(await formSubmitStarted(page)).toEqual("true")
+ expect(await pathname(page.url())).toEqual("/src/tests/fixtures/one.html")
+ expect(await visitAction(page)).toEqual("advance")
+ expect(getSearchParam(page.url(), "greeting")).toEqual("secondary_submitter")
})
test("form submission with secondary submitter click - confirmation cancelled", async ({ page }) => {
page.on("dialog", (alert) => {
- assert.equal(alert.message(), "Are you really sure?")
+ expect(alert.message()).toEqual("Are you really sure?")
alert.dismiss()
})
await page.click("#standard form.confirm #secondary_submitter")
- assert.notOk(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).not.toEqual("true")
})
test("from submission with confirmation overridden", async ({ page }) => {
page.on("dialog", (alert) => {
- assert.equal(alert.message(), "Overridden message")
+ expect(alert.message()).toEqual("Overridden message")
alert.accept()
})
await page.evaluate(() => window.Turbo.setConfirmMethod(() => Promise.resolve(confirm("Overridden message"))))
await page.click("#standard form.confirm input[type=submit]")
- assert.ok(await formSubmitStarted(page))
+ expect(await formSubmitStarted(page)).toEqual("true")
})
test("standard form submission does not render a progress bar before expiring the delay", async ({ page }) => {
await page.evaluate(() => window.Turbo.setProgressBarDelay(500))
await page.click("#standard form.redirect input[type=submit]")
- assert.notOk(await hasSelector(page, ".turbo-progress-bar"), "does not show progress bar before delay")
+ await expect(page.locator(".turbo-progress-bar")).not.toBeVisible()
})
test("standard POST form submission with redirect response", async ({ page }) => {
await page.click("#standard form.redirect input[type=submit]")
- await nextBody(page)
+ await nextEventNamed(page, "turbo:load")
- assert.ok(await formSubmitStarted(page))
- assert.equal(await pathname(page.url()), "/src/tests/fixtures/form.html")
- assert.equal(await visitAction(page), "advance")
- assert.equal(getSearchParam(page.url(), "greeting"), "Hello from a redirect")
- assert.equal(
- await nextAttributeMutationNamed(page, "html", "aria-busy"),
- "true",
- "sets [aria-busy] on the document element"
+ expect(await formSubmitStarted(page)).toEqual("true")
+ expect(await pathname(page.url())).toEqual("/src/tests/fixtures/form.html")
+ expect(await visitAction(page)).toEqual("advance")
+ expect(getSearchParam(page.url(), "greeting")).toEqual("Hello from a redirect")
+ expect(
+ await nextAttributeMutationNamed(page, "html", "aria-busy")
+ ).toEqual(
+ "true"
)
- assert.equal(
- await nextAttributeMutationNamed(page, "html", "aria-busy"),
- null,
- "removes [aria-busy] from the document element"
+ expect(
+ await nextAttributeMutationNamed(page, "html", "aria-busy")
+ ).toEqual(
+ null
)
})
test("standard POST form submission events", async ({ page }) => {
await page.click("#standard-post-form-submit")
- assert.ok(await formSubmitStarted(page), "fires turbo:submit-start")
+ expect(await formSubmitStarted(page)).toEqual("true")
const { fetchOptions } = await nextEventNamed(page, "turbo:before-fetch-request")
- assert.ok(fetchOptions.headers["Accept"].includes("text/vnd.turbo-stream.html"))
+ expect(fetchOptions.headers["Accept"]).toContain("text/vnd.turbo-stream.html")
await nextEventNamed(page, "turbo:before-fetch-response")
- assert.ok(await formSubmitEnded(page), "fires turbo:submit-end")
+ expect(await formSubmitEnded(page)).toEqual("true")
await nextEventNamed(page, "turbo:before-visit")
await nextEventNamed(page, "turbo:visit")
@@ -160,10 +152,9 @@ test("supports transforming a POST submission to a GET in a turbo:submit-start l
}))
)
await page.click("#standard form[method=post] [type=submit]")
- await nextEventNamed(page, "turbo:load")
- assert.equal(await page.textContent("h1"), "One", "overrides the method and action")
- assert.equal(getSearchParam(page.url(), "greeting"), "Hello, from an event listener")
+ await expect(page.locator("h1")).toHaveText("One")
+ expect(getSearchParam(page.url(), "greeting")).toEqual("Hello, from an event listener")
})
test("supports transforming a GET submission to a POST in a turbo:submit-start listener", async ({ page }) => {
@@ -175,10 +166,9 @@ test("supports transforming a GET submission to a POST in a turbo:submit-start l
}))
)
await page.click("#standard form[method=get] [type=submit]")
- await nextEventNamed(page, "turbo:load")
- assert.equal(await page.textContent("h1"), "One", "overrides the method and action")
- assert.equal(getSearchParam(page.url(), "greeting"), "Hello, from an event listener")
+ await expect(page.locator("h1")).toHaveText("One")
+ expect(getSearchParam(page.url(), "greeting")).toEqual("Hello, from an event listener")
})
test("supports modifying the submission in a turbo:before-fetch-request listener", async ({ page }) => {
@@ -191,49 +181,57 @@ test("supports modifying the submission in a turbo:before-fetch-request listener
}))
)
await page.click("#standard form[method=post] [type=submit]")
+
+ await expect(page.locator("h1")).toHaveText("One")
+ expect(getSearchParam(page.url(), "greeting")).toEqual("Hello from a redirect")
+})
+
+test("standard POST form submission merges values from both searchParams and body", async ({ page }) => {
+ await page.click("#form-action-post-redirect-self-q-b")
await nextEventNamed(page, "turbo:load")
- assert.equal(await page.textContent("h1"), "One", "overrides the method and action")
- assert.equal(getSearchParam(page.url(), "greeting"), "Hello from a redirect")
+ expect(pathname(page.url())).toEqual("/src/tests/fixtures/form.html")
+ expect(getSearchParam(page.url(), "q")).toEqual("b")
+ expect(getSearchParam(page.url(), "sort")).toEqual("asc")
})
test("standard POST form submission merges values from both searchParams and body", async ({ page }) => {
await page.click("#form-action-post-redirect-self-q-b")
- await nextBody(page)
+ await nextEventNamed(page, "turbo:load")
- assert.equal(pathname(page.url()), "/src/tests/fixtures/form.html")
- assert.equal(getSearchParam(page.url(), "q"), "b")
- assert.equal(getSearchParam(page.url(), "sort"), "asc")
+ expect(pathname(page.url())).toEqual("/src/tests/fixtures/form.html")
+ expect(getSearchParam(page.url(), "q")).toEqual("b")
+ expect(getSearchParam(page.url(), "sort")).toEqual("asc")
})
test("standard POST form submission toggles submitter [disabled] attribute", async ({ page }) => {
await page.click("#standard-post-form-submit")
- assert.equal(
- await nextAttributeMutationNamed(page, "standard-post-form-submit", "disabled"),
- "",
- "sets [disabled] on the submitter"
+ expect(
+ await nextAttributeMutationNamed(page, "standard-post-form-submit", "disabled")
+ ).toEqual(
+ ""
)
- assert.equal(
- await nextAttributeMutationNamed(page, "standard-post-form-submit", "disabled"),
- null,
- "removes [disabled] from the submitter"
+ expect(
+ await nextAttributeMutationNamed(page, "standard-post-form-submit", "disabled")
+ ).toEqual(
+ null
)
})
test("replaces input value with data-turbo-submits-with on form submission", async ({ page }) => {
- page.click("#submits-with-form-input")
+ await page.click("#submits-with-form-input")
- assert.equal(
- await nextAttributeMutationNamed(page, "submits-with-form-input", "value"),
- "Saving...",
- "sets data-turbo-submits-with on the submitter"
+ expect(
+ await nextAttributeMutationNamed(page, "submits-with-form-input", "value")
+ ).toEqual(
+ "Saving..."
)
- assert.equal(
- await nextAttributeMutationNamed(page, "submits-with-form-input", "value"),
- "Save",
- "restores the original submitter text value"
+ expect(
+ await nextAttributeMutationNamed(page, "submits-with-form-input", "value")
+ ).toEqual(
+ "Save"
)
})
@@ -241,17 +239,17 @@ test("replaces button innerHTML with data-turbo-submits-with on form submission"
await page.click("#submits-with-form-button")
await nextEventNamed(page, "turbo:submit-start")
- assert.equal(
- await page.textContent("#submits-with-form-button"),
- "Saving...",
- "sets data-turbo-submits-with on the submitter"
+ await expect(
+ page.locator("#submits-with-form-button")
+ ).toHaveText(
+ "Saving..."
)
await nextEventNamed(page, "turbo:submit-end")
- assert.equal(
- await page.textContent("#submits-with-form-button"),
- "Save",
- "sets data-turbo-submits-with on the submitter"
+ await expect(
+ page.locator("#submits-with-form-button")
+ ).toHaveText(
+ "Save"
)
})
@@ -259,44 +257,41 @@ test("standard GET form submission", async ({ page }) => {
await page.click("#standard form.greeting input[type=submit]")
await nextBody(page)
- assert.ok(await formSubmitStarted(page))
- assert.equal(pathname(page.url()), "/src/tests/fixtures/one.html")
- assert.equal(await visitAction(page), "advance")
- assert.equal(getSearchParam(page.url(), "greeting"), "Hello from a form")
- assert.equal(
- await nextAttributeMutationNamed(page, "html", "aria-busy"),
- "true",
- "sets [aria-busy] on the document element"
+ expect(await formSubmitStarted(page)).toEqual("true")
+ expect(pathname(page.url())).toEqual("/src/tests/fixtures/one.html")
+ expect(await visitAction(page)).toEqual("advance")
+ expect(getSearchParam(page.url(), "greeting")).toEqual("Hello from a form")
+ expect(
+ await nextAttributeMutationNamed(page, "html", "aria-busy")
+ ).toEqual(
+ "true"
)
- assert.equal(
- await nextAttributeMutationNamed(page, "html", "aria-busy"),
- null,
- "removes [aria-busy] from the document element"
+ expect(
+ await nextAttributeMutationNamed(page, "html", "aria-busy")
+ ).toEqual(
+ null
)
})
test("standard GET HTMLFormElement.requestSubmit() with Turbo Action", async ({ page }) => {
- await page.evaluate(() => {
- const formControl = document.querySelector("#external-select")
-
+ const select = await page.locator("#external-select")
+ await select.evaluate((formControl) => {
if (formControl && formControl.form) formControl.form.requestSubmit()
})
await nextEventNamed(page, "turbo:load")
- assert.equal(await page.textContent("h1"), "Form", "Retains original page state")
- assert.equal(await page.textContent("#hello h2"), "Hello from a frame", "navigates #hello turbo frame")
- assert.equal(await visitAction(page), "replace", "reads Turbo Action from