Skip to content

An opinionated toast component for React.

fix: swipe test (#545)

Emil Kowalski7d017fce95a7
diff --git a/test/tests/basic.spec.ts b/test/tests/basic.spec.ts
index 019f400..4c9a2ab 100644
--- a/test/tests/basic.spec.ts
+++ b/test/tests/basic.spec.ts
@@ -109,19 +109,23 @@ test.describe('Basic functionality', () => {
test("toast's dismiss callback gets executed correctly", async ({ page }) => {
await page.getByTestId('dismiss-toast-callback').click();
const toast = page.locator('[data-sonner-toast]');
- const dragBoundingBox = await toast.boundingBox();
- if (!dragBoundingBox) return;
+ await toast.waitFor({ state: 'visible' });
- // Initial touch point
- await page.mouse.move(dragBoundingBox.x + dragBoundingBox.width / 2, dragBoundingBox.y);
+ const box = await toast.boundingBox();
+ if (!box) return;
+
+ const startX = box.x + box.width / 2;
+ const startY = box.y + box.height / 2;
+
+ await page.mouse.move(startX, startY);
await page.mouse.down();
- // Move mouse slightly to determine swipe direction
- await page.mouse.move(dragBoundingBox.x + dragBoundingBox.width / 2, dragBoundingBox.y + 10);
+ // Small initial movement to trigger drag
+ await page.mouse.move(startX, startY + 20, { steps: 5 });
- // Complete the swipe
- await page.mouse.move(0, dragBoundingBox.y + 300);
+ // Main swipe movement
+ await page.mouse.move(startX, startY + 300, { steps: 10 });
await page.mouse.up();
await expect(page.getByTestId('dismiss-el')).toHaveCount(1);