1 year ago
#388209
Deiver Garcia
react-redux mock subscribe useStore in reactJS
This is the element where the component logic is built, the value fragments to understand the situation
import { useStore } from ‘react-redux’;
const reduxStore = useStore();
useLayoutEffect(() => {
const unsubscribe = reduxStore.subscribe(obtainDataStore);
return () => {
unsubscribe();
};
}, [obtainDataStore, reduxStore]);
I need to be able to generate a mock that allows me to respond to subscribers in a jest test in order to generate usability tests of my component I am doing the following
import useCalculatePublish from ‘./component’;
import { renderHook } from ‘@testing-library/react-hooks’;
import { useStore } from ‘react-redux’;
jest.mock(‘react-redux’);
const store = { years: { first: ‘’, last: ‘’ }, category: ‘’, status: ‘’ };
describe(‘’, () => {
it(‘loaded’, async () => {
mockUseStore(store);
let x = await renderHook(() => useCalculatePublish(‘test’));
console.log(x);
});
});
const mockUseStore = ({ years, status, category }) => {
useStore.mockReturnValue({
...mockUseStore,
getState: jest.fn().mockRejectedValue({
filterReducer: { years, status, category },
}),
subscribe: jest.fn(),
});
};
Thanks in advance to anyone who can help me with this question...
reactjs
redux
jestjs
mocking
0 Answers
Your Answer