redux-observable-test-helpers
Unit test helpers for redux-observable epics
Install
npm:
Install withnpm i redux-observable-test-helpers --save-dev
Background
Testing async code that creates side effects isn't easy. One recommendation to make async testing with RXJS easier and more consistent is incorporating "marble notation" as a DSL for creating unit tests. "Marble Tests" are tests that use a specialized VirtualScheduler called the TestScheduler. They enable us to test asynchronous operations in a synchronous and dependable manner. By keeping our async "side-effects" within our epics we can leverage a simple test helper, expectEpic, to create concise and deterministic tests.
Usage
ES6
;
ES5
var helpers = ;var expectEpic = helpersexpectEpic;
Signature /** * expectEpic - Test helper for redux-observable epics * * @param epic - the redux-observable epic to test *{ * @param action - marble notation for the action the epic is listening for * @param call - (optional) a local sinon.spy used to get/set/reset api calls * @param callArgs - (optional) An array containing the api method, followed by any params * @param done - (optional) mocha callback for async tests * @param expected - marble notation for the expected result * @param replace - (optional) allows replacement of fields using timestamps or other generated values * @param response - the expected payload * @param store - (optional) a reference to the redux store *} */ const expectEpic = {...};
expectEpic Examples
- JSBin with multiple observables expected in the same frame
- JSBin with indirect ajax call
- JSBin with interval