Having the following redux-observable epic:
export const mouseEventEpic = (action$, store) =>
action$
::filter(action => action.type === MOUSE_OUT || action.type === MOUSE_OVER)
::debounceTime(200)
::map(action => getMappedAction(action, store));
const getMappedAction = (action, store) => {
switch (action.type) {
case MOUSE_OVER:
return {type: "OVER"};
case MOUSE_OUT:
return {type: "OUT"};
}
};
and the following test
import { expect } from 'chai';
import configureMockStore from 'redux-mock-store';
import { createEpicMiddleware } from 'redux-observable';
import { mouseEventEpic } from '...';
const epicMiddleware = createEpicMiddleware(mouseEventEpic );
const mockStore = configureMockStore([epicMiddleware]);
describe('Epic...', () => {
let store;
beforeEach(() => {
store = mockStore({});
});
it('test...', () => {
store.dispatch({type:'MOUSE_OVER'});
expect(store.getActions()).to.deep.equal([]);
});
});
The store.getActions() returns an array with one action - "MOUSE_OVER". Whereas when removing the debounce it returns another (and the expected) action - "OVER".
I'd like to stub/remove the debounce operator in the test.
Tried to follow the ideas in this link using the sinon stub function with no success.
Some guideline on how to mock a RxJS operator or specifically the debounce/throttle would be appreciated.
Using React, Mocha, Chai, Enzyme...
thanks
There are many ways, one would be to stub it out, but it has to be stubbed out before your epic is started, otherwise the operator has already been called and stubbing it will do nothing (this may be what happened when you tried).
I believe you'd need to move your middleware/store creation logic into the
beforeEach
, and stub outdebounceTime
in there too, before you create the middleware/store.As far as how to stub, one example using sinon is: