suspense-carousel.spec.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @ts-check
  2. const { test, expect } = require("@playwright/test");
  3. test("suspense resolves on server", async ({ page }) => {
  4. await page.goto("http://localhost:4040", { waitUntil: "commit" });
  5. // On the client, we should see some loading text
  6. const main = page.locator("#main");
  7. await expect(main).toContainText("Loading...");
  8. await page.waitForTimeout(1000);
  9. // Expect the page to contain the suspense result from the server
  10. await expect(main).toContainText("outer suspense result: Server");
  11. // And more loading text for the nested suspense
  12. await expect(main).toContainText("Loading... more");
  13. await page.waitForTimeout(1000);
  14. // And the nested suspense result
  15. await expect(main).toContainText("nested suspense result: Server");
  16. // Click the outer button
  17. let button = page.locator("button#outer-button-0");
  18. await button.click();
  19. // The button should have incremented
  20. await expect(button).toContainText("1");
  21. // Click the nested button
  22. button = page.locator("button#nested-button-0");
  23. await button.click();
  24. // The button should have incremented
  25. await expect(button).toContainText("1");
  26. // Now incrementing the carousel should create a new suspense boundary
  27. let incrementCarouselButton = page.locator(
  28. "button#increment-carousel-button"
  29. );
  30. await incrementCarouselButton.click();
  31. // A new pending suspense should be created on the client
  32. await expect(main).toContainText("Loading...");
  33. // The suspense should resolve on the client
  34. let newSuspense = page.locator("#outer-3");
  35. await expect(newSuspense).toContainText("outer suspense result: Client");
  36. // It should be loading more
  37. await expect(newSuspense).toContainText("Loading... more");
  38. // And the nested suspense result
  39. await expect(newSuspense).toContainText("nested suspense result: Client");
  40. // Click the outer button
  41. button = page.locator("button#outer-button-3");
  42. await button.click();
  43. // The button should have incremented
  44. await expect(button).toContainText("1");
  45. // Click the nested button
  46. button = page.locator("button#nested-button-3");
  47. await button.click();
  48. // The button should have incremented
  49. await expect(button).toContainText("1");
  50. });