I created a saga that retrieves a value from the store with select and according to this value runs a statement or another:
const {id} = action.payload;
try {
const cache = yield select(state => state.cache);
if (cache[id]) {
// Do something
} else {
// Do something else
} catch (e) {
// errors
}
I tried to mock the store with react-mock-store :
import configureStore from 'redux-mock-store';
import createSagaMiddleware from 'redux-saga';
import { expect } from 'chai';
import { getCacheSaga } from '../../../src/js/sagas/cache-saga';
import { GET_CACHE } from '../../../src/js/actions/cache-actions';
const middlewares = [createSagaMiddleware()];
const mockStore = configureStore(middlewares);
mockStore({ cache: { foo: {} } });
describe('get cache saga', () => {
describe('getCacheSaga', () => {
it('retrieves data from cache', () => {
const iterator = getFormSaga({
payload: { id: 'foo' },
});
const cache = iterator.next();
console.log(cache); // undefined
});
});
but that does not work. Any ideas?