From 06ac086bdccac69616310abe6674c791405714ec Mon Sep 17 00:00:00 2001 From: AlexandrHoroshih Date: Mon, 11 Dec 2023 23:02:58 +0700 Subject: [PATCH] Test logs --- .../src/lib/redux-interop.spec.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/redux-interop/src/lib/redux-interop.spec.ts b/packages/redux-interop/src/lib/redux-interop.spec.ts index 3a35fa1a..ee47186d 100644 --- a/packages/redux-interop/src/lib/redux-interop.spec.ts +++ b/packages/redux-interop/src/lib/redux-interop.spec.ts @@ -28,6 +28,50 @@ describe('@withease/redux', () => { ); }); + test('Init errors are logged into console', () => { + const fakeStore = { + dispatch: () => { + throw new Error('fake dispatch!'); + }, + getState: () => { + return {}; + }, + subscribe: () => { + throw new Error('fake subscribe!'); + }, + }; + + const setup = createEvent(); + + const spy = vi.spyOn(console, 'error').mockImplementation(() => { + // ok + }); + + // @ts-expect-error - fakeStore is not a Redux store + const int = createReduxInterop({ reduxStore: fakeStore, setup }); + + expect(spy.mock.calls.map((x) => x[0])).toMatchInlineSnapshot('[]'); + + setup(); + + expect(spy.mock.calls.map((x) => x[0])).toMatchInlineSnapshot(` + [ + [Error: fake subscribe!], + ] + `); + + int.dispatch({ type: 'kek' }); + + expect(spy.mock.calls.map((x) => x[0])).toMatchInlineSnapshot(` + [ + [Error: fake subscribe!], + [Error: fake dispatch!], + ] + `); + + spy.mockRestore(); + }); + describe('raw Redux', () => { test('Should take redux store in', () => { const reduxStore = legacy_createStore(() => ({}), {});