Reputation: 544
I try to test my saga
and i have some problems with testing select
.
I want to mock createSelector
from reselect
, but i can't do this, because i have this error:
Cannot read property \'module\' of undefined
my reselect:
//R - is ramda
export const selectFilters = createSelector(R.path(['notification', 'filters']), (filters) => filters)
my saga:
//module gives me error because selectFilters returns undefined
const {module, orderByDate} = yield select(selectors.selectFilters())
Upvotes: 0
Views: 1133
Reputation: 5368
2 ways.
1.
jest.mock('bla/bla/selectors', () => ({
selectFilters: jest.fn(() => anythingToReturn),
}));
import {selectFilters} from 'bla/bla/selectors'
jest.mock('bla/bla/selectors')
it('should ...', () => {
(selectFilters as any).mockReturnValueOnce(anythingToReturn)
})
Upvotes: 0
Reputation: 2332
You have to pass the reference to of the selector the the select
effect. In your saga, you are actually calling the selector, and then passing the return value. If you do it properly, you don't have to mock the selector.
Modify your code like this to fix the error:
const {module, orderByDate} = yield select(selectors.selectFilters)
Upvotes: 1