Error on expectSaga.provide selector (state is undefined)
See original GitHub issueHey there! I’m implementing redux-saga-test-plan
on an existent project, and I’m having some troubles to use expectSaga.provide
with a specific kind of selector, and I do believe that this has been caused by some bug on the provide
at the moment of recognizing and mocking my selector.
I have something like that:
// Selector
const selectFruit = name => state => state.fruits[name]
// Saga
function* onGetFruit({ payload: { name } }) {
const myFruit = yield select(selectFruit(name))
if (myFruit === 'apple') {
const apple = {
edible: true,
color: 'red',
}
yield put(eatTheFuit(apple))
}
}
// Test
it('should find an apple and dispatch an eat action', () => {
return expectSaga(onGetFruit, {
payload: { name: 'apple' },
})
.provide([
[select(selectFruit('apple')), {
name: 'apple',
}],
])
.put({
type: 'EAT_THE_FRUIT', payload: {
edible: true,
color: 'red',
},
})
.run()
})
So, with this scenario I’m always getting an error like that:
TypeError: Cannot read property 'fruits' of undefined
> 2 | const selectFruit = name => state => state.fruits[name]
| ^
I’ve noticed that this doesn’t happen for some selector similar to that, where I use some kind of memoize
, like:
const memoizedSelectFruit = memoize(name => state => state.fruits[name])
I hope someone could help me with that! And thanks @jfairbank for this amazing package 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6
Top Results From Across the Web
Can not provide/test saga when using a reselect selector
The error I get is: It looks as though the reselect selector function is running and trying to access the global state from...
Read more >Dynamic Providers · GitBook - Redux Saga Test Plan
You can use completely dynamic providers by passing in an object literal to the provide method. The object literal argument must contain effect...
Read more >Testing Sagas - Redux-Saga
The redux-saga-test library provides syntactic sugar for your step-by-step tests. ... The testSaga API is used for exact order testing and expectSaga is...
Read more >Source - GitHub
Bug Fixes * (#183) You can now provide mock values for nested forks and spawns. ... ```js it('tests final store state', () =>...
Read more >React Redux - Undefined issues when following the Quick start
My problem is that I get an undefined error as follows: TypeError: state.user_display is undefined > 8 | const user = useSelector((state) ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve “worked around” this question by changing those selectors to pass the argument as a second parameter of the function, like it’s suggested on redux-saga docs.
This way I can pass a second parameter to
select
, specifying theid
,name
or whatever. To clarify, I udated the same first example:I was able to test a curried selector-function by using
matchers
instead ofselect
directly. I guess in your example it would be like this…