Revert "Replace chai with expect"
This reverts commit f7e570934d
.
Fixes #30
This commit is contained in:
parent
bc81dcd852
commit
0cf608c2c4
@ -35,9 +35,9 @@
|
|||||||
"babel-eslint": "^4.0.5",
|
"babel-eslint": "^4.0.5",
|
||||||
"babel-loader": "^5.3.2",
|
"babel-loader": "^5.3.2",
|
||||||
"benchmark": "^1.0.0",
|
"benchmark": "^1.0.0",
|
||||||
|
"chai": "^3.2.0",
|
||||||
"eslint": "^0.24.1",
|
"eslint": "^0.24.1",
|
||||||
"eslint-config-airbnb": "0.0.7",
|
"eslint-config-airbnb": "0.0.7",
|
||||||
"expect": "^1.9.0",
|
|
||||||
"exports-loader": "^0.6.2",
|
"exports-loader": "^0.6.2",
|
||||||
"gulp": "^3.6.0",
|
"gulp": "^3.6.0",
|
||||||
"gulp-babel": "^5.1.0",
|
"gulp-babel": "^5.1.0",
|
||||||
|
5
test/.eslintrc
Normal file
5
test/.eslintrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"no-unused-expressions": 0
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,17 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.constant', () => {
|
describe('u.constant', () => {
|
||||||
it('returns what it is given... constantly', () => {
|
it('returns what it is given... constantly', () => {
|
||||||
const func = u.constant(4);
|
const func = u.constant(4);
|
||||||
|
|
||||||
expect(func()).toBe(4);
|
expect(func()).to.equal(4);
|
||||||
expect(func('hi')).toBe(4);
|
expect(func('hi')).to.equal(4);
|
||||||
expect(func('hi', 8)).toBe(4);
|
expect(func('hi', 8)).to.equal(4);
|
||||||
expect(func(4)).toBe(4);
|
expect(func(4)).to.equal(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.constant({})())).toBe(true);
|
expect(Object.isFrozen(u.constant({})())).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.freeze', () => {
|
describe('u.freeze', () => {
|
||||||
@ -10,29 +10,29 @@ describe('u.freeze', () => {
|
|||||||
const object = {};
|
const object = {};
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
|
|
||||||
expect(Object.isFrozen(object)).toBe(true);
|
expect(Object.isFrozen(object)).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes nested objects', () => {
|
it('freezes nested objects', () => {
|
||||||
const object = { foo: { bar: 3 } };
|
const object = { foo: { bar: 3 } };
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
|
|
||||||
expect(Object.isFrozen(object.foo)).toBe(true);
|
expect(Object.isFrozen(object.foo)).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes nested arrays', () => {
|
it('freezes nested arrays', () => {
|
||||||
const object = [[0]];
|
const object = [[0]];
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
|
|
||||||
expect(Object.isFrozen(object)).toBe(true);
|
expect(Object.isFrozen(object)).to.be.true;
|
||||||
expect(Object.isFrozen(object[0])).toBe(true);
|
expect(Object.isFrozen(object[0])).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores functions', () => {
|
it('ignores functions', () => {
|
||||||
const object = { foo: () => 1 };
|
const object = { foo: () => 1 };
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
|
|
||||||
expect(Object.isFrozen(object.foo)).toBe(false);
|
expect(Object.isFrozen(object.foo)).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not freeze children if the parent is already frozen', () => {
|
it('does not freeze children if the parent is already frozen', () => {
|
||||||
@ -40,7 +40,7 @@ describe('u.freeze', () => {
|
|||||||
Object.freeze(object);
|
Object.freeze(object);
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
|
|
||||||
expect(Object.isFrozen(object.foo)).toBe(false);
|
expect(Object.isFrozen(object.foo)).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not freeze in production', () => {
|
it('does not freeze in production', () => {
|
||||||
@ -48,18 +48,18 @@ describe('u.freeze', () => {
|
|||||||
const object = {};
|
const object = {};
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
|
|
||||||
expect(Object.isFrozen(object)).toBe(false);
|
expect(Object.isFrozen(object)).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles null objects', () => {
|
it('handles null objects', () => {
|
||||||
const object = { foo: null };
|
const object = { foo: null };
|
||||||
u.freeze(object);
|
u.freeze(object);
|
||||||
expect(Object.isFrozen(object)).toBe(true);
|
expect(Object.isFrozen(object)).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the same object', () => {
|
it('returns the same object', () => {
|
||||||
const object = {};
|
const object = {};
|
||||||
const result = u.freeze(object);
|
const result = u.freeze(object);
|
||||||
expect(result).toBe(object);
|
expect(result).to.equal(object);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.if', () => {
|
describe('u.if', () => {
|
||||||
it('does not update if the predicate is false', () => {
|
it('does not update if the predicate is false', () => {
|
||||||
const object = { a: 0 };
|
const object = { a: 0 };
|
||||||
const result = u.if(false, { b: 1 }, object);
|
const result = u.if(false, { b: 1 }, object);
|
||||||
expect(result).toEqual(object);
|
expect(result).to.eql(object);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does update if the predicate is true', () => {
|
it('does update if the predicate is true', () => {
|
||||||
const object = { a: 0 };
|
const object = { a: 0 };
|
||||||
const result = u.if(true, { b: 1 }, object);
|
const result = u.if(true, { b: 1 }, object);
|
||||||
expect(result).toEqual({ a: 0, b: 1 });
|
expect(result).to.eql({ a: 0, b: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will use the result of a function passed as a predicate', () => {
|
it('will use the result of a function passed as a predicate', () => {
|
||||||
@ -19,7 +19,7 @@ describe('u.if', () => {
|
|||||||
const aIsThree = x => x.a === 3;
|
const aIsThree = x => x.a === 3;
|
||||||
const result = u.if(aIsThree, { b: 1 }, object);
|
const result = u.if(aIsThree, { b: 1 }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ a: 0 });
|
expect(result).to.eql({ a: 0 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be partially applied', () => {
|
it('can be partially applied', () => {
|
||||||
@ -31,11 +31,11 @@ describe('u.if', () => {
|
|||||||
a: u.if(isEven, inc),
|
a: u.if(isEven, inc),
|
||||||
}, object);
|
}, object);
|
||||||
|
|
||||||
expect(result).toEqual({ a: 3 });
|
expect(result).to.eql({ a: 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.if(true, {}, {}))).toBe(true);
|
expect(Object.isFrozen(u.if(true, {}, {}))).to.be.true;
|
||||||
expect(Object.isFrozen(u.if(false, {}, {}))).toBe(true);
|
expect(Object.isFrozen(u.if(false, {}, {}))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.ifElse', () => {
|
describe('u.ifElse', () => {
|
||||||
it('does updates with the else if the predicate is false', () => {
|
it('does updates with the else if the predicate is false', () => {
|
||||||
const object = { a: 0 };
|
const object = { a: 0 };
|
||||||
const result = u.ifElse(false, { b: 1 }, { b: 2 }, object);
|
const result = u.ifElse(false, { b: 1 }, { b: 2 }, object);
|
||||||
expect(result).toEqual({ a: 0, b: 2 });
|
expect(result).to.eql({ a: 0, b: 2 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates with the true update if the predicate is true', () => {
|
it('updates with the true update if the predicate is true', () => {
|
||||||
const object = { a: 0 };
|
const object = { a: 0 };
|
||||||
const result = u.ifElse(true, { b: 1 }, { b: 4 }, object);
|
const result = u.ifElse(true, { b: 1 }, { b: 4 }, object);
|
||||||
expect(result).toEqual({ a: 0, b: 1 });
|
expect(result).to.eql({ a: 0, b: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will use the result of a function passed as a predicate', () => {
|
it('will use the result of a function passed as a predicate', () => {
|
||||||
@ -19,7 +19,7 @@ describe('u.ifElse', () => {
|
|||||||
const aIsThree = x => x.a === 3;
|
const aIsThree = x => x.a === 3;
|
||||||
const result = u.ifElse(aIsThree, { b: 1 }, { b: 4 }, object);
|
const result = u.ifElse(aIsThree, { b: 1 }, { b: 4 }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ a: 0, b: 4 });
|
expect(result).to.eql({ a: 0, b: 4 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be partially applied', () => {
|
it('can be partially applied', () => {
|
||||||
@ -32,11 +32,11 @@ describe('u.ifElse', () => {
|
|||||||
a: u.ifElse(isEven, inc, dec),
|
a: u.ifElse(isEven, inc, dec),
|
||||||
}, object);
|
}, object);
|
||||||
|
|
||||||
expect(result).toEqual({ a: 3 });
|
expect(result).to.eql({ a: 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.ifElse(true, {}, {}, {}))).toBe(true);
|
expect(Object.isFrozen(u.ifElse(true, {}, {}, {}))).to.be.true;
|
||||||
expect(Object.isFrozen(u.ifElse(false, {}, {}, {}))).toBe(true);
|
expect(Object.isFrozen(u.ifElse(false, {}, {}, {}))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,59 +1,59 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.is', () => {
|
describe('u.is', () => {
|
||||||
it('returns true if path matches a value predicate', () => {
|
it('returns true if path matches a value predicate', () => {
|
||||||
const result = u.is('a.b', 4, { a: { b: 4 } });
|
const result = u.is('a.b', 4, { a: { b: 4 } });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns true if path matches a function predicate', () => {
|
it('returns true if path matches a function predicate', () => {
|
||||||
const isEven = x => x % 2 === 0;
|
const isEven = x => x % 2 === 0;
|
||||||
const result = u.is('a.b', isEven, { a: { b: 6 } });
|
const result = u.is('a.b', isEven, { a: { b: 6 } });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns false if path matches a value predicate', () => {
|
it('returns false if path matches a value predicate', () => {
|
||||||
const result = u.is('a.b', 4, { a: { b: 5 } });
|
const result = u.is('a.b', 4, { a: { b: 5 } });
|
||||||
expect(result).toBe(false);
|
expect(result).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns false if path matches a function predicate', () => {
|
it('returns false if path matches a function predicate', () => {
|
||||||
const isEven = x => x % 2 === 0;
|
const isEven = x => x % 2 === 0;
|
||||||
const result = u.is('a.b', isEven, { a: { b: 7 } });
|
const result = u.is('a.b', isEven, { a: { b: 7 } });
|
||||||
expect(result).toBe(false);
|
expect(result).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns false if the path does not exist', () => {
|
it('returns false if the path does not exist', () => {
|
||||||
const result = u.is('a.b.c.d', 4, { a: { b: {} } });
|
const result = u.is('a.b.c.d', 4, { a: { b: {} } });
|
||||||
expect(result).toBe(false);
|
expect(result).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can test for undefined', () => {
|
it('can test for undefined', () => {
|
||||||
const result = u.is('a.b.c', undefined, { a: { b: {} } });
|
const result = u.is('a.b.c', undefined, { a: { b: {} } });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tests the actual object if a blank path is given', () => {
|
it('tests the actual object if a blank path is given', () => {
|
||||||
const result = u.is('', 4, 4);
|
const result = u.is('', 4, 4);
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use arrays as paths', () => {
|
it('can use arrays as paths', () => {
|
||||||
const result = u.is(['a', 'b'], 4, { a: { b: 4 } });
|
const result = u.is(['a', 'b'], 4, { a: { b: 4 } });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can include array indexes in paths', () => {
|
it('can include array indexes in paths', () => {
|
||||||
let result = u.is('a.1.b', 4, { a: [{}, { b: 4 }] });
|
let result = u.is('a.1.b', 4, { a: [{}, { b: 4 }] });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
|
|
||||||
result = u.is(['a', 1, 'b'], 4, { a: [{}, { b: 4 }] });
|
result = u.is(['a', 1, 'b'], 4, { a: [{}, { b: 4 }] });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be partially applied', () => {
|
it('can be partially applied', () => {
|
||||||
const result = u.is('a.b')(4)({ a: { b: 4 } });
|
const result = u.is('a.b')(4)({ a: { b: 4 } });
|
||||||
expect(result).toBe(true);
|
expect(result).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.map', () => {
|
describe('u.map', () => {
|
||||||
@ -7,7 +7,7 @@ describe('u.map', () => {
|
|||||||
const inc = x => x + 1;
|
const inc = x => x + 1;
|
||||||
const result = u.map(inc, object);
|
const result = u.map(inc, object);
|
||||||
|
|
||||||
expect(result).toEqual([1, 2, 3]);
|
expect(result).to.eql([1, 2, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies updates to each value in an object', () => {
|
it('applies updates to each value in an object', () => {
|
||||||
@ -15,14 +15,14 @@ describe('u.map', () => {
|
|||||||
const inc = x => x + 1;
|
const inc = x => x + 1;
|
||||||
const result = u.map(inc, object);
|
const result = u.map(inc, object);
|
||||||
|
|
||||||
expect(result).toEqual({ a: 1, b: 2, c: 3 });
|
expect(result).to.eql({ a: 1, b: 2, c: 3 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update with a regular updates object', () => {
|
it('can update with a regular updates object', () => {
|
||||||
const object = [{ a: 0 }, { a: 0 }];
|
const object = [{ a: 0 }, { a: 0 }];
|
||||||
const result = u.map({ a: 1 }, object);
|
const result = u.map({ a: 1 }, object);
|
||||||
|
|
||||||
expect(result).toEqual([{ a: 1 }, { a: 1 }]);
|
expect(result).to.eql([{ a: 1 }, { a: 1 }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the same object if no updates are made', () => {
|
it('returns the same object if no updates are made', () => {
|
||||||
@ -30,12 +30,12 @@ describe('u.map', () => {
|
|||||||
const ident = x => x;
|
const ident = x => x;
|
||||||
let result = u.map(ident, array);
|
let result = u.map(ident, array);
|
||||||
|
|
||||||
expect(result).toBe(array);
|
expect(result).to.equal(array);
|
||||||
|
|
||||||
const object = { a: 0 };
|
const object = { a: 0 };
|
||||||
result = u.map(ident, object);
|
result = u.map(ident, object);
|
||||||
|
|
||||||
expect(result).toBe(object);
|
expect(result).to.equal(object);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes the key or index as the second parameter to the iteratee', () => {
|
it('passes the key or index as the second parameter to the iteratee', () => {
|
||||||
@ -46,7 +46,7 @@ describe('u.map', () => {
|
|||||||
const setToKey = (_, key) => key;
|
const setToKey = (_, key) => key;
|
||||||
const result = u.map(u.map(setToKey), object);
|
const result = u.map(u.map(setToKey), object);
|
||||||
|
|
||||||
expect(result).toEqual( {
|
expect(result).to.eql( {
|
||||||
a: { x: 'x' },
|
a: { x: 'x' },
|
||||||
b: [0, 1],
|
b: [0, 1],
|
||||||
});
|
});
|
||||||
@ -61,12 +61,12 @@ describe('u.map', () => {
|
|||||||
b: u.map(setToKey),
|
b: u.map(setToKey),
|
||||||
}, object);
|
}, object);
|
||||||
|
|
||||||
expect(result).toEqual( {
|
expect(result).to.eql( {
|
||||||
b: [0, 1],
|
b: [0, 1],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.map({}, {}))).toBe(true);
|
expect(Object.isFrozen(u.map({}, {}))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.omit', () => {
|
describe('u.omit', () => {
|
||||||
it('can omit a key', () => {
|
it('can omit a key', () => {
|
||||||
const result = u({ foo: u.omit('bar') }, { foo: { bar: 7 } });
|
const result = u({ foo: u.omit('bar') }, { foo: { bar: 7 } });
|
||||||
|
|
||||||
expect(result).toEqual({ foo: {} });
|
expect(result).to.eql({ foo: {} });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.omit('a', {}))).toBe(true);
|
expect(Object.isFrozen(u.omit('a', {}))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.reject', () => {
|
describe('u.reject', () => {
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.reject('a', []))).toBe(true);
|
expect(Object.isFrozen(u.reject('a', []))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.updateIn', () => {
|
describe('u.updateIn', () => {
|
||||||
it('can update a single path described with a string', () => {
|
it('can update a single path described with a string', () => {
|
||||||
const object = { a: { b: 0 } };
|
const object = { a: { b: 0 } };
|
||||||
const result = u.updateIn('a.b', 3, object);
|
const result = u.updateIn('a.b', 3, object);
|
||||||
expect(result).toEqual({ a: { b: 3 } });
|
expect(result).to.eql({ a: { b: 3 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update a single path described with a string with a function', () => {
|
it('can update a single path described with a string with a function', () => {
|
||||||
const inc = x => x + 1;
|
const inc = x => x + 1;
|
||||||
const object = { a: { b: 0 } };
|
const object = { a: { b: 0 } };
|
||||||
const result = u.updateIn('a.b', inc, object);
|
const result = u.updateIn('a.b', inc, object);
|
||||||
expect(result).toEqual({ a: { b: 1 } });
|
expect(result).to.eql({ a: { b: 1 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update a single path described with an array', () => {
|
it('can update a single path described with an array', () => {
|
||||||
const object = { a: { b: 0 } };
|
const object = { a: { b: 0 } };
|
||||||
const result = u.updateIn(['a', 'b'], 3, object);
|
const result = u.updateIn(['a', 'b'], 3, object);
|
||||||
expect(result).toEqual({ a: { b: 3 } });
|
expect(result).to.eql({ a: { b: 3 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update arrays', () => {
|
it('can update arrays', () => {
|
||||||
const object = { a: [0, 0, 0] };
|
const object = { a: [0, 0, 0] };
|
||||||
const result = u.updateIn('a.1', 3, object);
|
const result = u.updateIn('a.1', 3, object);
|
||||||
expect(result).toEqual({ a: [0, 3, 0] });
|
expect(result).to.eql({ a: [0, 3, 0] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be partially applied', () => {
|
it('can be partially applied', () => {
|
||||||
const object = { a: { b: 0 } };
|
const object = { a: { b: 0 } };
|
||||||
const result = u.updateIn('a.b')(3)(object);
|
const result = u.updateIn('a.b')(3)(object);
|
||||||
expect(result).toEqual({ a: { b: 3 } });
|
expect(result).to.eql({ a: { b: 3 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('replaces the object outright if the path is empty', () => {
|
it('replaces the object outright if the path is empty', () => {
|
||||||
const object = {};
|
const object = {};
|
||||||
const result = u.updateIn('', 3, object);
|
const result = u.updateIn('', 3, object);
|
||||||
expect(result).toBe(3);
|
expect(result).to.equal(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.updateIn('a', 0, {}))).toBe(true);
|
expect(Object.isFrozen(u.updateIn('a', 0, {}))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('updeep', () => {
|
describe('updeep', () => {
|
||||||
@ -6,54 +6,54 @@ describe('updeep', () => {
|
|||||||
const object = { foo: 3, bar: [7, 5] };
|
const object = { foo: 3, bar: [7, 5] };
|
||||||
const result = u({}, object);
|
const result = u({}, object);
|
||||||
|
|
||||||
expect(result).toBe(object);
|
expect(result).to.equal(object);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update with fixed values', () => {
|
it('can update with fixed values', () => {
|
||||||
const object = { foo: 3, bar: [7, 5] };
|
const object = { foo: 3, bar: [7, 5] };
|
||||||
const result = u({ foo: 4 }, object);
|
const result = u({ foo: 4 }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: 4, bar: [7, 5] });
|
expect(result).to.deep.equal({ foo: 4, bar: [7, 5] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns the same instance if an update doesn\'t make changes', () => {
|
it('returns the same instance if an update doesn\'t make changes', () => {
|
||||||
const object = { foo: 3 };
|
const object = { foo: 3 };
|
||||||
const result = u({ foo: 3 }, object);
|
const result = u({ foo: 3 }, object);
|
||||||
|
|
||||||
expect(result).toBe(object);
|
expect(result).to.equal(object);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update a nested structure', () => {
|
it('can update a nested structure', () => {
|
||||||
const object = { foo: { bar: 7, bam: 3 }, baz: 32 };
|
const object = { foo: { bar: 7, bam: 3 }, baz: 32 };
|
||||||
const result = u({ foo: { bar: 8 } }, object);
|
const result = u({ foo: { bar: 8 } }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: { bar: 8, bam: 3 }, baz: 32 });
|
expect(result).to.deep.equal({ foo: { bar: 8, bam: 3 }, baz: 32 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update arrays', () => {
|
it('can update arrays', () => {
|
||||||
const object = [1, 2, 3];
|
const object = [1, 2, 3];
|
||||||
const result = u({ 1: 7 }, object);
|
const result = u({ 1: 7 }, object);
|
||||||
|
|
||||||
expect(result).toEqual([1, 7, 3]);
|
expect(result).to.deep.equal([1, 7, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('replaces the object outright if updates are a constant', () => {
|
it('replaces the object outright if updates are a constant', () => {
|
||||||
expect(u(3, {})).toBe(3);
|
expect(u(3, {})).to.equal(3);
|
||||||
expect(u(null, {})).toBe(null);
|
expect(u(null, {})).to.be.null;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can add an element to an array', () => {
|
it('can add an element to an array', () => {
|
||||||
const object = [];
|
const object = [];
|
||||||
const result = u({ 0: 3 }, object);
|
const result = u({ 0: 3 }, object);
|
||||||
|
|
||||||
expect(result).toEqual([3]);
|
expect(result).to.eql([3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update nested arrays', () => {
|
it('can update nested arrays', () => {
|
||||||
const object = { foo: [1, 2, 3], bar: 9 };
|
const object = { foo: [1, 2, 3], bar: 9 };
|
||||||
const result = u({ foo: { 1: 7 } }, object);
|
const result = u({ foo: { 1: 7 } }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: [1, 7, 3], bar: 9 });
|
expect(result).to.deep.equal({ foo: [1, 7, 3], bar: 9 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use functions to update values', () => {
|
it('can use functions to update values', () => {
|
||||||
@ -61,7 +61,7 @@ describe('updeep', () => {
|
|||||||
const object = { foo: 3, bar: 4, baz: 7 };
|
const object = { foo: 3, bar: 4, baz: 7 };
|
||||||
const result = u({ foo: inc, bar: inc }, object);
|
const result = u({ foo: inc, bar: inc }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: 4, bar: 5, baz: 7 });
|
expect(result).to.deep.equal({ foo: 4, bar: 5, baz: 7 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be partially applied', () => {
|
it('can be partially applied', () => {
|
||||||
@ -71,44 +71,44 @@ describe('updeep', () => {
|
|||||||
|
|
||||||
const result = incFoo(object);
|
const result = incFoo(object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: 4 });
|
expect(result).to.deep.equal({ foo: 4 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('passes additional arguments on to updates if it is a function', () => {
|
it('passes additional arguments on to updates if it is a function', () => {
|
||||||
const func = (_, x) => x;
|
const func = (_, x) => x;
|
||||||
const result = u(func, 0, 4);
|
const result = u(func, 0, 4);
|
||||||
|
|
||||||
expect(result).toBe(4);
|
expect(result).to.equal(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update if the value is an array', () => {
|
it('can update if the value is an array', () => {
|
||||||
const object = {};
|
const object = {};
|
||||||
const result = u({ foo: [0, 1] }, object);
|
const result = u({ foo: [0, 1] }, object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: [0, 1] });
|
expect(result).to.deep.equal({ foo: [0, 1] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can update when original object is undefined', () => {
|
it('can update when original object is undefined', () => {
|
||||||
const result = u({ foo: [0, 1] }, undefined);
|
const result = u({ foo: [0, 1] }, undefined);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: [0, 1] });
|
expect(result).to.deep.equal({ foo: [0, 1] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can take a function as the updater', () => {
|
it('can take a function as the updater', () => {
|
||||||
const result = u(i => i + 1, 7);
|
const result = u(i => i + 1, 7);
|
||||||
|
|
||||||
expect(result).toEqual(8);
|
expect(result).to.eql(8);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deeply freezes the result', () => {
|
it('deeply freezes the result', () => {
|
||||||
const result = u({ foo: { bar: 3 } }, { foo: { bar: 0 } });
|
const result = u({ foo: { bar: 3 } }, { foo: { bar: 0 } });
|
||||||
|
|
||||||
expect(Object.isFrozen(result)).toBe(true);
|
expect(Object.isFrozen(result)).to.be.true;
|
||||||
expect(Object.isFrozen(result.foo)).toBe(true);
|
expect(Object.isFrozen(result.foo)).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('assigns null values', () => {
|
it('assigns null values', () => {
|
||||||
expect(u({isNull: null}, {})).toEqual({isNull: null});
|
expect(u({isNull: null}, {})).to.eql({isNull: null});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use a placeholder to partially apply', () => {
|
it('can use a placeholder to partially apply', () => {
|
||||||
@ -116,22 +116,22 @@ describe('updeep', () => {
|
|||||||
const updateJoe = u(u._, { name: 'Joe Merrill', age: 21 });
|
const updateJoe = u(u._, { name: 'Joe Merrill', age: 21 });
|
||||||
const result = updateJoe({ age: increment });
|
const result = updateJoe({ age: increment });
|
||||||
|
|
||||||
expect(result).toEqual({ name: 'Joe Merrill', age: 22 });
|
expect(result).to.eql({ name: 'Joe Merrill', age: 22 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('defaults to an empty object when null or undefined', () => {
|
it('defaults to an empty object when null or undefined', () => {
|
||||||
let result = u({ a: { b: 0 } }, { a: null });
|
let result = u({ a: { b: 0 } }, { a: null });
|
||||||
expect(result).toEqual({ a: { b: 0 } });
|
expect(result).to.eql({ a: { b: 0 } });
|
||||||
|
|
||||||
result = u({ a: { b: 0 } }, { a: undefined });
|
result = u({ a: { b: 0 } }, { a: undefined });
|
||||||
expect(result).toEqual({ a: { b: 0 } });
|
expect(result).to.eql({ a: { b: 0 } });
|
||||||
|
|
||||||
result = u({ a: { b: 0 } }, { });
|
result = u({ a: { b: 0 } }, { });
|
||||||
expect(result).toEqual({ a: { b: 0 } });
|
expect(result).to.eql({ a: { b: 0 } });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('preserves empty objects when empty updates are specified', () => {
|
it('preserves empty objects when empty updates are specified', () => {
|
||||||
const result = u({ a: {} }, {});
|
const result = u({ a: {} }, {});
|
||||||
expect(result).toEqual({ a: {} });
|
expect(result).to.eql({ a: {} });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,90 +1,90 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import { curry1, curry2, curry3, curry4, _ } from '../../lib/util/curry';
|
import { curry1, curry2, curry3, curry4, _ } from '../../lib/util/curry';
|
||||||
|
|
||||||
describe('curry1', () => {
|
describe('curry1', () => {
|
||||||
it('can curry one arguments', () => {
|
it('can curry one arguments', () => {
|
||||||
const addOne = curry1((x) => x + 1);
|
const addOne = curry1((x) => x + 1);
|
||||||
expect(addOne(3)).toBe(4);
|
expect(addOne(3)).to.equal(4);
|
||||||
expect(addOne()(3)).toBe(4);
|
expect(addOne()(3)).to.equal(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will take up to two extra arguments', () => {
|
it('will take up to two extra arguments', () => {
|
||||||
const curried = curry1((a, b, c) => [a, b, c]);
|
const curried = curry1((a, b, c) => [a, b, c]);
|
||||||
expect(curried(1, 2, 3, 4)).toEqual([1, 2, 3]);
|
expect(curried(1, 2, 3, 4)).to.eql([1, 2, 3]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('curry2', () => {
|
describe('curry2', () => {
|
||||||
it('can curry two arguments', () => {
|
it('can curry two arguments', () => {
|
||||||
const add = curry2((x, y) => x + y);
|
const add = curry2((x, y) => x + y);
|
||||||
expect(add(3)(4)).toBe(7);
|
expect(add(3)(4)).to.equal(7);
|
||||||
expect(add()(3)()(4)).toBe(7);
|
expect(add()(3)()(4)).to.equal(7);
|
||||||
expect(add(3, 4)).toBe(7);
|
expect(add(3, 4)).to.equal(7);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will take up to two extra arguments', () => {
|
it('will take up to two extra arguments', () => {
|
||||||
const curried = curry2((a, b, c, d) => [a, b, c, d]);
|
const curried = curry2((a, b, c, d) => [a, b, c, d]);
|
||||||
expect(curried(1, 2, 3, 4, 5)).toEqual([1, 2, 3, 4]);
|
expect(curried(1, 2, 3, 4, 5)).to.eql([1, 2, 3, 4]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use the placeholder', () => {
|
it('can use the placeholder', () => {
|
||||||
const curried = curry2((a, b, c, d) => [a, b, c, d]);
|
const curried = curry2((a, b, c, d) => [a, b, c, d]);
|
||||||
expect(curried(_, 2)(1, 3, 4)).toEqual([1, 2, 3, 4]);
|
expect(curried(_, 2)(1, 3, 4)).to.eql([1, 2, 3, 4]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('curry3', () => {
|
describe('curry3', () => {
|
||||||
it('can curry three arguments', () => {
|
it('can curry three arguments', () => {
|
||||||
const add = curry3((x, y, z) => x + y + z);
|
const add = curry3((x, y, z) => x + y + z);
|
||||||
expect(add(3, _)(4)(5)).toBe(12);
|
expect(add(3, _)(4)(5)).to.equal(12);
|
||||||
expect(add()(3)()(4, 5)).toBe(12);
|
expect(add()(3)()(4, 5)).to.equal(12);
|
||||||
expect(add(3, 4, 5)).toBe(12);
|
expect(add(3, 4, 5)).to.equal(12);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will take up to two extra arguments', () => {
|
it('will take up to two extra arguments', () => {
|
||||||
const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]);
|
const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]);
|
||||||
expect(curried(1, 2, 3, 4, 5, 6)).toEqual([1, 2, 3, 4, 5]);
|
expect(curried(1, 2, 3, 4, 5, 6)).to.eql([1, 2, 3, 4, 5]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use the placeholder', () => {
|
it('can use the placeholder', () => {
|
||||||
const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]);
|
const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]);
|
||||||
expect(curried(_, 2)('a', 3, 4, 5)).toEqual(['a', 2, 3, 4, 5]);
|
expect(curried(_, 2)('a', 3, 4, 5)).to.eql(['a', 2, 3, 4, 5]);
|
||||||
expect(curried('b', _, 3)(2, 4, 5)).toEqual(['b', 2, 3, 4, 5]);
|
expect(curried('b', _, 3)(2, 4, 5)).to.eql(['b', 2, 3, 4, 5]);
|
||||||
expect(curried(_, 2, 3)('c', 4, 5)).toEqual(['c', 2, 3, 4, 5]);
|
expect(curried(_, 2, 3)('c', 4, 5)).to.eql(['c', 2, 3, 4, 5]);
|
||||||
expect(curried(_, _, 3)('d', 2, 4, 5)).toEqual(['d', 2, 3, 4, 5]);
|
expect(curried(_, _, 3)('d', 2, 4, 5)).to.eql(['d', 2, 3, 4, 5]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('curry4', () => {
|
describe('curry4', () => {
|
||||||
it('can curry four arguments', () => {
|
it('can curry four arguments', () => {
|
||||||
const add = curry4((x, y, z, u) => x + y + z + u);
|
const add = curry4((x, y, z, u) => x + y + z + u);
|
||||||
expect(add(3, _)(4)(5)(6)).toBe(18);
|
expect(add(3, _)(4)(5)(6)).to.equal(18);
|
||||||
expect(add()(3)()(4, 5, 6)).toBe(18);
|
expect(add()(3)()(4, 5, 6)).to.equal(18);
|
||||||
expect(add(3, 4, 5, 6)).toBe(18);
|
expect(add(3, 4, 5, 6)).to.equal(18);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will take up to two extra arguments', () => {
|
it('will take up to two extra arguments', () => {
|
||||||
const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]);
|
const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]);
|
||||||
expect(curried(1, 2, 3, 4, 5, 6, 7)).toEqual([1, 2, 3, 4, 5, 6]);
|
expect(curried(1, 2, 3, 4, 5, 6, 7)).to.eql([1, 2, 3, 4, 5, 6]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can use the placeholder', () => {
|
it('can use the placeholder', () => {
|
||||||
const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]);
|
const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]);
|
||||||
expect(curried(_, 2)('a', 3, 4, 5, 6)).toEqual(['a', 2, 3, 4, 5, 6]);
|
expect(curried(_, 2)('a', 3, 4, 5, 6)).to.eql(['a', 2, 3, 4, 5, 6]);
|
||||||
expect(curried(_, 2, 3)('b', 4, 5, 6)).toEqual(['b', 2, 3, 4, 5, 6]);
|
expect(curried(_, 2, 3)('b', 4, 5, 6)).to.eql(['b', 2, 3, 4, 5, 6]);
|
||||||
expect(curried(_, 2, 3, 4)('c', 5, 6)).toEqual(['c', 2, 3, 4, 5, 6]);
|
expect(curried(_, 2, 3, 4)('c', 5, 6)).to.eql(['c', 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
expect(curried('d', _, 3)(2, 4, 5, 6)).toEqual(['d', 2, 3, 4, 5, 6]);
|
expect(curried('d', _, 3)(2, 4, 5, 6)).to.eql(['d', 2, 3, 4, 5, 6]);
|
||||||
expect(curried('e', _, 3, 4)(2, 5, 6)).toEqual(['e', 2, 3, 4, 5, 6]);
|
expect(curried('e', _, 3, 4)(2, 5, 6)).to.eql(['e', 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
expect(curried('f', 2, _, 4)(3, 5, 6)).toEqual(['f', 2, 3, 4, 5, 6]);
|
expect(curried('f', 2, _, 4)(3, 5, 6)).to.eql(['f', 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
expect(curried(_, _, 3)('g', 2, 4, 5, 6)).toEqual(['g', 2, 3, 4, 5, 6]);
|
expect(curried(_, _, 3)('g', 2, 4, 5, 6)).to.eql(['g', 2, 3, 4, 5, 6]);
|
||||||
expect(curried(_, _, 3, 4)('h', 2, 5, 6)).toEqual(['h', 2, 3, 4, 5, 6]);
|
expect(curried(_, _, 3, 4)('h', 2, 5, 6)).to.eql(['h', 2, 3, 4, 5, 6]);
|
||||||
expect(curried(_, 2, _, 4)('i', 3, 5, 6)).toEqual(['i', 2, 3, 4, 5, 6]);
|
expect(curried(_, 2, _, 4)('i', 3, 5, 6)).to.eql(['i', 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
expect(curried('j', _, _, 4)(2, 3, 5, 6)).toEqual(['j', 2, 3, 4, 5, 6]);
|
expect(curried('j', _, _, 4)(2, 3, 5, 6)).to.eql(['j', 2, 3, 4, 5, 6]);
|
||||||
|
|
||||||
expect(curried(_, _, _, 4)('k', 2, 3, 5, 6)).toEqual(['k', 2, 3, 4, 5, 6]);
|
expect(curried(_, _, _, 4)('k', 2, 3, 5, 6)).to.eql(['k', 2, 3, 4, 5, 6]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import expect from 'expect';
|
import { expect } from 'chai';
|
||||||
import u from '../lib';
|
import u from '../lib';
|
||||||
|
|
||||||
describe('u.withDefault', () => {
|
describe('u.withDefault', () => {
|
||||||
@ -6,14 +6,14 @@ describe('u.withDefault', () => {
|
|||||||
const inc = x => x + 1;
|
const inc = x => x + 1;
|
||||||
const result = u.withDefault({ a: 0 }, { a: inc }, undefined);
|
const result = u.withDefault({ a: 0 }, { a: inc }, undefined);
|
||||||
|
|
||||||
expect(result).toEqual({ a: 1 });
|
expect(result).to.eql({ a: 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses ignores the default if the object is defined', () => {
|
it('uses ignores the default if the object is defined', () => {
|
||||||
const inc = x => x + 1;
|
const inc = x => x + 1;
|
||||||
const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 });
|
const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 });
|
||||||
|
|
||||||
expect(result).toEqual({ a: 4 });
|
expect(result).to.eql({ a: 4 });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be partially applied', () => {
|
it('can be partially applied', () => {
|
||||||
@ -22,10 +22,10 @@ describe('u.withDefault', () => {
|
|||||||
foo: u.withDefault([], { 0: 'bar' }),
|
foo: u.withDefault([], { 0: 'bar' }),
|
||||||
}, object);
|
}, object);
|
||||||
|
|
||||||
expect(result).toEqual({ foo: ['bar'] });
|
expect(result).to.eql({ foo: ['bar'] });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('freezes the result', () => {
|
it('freezes the result', () => {
|
||||||
expect(Object.isFrozen(u.withDefault({}, { a: 1 })(undefined))).toBe(true);
|
expect(Object.isFrozen(u.withDefault({}, { a: 1 })(undefined))).to.be.true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user