1
0

nested-suspense.spec.js 2.8 KB

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