Skip to content

Commit

Permalink
Test logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrHoroshih committed Dec 11, 2023
1 parent 6b2a83e commit 06ac086
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/redux-interop/src/lib/redux-interop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({}), {});
Expand Down

0 comments on commit 06ac086

Please sign in to comment.