Skip to content

Commit

Permalink
feat: add test for updating toast
Browse files Browse the repository at this point in the history
  • Loading branch information
estubmo committed Oct 1, 2023
1 parent 8c34fe2 commit 700c534
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions test/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ export default function Home({ searchParams }: any) {
>
Non-dismissible Toast
</button>
<button
data-testid="update-toast"
className="button"
onClick={() => {
const toastId = toast('My Unupdated Toast', {
duration: 10000,
});
toast('My Updated Toast', {
id: toastId,
duration: 10000,
});
}}
>
Updated Toast
</button>
{showAutoClose ? <div data-testid="auto-close-el" /> : null}
{showDismiss ? <div data-testid="dismiss-el" /> : null}
<Toaster position={searchParams.position || 'bottom-right'} theme={theme} dir={searchParams.dir || 'auto'} />
Expand Down
8 changes: 7 additions & 1 deletion test/tests/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test';
import { expect, test } from '@playwright/test';

test.beforeEach(async ({ page }) => {
await page.goto('/');
Expand Down Expand Up @@ -159,4 +159,10 @@ test.describe('Basic functionality', () => {
await page.getByTestId('default-button').click();
await expect(page.locator('[data-sonner-toaster]')).toHaveAttribute('dir', 'ltr');
});

test('show correct toast content when updating', async ({ page }) => {
await page.getByTestId('update-toast').click();
await expect(page.getByText('My Unupdated Toast')).toHaveCount(0);
await expect(page.getByText('My Updated Toast')).toHaveCount(1);
});
});

0 comments on commit 700c534

Please sign in to comment.