jestjsredux-sagareselect

How i can mock Reselect functions with jest?


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())


Solution

  • 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)