diff --git a/src/index.tsx b/src/index.tsx
index ce031e8..c87c787 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -423,11 +423,11 @@ const Toast = (props: ToastProps) => {
data-close-button
onClick={
disabled || !dismissible
- ? () => {}
+ ? () => { }
: () => {
- deleteToast();
- toast.onDismiss?.(toast);
- }
+ deleteToast();
+ toast.onDismiss?.(toast);
+ }
}
className={cn(classNames?.closeButton, toast?.classNames?.closeButton)}
>
@@ -436,11 +436,12 @@ const Toast = (props: ToastProps) => {
) : null}
{/* TODO: This can be cleaner */}
{(toastType || toast.icon || toast.promise) &&
- toast.icon !== null &&
- (icons?.[toastType] !== null || toast.icon) ? (
+ toast.icon !== null &&
+ (icons?.[toastType] !== null || toast.icon) ? (
- {toast.promise || (toast.type === 'loading' && !toast.icon) ? toast.icon || getLoadingIcon() : null}
- {toast.type !== 'loading' ? icon : null}
+ {toast.type === 'loading'
+ ? toast.icon || getLoadingIcon()
+ : icon}
) : null}
@@ -632,10 +633,10 @@ const Toaster = React.forwardRef(function Toaster(pro
theme !== 'system'
? theme
: typeof window !== 'undefined'
- ? window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
- ? 'dark'
- : 'light'
- : 'light',
+ ? window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
+ ? 'dark'
+ : 'light'
+ : 'light',
);
const listRef = React.useRef(null);
diff --git a/test/src/app/page.tsx b/test/src/app/page.tsx
index ef50965..2c7a74f 100644
--- a/test/src/app/page.tsx
+++ b/test/src/app/page.tsx
@@ -364,6 +364,30 @@ export default function Home({ searchParams }: any) {
>
Promise Toast with testId
+
{showAutoClose ? : null}
{showDismiss ? : null}
{
await expect(page.getByTestId('promise-test-toast')).toHaveText('Loading...');
await expect(page.getByTestId('promise-test-toast')).toHaveText('Loaded');
});
+
+ test('promise toast with custom icon should replace loader on success', async ({ page }) => {
+ await page.getByTestId('promise-custom-icon').click();
+ await expect(page.getByText('Loading...')).toBeVisible();
+ await expect(page.getByText('Finished!')).toBeVisible();
+ const icons = page.locator('[data-sonner-toast] svg');
+ await expect(icons).toHaveCount(1);
+ });
+
});