nested-suspense-ssg.spec.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // @ts-check
  2. const { test, expect } = require("@playwright/test");
  3. test("nested suspense resolves", async ({ page }) => {
  4. // Wait for the dev server to reload
  5. await page.goto("http://localhost:5050");
  6. // Then wait for the page to start loading
  7. await page.goto("http://localhost:5050", { waitUntil: "commit" });
  8. // Expect the page to contain the suspense result from the server
  9. const mainMessageTitle = page.locator("#title-0");
  10. await expect(mainMessageTitle).toContainText("The robot says hello world");
  11. const mainMessageBody = page.locator("#body-0");
  12. await expect(mainMessageBody).toContainText(
  13. "The robot becomes sentient and says hello world"
  14. );
  15. // And expect the title to have resolved on the client
  16. await expect(page).toHaveTitle("The robot says hello world");
  17. // Nested suspense should be resolved
  18. const nestedMessageTitle1 = page.locator("#title-1");
  19. await expect(nestedMessageTitle1).toContainText("The world says hello back");
  20. const nestedMessageBody1 = page.locator("#body-1");
  21. await expect(nestedMessageBody1).toContainText(
  22. "In a stunning turn of events, the world collectively unites and says hello back"
  23. );
  24. const nestedMessageDiv2 = page.locator("#children-2");
  25. await expect(nestedMessageDiv2).toBeEmpty();
  26. const nestedMessageTitle2 = page.locator("#title-2");
  27. await expect(nestedMessageTitle2).toContainText("Goodbye Robot");
  28. const nestedMessageBody2 = page.locator("#body-2");
  29. await expect(nestedMessageBody2).toContainText("The robot says goodbye");
  30. const nestedMessageDiv3 = page.locator("#children-3");
  31. await expect(nestedMessageDiv3).toBeEmpty();
  32. const nestedMessageTitle3 = page.locator("#title-3");
  33. await expect(nestedMessageTitle3).toContainText("Goodbye World");
  34. const nestedMessageBody3 = page.locator("#body-3");
  35. await expect(nestedMessageBody3).toContainText("The world says goodbye");
  36. // Deeply nested suspense should be resolved
  37. const nestedMessageDiv4 = page.locator("#children-4");
  38. await expect(nestedMessageDiv4).toBeEmpty();
  39. const nestedMessageTitle4 = page.locator("#title-4");
  40. await expect(nestedMessageTitle4).toContainText("Hello World");
  41. const nestedMessageBody4 = page.locator("#body-4");
  42. await expect(nestedMessageBody4).toContainText("The world says hello again");
  43. });