Files
kochwas/tests/unit/toast-store.test.ts

36 lines
1.2 KiB
TypeScript
Raw Normal View History

import { describe, it, expect, beforeEach, vi } from 'vitest';
describe('toast store', () => {
beforeEach(async () => {
vi.useFakeTimers();
const mod = await import('../../src/lib/client/toast.svelte');
mod.toastStore.toasts = [];
});
it('queues toasts with auto-dismiss', async () => {
const { toastStore } = await import('../../src/lib/client/toast.svelte');
toastStore.info('Hello');
expect(toastStore.toasts.length).toBe(1);
expect(toastStore.toasts[0].message).toBe('Hello');
expect(toastStore.toasts[0].kind).toBe('info');
vi.advanceTimersByTime(3000);
expect(toastStore.toasts.length).toBe(0);
});
it('supports error kind and manual dismiss', async () => {
const { toastStore } = await import('../../src/lib/client/toast.svelte');
const id = toastStore.error('Boom');
expect(toastStore.toasts[0].kind).toBe('error');
toastStore.dismiss(id);
expect(toastStore.toasts.length).toBe(0);
});
it('allows multiple concurrent toasts', async () => {
const { toastStore } = await import('../../src/lib/client/toast.svelte');
toastStore.info('A');
toastStore.info('B');
expect(toastStore.toasts.length).toBe(2);
});
});