nested-suspense.spec.js 2.6 KB

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