Skip to content

Instantly share code, notes, and snippets.

@kevinsalter
Created November 20, 2016 05:04
Show Gist options
  • Save kevinsalter/91702a8e5b81b0c6ae871afa1ec49c17 to your computer and use it in GitHub Desktop.
Save kevinsalter/91702a8e5b81b0c6ae871afa1ec49c17 to your computer and use it in GitHub Desktop.
import { assert } from 'chai';
import { ActionsObservable } from 'redux-observable';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/toArray';
import saveFieldEpic from './saveField.js';
const action$ = ActionsObservable.of(
{type: 'SAVE_FIELD', payload: {url: '/api/endpoint/9999/'}}
);
describe('saveFieldEpic Epic', () => {
it('dispatches the correct actions when it is successful', (done) => {
const ajax = () => Observable.of({});
const expectedOutputActions = [{type: "IS_SAVING"}, {type: "SAVING_SUCCESS"}];
saveFieldEpic(action$, null, {ajax})
.toArray()
.subscribe(actualOutputActions => {
assert.deepEqual(actualOutputActions, expectedOutputActions);
done();
}
);
});
it('dispatches the correct actions when there is an error', (done) => {
const ajax = () => Observable.throw('save failed');
const expectedOutputActions = [
{type: "IS_SAVING"},
{type: "SAVING_ERROR", error: 'save failed'},
];
saveFieldEpic(action$, null, {ajax})
.toArray()
.subscribe(actualOutputActions => {
assert.deepEqual(actualOutputActions, expectedOutputActions);
done();
}
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment