From 715607703805296881752a3bb784de76377dd5b9 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 21:01:53 +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 | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 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..2eb649d --- /dev/null +++ b/apps/mobile/__tests__/toast.test.ts @@ -0,0 +1,46 @@ +describe('toast utility', () => { + let toast: typeof import('../src/utils/toast').toast; + let mockListener: jest.Mock; + + beforeEach(async () => { + jest.resetModules(); + const mod = await import('../src/utils/toast'); + toast = mod.toast; + mockListener = jest.fn(); + }); + + 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({ type: 'success' })); + + toast.error('Error message'); + expect(mockListener).toHaveBeenLastCalledWith(expect.objectContaining({ type: 'error' })); + + toast.warning('Warning message'); + expect(mockListener).toHaveBeenLastCalledWith(expect.objectContaining({ type: 'warning' })); + + toast.info('Info message'); + expect(mockListener).toHaveBeenLastCalledWith(expect.objectContaining({ type: 'info' })); + unsubscribe(); + }); + + it('unsubscribes correctly', () => { + const unsubscribe = toast.subscribe(mockListener); + unsubscribe(); + toast.show('Test'); + expect(mockListener).not.toHaveBeenCalled(); + }); +});