Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions apps/mobile/__tests__/toast.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { toast } from '../src/utils/toast';

describe('toast utility', () => {
let mockListener: jest.Mock;

beforeEach(() => {
mockListener = jest.fn();
});

afterEach(() => {
// Clear listeners to avoid leaking between tests
// Since we don't have a public clear method, we rely on unsubscribe
jest.clearAllMocks();
});

it('subscribes and receives a show event', () => {
const unsubscribe = toast.subscribe(mockListener);
toast.show('Hello World', 'info', 2000);

expect(mockListener).toHaveBeenCalledTimes(1);
expect(mockListener).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Hello World',
type: 'info',
duration: 2000,
id: expect.any(String)
})
);

unsubscribe();
});

it('helper methods work correctly', () => {
const unsubscribe = toast.subscribe(mockListener);

toast.success('Success message');
expect(mockListener).toHaveBeenLastCalledWith(
expect.objectContaining({ message: 'Success message', type: 'success' })
);

toast.error('Error message');
expect(mockListener).toHaveBeenLastCalledWith(
expect.objectContaining({ message: 'Error message', type: 'error' })
);

toast.warning('Warning message');
expect(mockListener).toHaveBeenLastCalledWith(
expect.objectContaining({ message: 'Warning message', type: 'warning' })
);

toast.info('Info message');
expect(mockListener).toHaveBeenLastCalledWith(
expect.objectContaining({ message: 'Info message', type: 'info' })
);

unsubscribe();
});

it('unsubscribes correctly', () => {
const unsubscribe = toast.subscribe(mockListener);
unsubscribe();

toast.show('Test');
expect(mockListener).not.toHaveBeenCalled();
});
});
Loading