nested-suspense.spec.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 more loading text for the nested suspense
  17. await expect(mainMessageDiv).toContainText("Loading 1...");
  18. await expect(mainMessageDiv).toContainText("Loading 2...");
  19. await expect(mainMessageDiv).toContainText("Loading 3...");
  20. const nestedMessageDiv1 = page.locator("#children-1");
  21. const nestedMessageTitle1 = page.locator("#title-1");
  22. await expect(nestedMessageTitle1).toContainText("The world says hello back");
  23. const nestedMessageBody1 = page.locator("#body-1");
  24. await expect(nestedMessageBody1).toContainText(
  25. "In a stunning turn of events, the world collectively unites and says hello back"
  26. );
  27. const nestedMessageDiv2 = page.locator("#children-2");
  28. await expect(nestedMessageDiv2).toBeEmpty();
  29. const nestedMessageTitle2 = page.locator("#title-2");
  30. await expect(nestedMessageTitle2).toContainText("Goodbye Robot");
  31. const nestedMessageBody2 = page.locator("#body-2");
  32. await expect(nestedMessageBody2).toContainText("The robot says goodbye");
  33. const nestedMessageDiv3 = page.locator("#children-3");
  34. await expect(nestedMessageDiv3).toBeEmpty();
  35. const nestedMessageTitle3 = page.locator("#title-3");
  36. await expect(nestedMessageTitle3).toContainText("Goodbye World");
  37. const nestedMessageBody3 = page.locator("#body-3");
  38. await expect(nestedMessageBody3).toContainText("The world says goodbye");
  39. // Even more loading text for the deeply nested suspense
  40. await expect(nestedMessageDiv1).toContainText("Loading 4...");
  41. const nestedMessageDiv4 = page.locator("#children-4");
  42. await expect(nestedMessageDiv4).toBeEmpty();
  43. const nestedMessageTitle4 = page.locator("#title-4");
  44. await expect(nestedMessageTitle4).toContainText("Hello World");
  45. const nestedMessageBody4 = page.locator("#body-4");
  46. await expect(nestedMessageBody4).toContainText("The world says hello again");
  47. });