1
0

fullstack.spec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // @ts-check
  2. const { test, expect } = require("@playwright/test");
  3. test("hydration", async ({ page }) => {
  4. await page.goto("http://localhost:3333");
  5. // Expect the page to contain the pending text.
  6. const main = page.locator("#main");
  7. await expect(main).toContainText("Server said: ...");
  8. // Expect the page to contain the counter text.
  9. await expect(main).toContainText("hello axum! 12345");
  10. // Expect the title to contain the counter text.
  11. await expect(page).toHaveTitle("hello axum! 12345");
  12. // Click the increment button.
  13. let button = page.locator("button.increment-button");
  14. await button.click();
  15. // Click the server button.
  16. let serverButton = page.locator("button.server-button");
  17. await serverButton.click();
  18. // Expect the page to contain the updated counter text.
  19. await expect(main).toContainText("hello axum! 12346");
  20. // Expect the title to contain the updated counter text.
  21. await expect(page).toHaveTitle("hello axum! 12346");
  22. // Expect the page to contain the updated counter text.
  23. await expect(main).toContainText("Server said: Hello from the server!");
  24. // Make sure the error that was thrown on the server is shown in the error boundary on the client
  25. const errors = page.locator("#errors");
  26. await expect(errors).toContainText("Hmm, something went wrong.");
  27. // Expect the onmounted event to be called exactly once.
  28. const mountedDiv = page.locator("div.onmounted-div");
  29. await expect(mountedDiv).toHaveText("onmounted was called 1 times");
  30. });