UNPKG

react-redux-fetch

Version:

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

98 lines (79 loc) 2.59 kB
'use strict'; var _chai = require('chai'); var _chai2 = _interopRequireDefault(_chai); var _Definition = require('./Definition'); var _Definition2 = _interopRequireDefault(_Definition); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } _chai2.default.should(); describe('Definition', function () { describe('constructor()', function () { it('should store the passed arguments', function () { var args = { foo: { bar: 'foobar' } }; var def = new _Definition2.default(args); def.args.should.equal(args); }); it('should initialze "args" with an empty object if no arguments are passed', function () { var def = new _Definition2.default(); def.args.should.eql({}); }); }); describe('replaceArgument()', function () { var args = { foo: { bar: 'foobar' } }; var def = new _Definition2.default(args); it('should return the definition instance', function () { def.replaceArgument('foo.bar', 'barfoo').should.equal(def); }); it('should replace an argument at a given path', function () { def.args.foo.bar.should.equal('barfoo'); }); it('should add the path if the path does not exist', function () { def.replaceArgument('john.doe', 'jane').args.should.have.property('john'); def.args.john.doe.should.equal('jane'); }); }); describe('addArgument()', function () { var def = new _Definition2.default(); it('should return the definition instance', function () { def.addArgument('john', { doe: 'jane' }).should.equal(def); }); it('should add an argument at a given key', function () { def.args.should.eql({ john: { doe: 'jane' } }); }); }); describe('getArguments()', function () { it('should return the args object', function () { var args = { foo: { bar: 'foobar' } }; var def = new _Definition2.default(args); def.getArguments().should.equal(args); }); }); describe('getArgument()', function () { it('should return the arg for the key', function () { var args = { foo: { bar: 'foobar' } }; var def = new _Definition2.default(args); def.getArgument('foo').should.equal(args.foo); }); it('should throw an error if the key does not exist', function () { var def = new _Definition2.default(); (function shouldThrow() { def.getArgument('foo'); }).should.throw(Error); }); }); });