具有以下 redux-observable 史诗:
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"};
}
};
和以下测试
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([]);
});
});
store.getActions() 返回一个带有一个动作的数组 - “MOUSE_OVER”。而在消除去抖动时,它会返回另一个(和预期的)动作 - “OVER”。
我想在测试中存根/删除去抖动运算符。尝试使用 sinon 存根函数遵循此链接中的想法,但没有成功。
一些关于如何模拟 RxJS 运算符或特别是去抖动/节流的指南将不胜感激。
使用 React、Mocha、Chai、Enzyme……
谢谢