UNPKG

sharyn

Version:

Combines all the other packages under one.

131 lines (128 loc) 3.29 kB
"use strict"; var _recompose = require("recompose"); var _asyncReductions = require("./async-reductions"); test('setAsyncRequest', function () { var asyncState = {}; expect((0, _asyncReductions.setAsyncRequest)(asyncState, { key: 'foo' })).toEqual({ foo: true }); expect((0, _asyncReductions.setAsyncRequest)(asyncState, { key: 'foo', useStatus: true })).toEqual({ foo: 'REQUEST' }); expect((0, _asyncReductions.setAsyncRequest)(asyncState, { key: 'foo', status: 'CUSTOM' })).toEqual({ foo: 'CUSTOM' }); expect(function () { return (0, _asyncReductions.setAsyncRequest)(asyncState, { key: 'foo', useStatus: false, status: 'CUSTOM' }); }).toThrow(); expect((0, _recompose.compose)((0, _asyncReductions.setAsyncRequest)({ key: 'foo', status: 'CUSTOM' }))(asyncState)).toEqual({ foo: 'CUSTOM' }); }); test('setAsyncSuccess', function () { var asyncState = { foo: true }; expect((0, _asyncReductions.setAsyncSuccess)(asyncState, { key: 'foo' })).toEqual({}); expect((0, _asyncReductions.setAsyncSuccess)(asyncState, { key: 'foo', useStatus: true })).toEqual({ foo: 'SUCCESS' }); expect((0, _asyncReductions.setAsyncSuccess)(asyncState, { key: 'foo', status: 'CUSTOM' })).toEqual({ foo: 'CUSTOM' }); expect(function () { return (0, _asyncReductions.setAsyncSuccess)(asyncState, { key: 'foo', useStatus: false, status: 'CUSTOM' }); }).toThrow(); expect((0, _recompose.compose)((0, _asyncReductions.setAsyncSuccess)({ key: 'foo', status: 'CUSTOM' }))(asyncState)).toEqual({ foo: 'CUSTOM' }); }); test('setAsyncFailure', function () { var asyncState = { foo: true }; expect((0, _asyncReductions.setAsyncFailure)(asyncState, { key: 'foo' })).toEqual({}); expect((0, _asyncReductions.setAsyncFailure)(asyncState, { key: 'foo', useStatus: true })).toEqual({ foo: 'FAILURE' }); expect((0, _asyncReductions.setAsyncFailure)(asyncState, { key: 'foo', status: 'CUSTOM' })).toEqual({ foo: 'CUSTOM' }); expect(function () { return (0, _asyncReductions.setAsyncFailure)(asyncState, { key: 'foo', useStatus: false, status: 'CUSTOM' }); }).toThrow(); expect((0, _recompose.compose)((0, _asyncReductions.setAsyncFailure)({ key: 'foo', status: 'CUSTOM' }))(asyncState)).toEqual({ foo: 'CUSTOM' }); }); test('delAsyncEntry', function () { var asyncState = { foo: 'foo' }; expect(function () { return (0, _asyncReductions.delAsyncEntry)(); }).toThrow(); expect(function () { return (0, _asyncReductions.delAsyncEntry)(1); }).toThrow(); expect((0, _asyncReductions.delAsyncEntry)('foo')(asyncState)).toEqual({}); expect((0, _recompose.compose)((0, _asyncReductions.delAsyncEntry)('foo'))(asyncState)).toEqual({}); }); test('clearAsync', function () { var asyncState = { foo: 'foo', bar: 'bar' }; expect((0, _asyncReductions.clearAsync)()).toEqual({}); expect((0, _asyncReductions.clearAsync)('foo')(asyncState)).toEqual({ foo: 'foo' }); expect((0, _recompose.compose)((0, _asyncReductions.clearAsync)('foo'))(asyncState)).toEqual({ foo: 'foo' }); });