From 137df708ce47e4aa9ca79b2e0bcf24b9ff5cd757 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2026 20:11:27 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20for=20toast=20util?= =?UTF-8?q?ity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🎯 What: Added tests for the simple event emitter toast utility. * 📊 Coverage: Testing covers subscribing, receiving events, helper methods (success, error, warning, info) and unsubscribing. * ✨ Result: Improved test coverage and reliability of the toast component. --- apps/mobile/__tests__/toast.test.ts | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 apps/mobile/__tests__/toast.test.ts diff --git a/apps/mobile/__tests__/toast.test.ts b/apps/mobile/__tests__/toast.test.ts new file mode 100644 index 0000000..3f3aa21 --- /dev/null +++ b/apps/mobile/__tests__/toast.test.ts @@ -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(); + }); +});