suspense-carousel.spec.js 2.3 KB

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