Testing Your Subscriptions
Run it like a Function
export const mySubscription = (dispatch, delay, onIntervalAction) => dispatch => {
const handle = setInterval(dispatch, delay, onIntervalAction);
return () => {
clearInterval(handle);
};
};import { mySubscription } from './mySubscription.js';
import * as sinon from 'sinon';
describe('mySubscription', () => {
it('creates an interval', () => {
expect.assertions(1);
sinon.spyOn(global, 'setInterval');
const dispatch = sinon.fake();
const myAction = () => {};
const cleanup = mySubscription(dispatch, 1000, myAction);
expect(global.setInterval.mock.calls).toHaveLength(1);
cleanup();
expect(dispatch.calledWith, [myAction]);
setInterval.restore();
});
});End to End Testing
Last updated