UNPKG

react-redux-fetch

Version:

A declarative and customizable way to fetch data for React components and manage that data in the Redux state

103 lines (84 loc) 3.52 kB
'use strict'; var _chai = require('chai'); var _chai2 = _interopRequireDefault(_chai); var _actions = require('./actions'); var _actions2 = _interopRequireDefault(_actions); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } _chai2.default.should(); describe('actions', function () { describe('action()', function () { var actionCreator = (0, _actions.action)('ACTION_TYPE'); var payload = { john: 'doe' }; it('should return a function', function () { actionCreator.should.be.a('function'); }); it('should return an object with a type property, when executing the actionCreator function', function () { actionCreator().should.have.a.property('type'); actionCreator().type.should.equal('ACTION_TYPE'); }); it('should return an object with the passed payload, when executing the actionCreator function', function () { actionCreator(payload).should.have.property('john').and.equal('doe'); }); }); describe('actions', function () { describe('for()', function () { var verb = 'post'; var actionCreators = _actions2.default.for(verb); it('should return an object', function () { actionCreators.should.be.an('object'); }); it('should have properties request, fulfil and reject, which are functions', function () { actionCreators.should.have.keys(['request', 'fulfill', 'reject']); actionCreators.request.should.be.a('function'); actionCreators.fulfill.should.be.a('function'); actionCreators.reject.should.be.a('function'); }); describe('request()', function () { var requestAction = actionCreators.request({ resource: { name: 'a' }, request: { url: 'www.react-redux-fetch.com' } }); it('should have properties: type, resource, request', function () { requestAction.should.be.an('object'); requestAction.should.have.keys(['type', 'resource', 'request']); requestAction.resource.should.eql({ name: 'a' }); requestAction.request.should.eql({ url: 'www.react-redux-fetch.com' }); }); }); describe('fulfill()', function () { var fulfillAction = actionCreators.fulfill({ resource: { name: 'a' }, value: 'b', request: { meta: { john: 'doe' } } }); it('should have properties: type, resource, value, request', function () { fulfillAction.should.be.an('object'); fulfillAction.should.have.keys(['type', 'resource', 'value', 'request']); fulfillAction.resource.should.eql({ name: 'a' }); fulfillAction.value.should.equal('b'); fulfillAction.request.should.eql({ meta: { john: 'doe' } }); }); }); describe('reject()', function () { var rejectAction = actionCreators.reject({ resource: { name: 'a' }, reason: 'b', request: { meta: { john: 'doe' } } }); it('should have properties: type, resource, reason, request', function () { rejectAction.should.be.an('object'); rejectAction.should.have.keys(['type', 'resource', 'reason', 'request']); rejectAction.resource.should.eql({ name: 'a' }); rejectAction.reason.should.equal('b'); rejectAction.request.should.eql({ meta: { john: 'doe' } }); }); }); }); }); });