chai-immutable
Advanced tools
Comparing version 1.5.0 to 1.5.1
@@ -244,3 +244,5 @@ 'use strict'; | ||
ok = keys.every(has); | ||
if (!contains) ok = ok && keys.length === obj.count(); | ||
if (!contains && !utils.flag(this, 'negate')) { | ||
ok = ok && keys.length === obj.count(); | ||
} | ||
} | ||
@@ -450,4 +452,4 @@ | ||
* | ||
* Asserts that the values of the target are equvalent to the values of | ||
* `collection`. Note that `.strictEqual()` and `.deepEqual()` assert | ||
* Asserts that the values of `actual` are equivalent to the values of | ||
* `expected`. Note that `.strictEqual()` and `.deepEqual()` assert | ||
* exactly like `.equal()` in the context of Immutable data structures. | ||
@@ -486,4 +488,4 @@ * | ||
* | ||
* Asserts that the values of the target are not equvalent to the values of | ||
* `collection`. Note that `.notStrictEqual()` and `.notDeepEqual()` assert | ||
* Asserts that the values of `actual` are not equivalent to the values of | ||
* `expected`. Note that `.notStrictEqual()` and `.notDeepEqual()` assert | ||
* exactly like `.notEqual()` in the context of Immutable data structures. | ||
@@ -490,0 +492,0 @@ * |
{ | ||
"name": "chai-immutable", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Chai assertions for Facebook's Immutable library for JavaScript collections", | ||
@@ -5,0 +5,0 @@ "main": "chai-immutable.js", |
@@ -158,4 +158,4 @@ [![npm Version](https://img.shields.io/npm/v/chai-immutable.svg)](https://npmjs.org/package/chai-immutable) | ||
Asserts that the values of the target are equvalent to the values of | ||
`collection`. Note that `.strictEqual()` and `.deepEqual()` assert | ||
Asserts that the values of `actual` are equivalent to the values of | ||
`expected`. Note that `.strictEqual()` and `.deepEqual()` assert | ||
exactly like `.equal()` in the context of Immutable data structures. | ||
@@ -180,4 +180,4 @@ | ||
Asserts that the values of the target are not equvalent to the values of | ||
`collection`. Note that `.notStrictEqual()` and `.notDeepEqual()` assert | ||
Asserts that the values of `actual` are not equivalent to the values of | ||
`expected`. Note that `.notStrictEqual()` and `.notDeepEqual()` assert | ||
exactly like `.notEqual()` in the context of Immutable data structures. | ||
@@ -184,0 +184,0 @@ |
371
test/test.js
@@ -21,4 +21,13 @@ 'use strict'; | ||
/*! | ||
* Test helper to check that a given function (wrapping the assertion) will | ||
* fail. | ||
*/ | ||
function fail(fn) { | ||
expect(fn).to.throw(chai.AssertionError); | ||
} | ||
describe('chai-immutable (' + typeEnv + ')', function () { | ||
var list3 = List.of(1, 2, 3); | ||
var deepMap = new Map({ | ||
@@ -29,9 +38,19 @@ foo: 'bar', | ||
var sameDeepMap = new Map({ | ||
foo: 'bar', | ||
list: List.of(1, 2, 3) | ||
}); | ||
var differentDeepMap = new Map({ | ||
foo: 'bar', | ||
list: List.of(42) | ||
}); | ||
describe('BDD interface', function () { | ||
describe('empty property', function () { | ||
it('should be true when given an empty collection', function () { | ||
it('should pass given an empty collection', function () { | ||
expect(new List()).to.be.empty; | ||
}); | ||
it('should be false when given a non-empty collection', function () { | ||
it('should pass using `not` given a non-empty collection', function () { | ||
expect(list3).to.not.be.empty; | ||
@@ -45,18 +64,18 @@ }); | ||
}); | ||
it('should fail given a non-empty collection', function () { | ||
fail(function () { expect(list3).to.be.empty; }); | ||
}); | ||
it('should fail using `not` given an empty collection', function () { | ||
fail(function () { expect(new List()).to.not.be.empty; }); | ||
}); | ||
}); | ||
describe('equal method', function () { | ||
it( | ||
'should fail when only the "expected" value is an Immutable collection', | ||
function () { | ||
var fn = function () { expect([]).to.equal(List()); }; | ||
expect(fn).to.throw(Error); | ||
} | ||
); | ||
it('should be true when compared structure is equal', function () { | ||
it('should pass given equal values', function () { | ||
expect(list3).to.equal(List.of(1, 2, 3)); | ||
}); | ||
it('should be false when compared structure not equal', function () { | ||
it('should pass using `not` given different values', function () { | ||
expect(list3).to.not.equal(new List()); | ||
@@ -86,8 +105,3 @@ }); | ||
it('should work on deep structures that are equal', function () { | ||
var sameDeepMap = new Map({ | ||
foo: 'bar', | ||
list: List.of(1, 2, 3) | ||
}); | ||
it('should pass given deeply equal values', function () { | ||
expect(deepMap).to.equal(sameDeepMap); | ||
@@ -100,8 +114,3 @@ expect(deepMap).to.equals(sameDeepMap); | ||
it('should work on deep structures that are not equal', function () { | ||
var differentDeepMap = new Map({ | ||
foo: 'bar', | ||
list: List.of(42) | ||
}); | ||
it('should pass using `not` given deeply different values', function () { | ||
expect(deepMap).to.not.equal(differentDeepMap); | ||
@@ -113,14 +122,46 @@ expect(deepMap).to.not.equals(differentDeepMap); | ||
}); | ||
it('should pass using `not` given a non-Immutable value', function () { | ||
expect([]).to.not.equal(List()); | ||
}); | ||
it('should fail given a non-Immutable value', function () { | ||
fail(function () { expect([]).to.equal(List()); }); | ||
}); | ||
it('should fail given different values', function () { | ||
fail(function () { expect(list3).to.equal(new List()); }); | ||
}); | ||
it('should fail using `not` given equal values', function () { | ||
fail(function () { expect(list3).to.not.equal(List.of(1, 2, 3)); }); | ||
}); | ||
it('should fail given deeply different values', function () { | ||
fail(function () { expect(deepMap).to.equal(differentDeepMap); }); | ||
fail(function () { expect(deepMap).to.equals(differentDeepMap); }); | ||
fail(function () { expect(deepMap).to.eq(differentDeepMap); }); | ||
fail(function () { expect(deepMap).to.eql(differentDeepMap); }); | ||
fail(function () { expect(deepMap).to.deep.equal(differentDeepMap); }); | ||
}); | ||
it('should fail using `not` given deeply equal values', function () { | ||
fail(function () { expect(deepMap).to.not.equal(sameDeepMap); }); | ||
fail(function () { expect(deepMap).to.not.equals(sameDeepMap); }); | ||
fail(function () { expect(deepMap).to.not.eq(sameDeepMap); }); | ||
fail(function () { expect(deepMap).to.not.eql(sameDeepMap); }); | ||
fail(function () { expect(deepMap).to.not.deep.equal(sameDeepMap); }); | ||
}); | ||
}); | ||
describe('include method', function () { | ||
it('should be true with an existing value', function () { | ||
it('should pass given an existing value', function () { | ||
expect(new List([1, 2, 3])).to.include(2); | ||
}); | ||
it('should be false with an inexisting value', function () { | ||
it('should pass using `not` given an inexisting value', function () { | ||
expect(new List([1, 2, 3])).to.not.include(42); | ||
}); | ||
it('should chain and be true with existing keys', function () { | ||
it('should chain and pass given an existing key', function () { | ||
expect(new Map({ | ||
@@ -132,3 +173,3 @@ foo: 'bar', | ||
it('should chain and be false with inexisting keys', function () { | ||
it('should chain and pass using `not` given an inexisting key', function () { | ||
expect(new Map({ | ||
@@ -154,2 +195,28 @@ foo: 'bar', | ||
}); | ||
it('should fail given an inexisting value', function () { | ||
fail(function () { expect(new List([1, 2, 3])).to.include(42); }); | ||
}); | ||
it('should fail using `not` given an existing value', function () { | ||
fail(function () { expect(new List([1, 2, 3])).not.to.include(2); }); | ||
}); | ||
it('should chain and fail given an inexisting key', function () { | ||
fail(function () { | ||
expect(new Map({ | ||
foo: 'bar', | ||
hello: 'universe' | ||
})).to.include.keys('not-foo'); | ||
}); | ||
}); | ||
it('should chain and fail using `not` given an existing key', function () { | ||
fail(function () { | ||
expect(new Map({ | ||
foo: 'bar', | ||
hello: 'universe' | ||
})).to.not.include.keys('foo'); | ||
}); | ||
}); | ||
}); | ||
@@ -161,3 +228,3 @@ | ||
it('should be true when given an existing key', function () { | ||
it('should pass given an existing key', function () { | ||
expect(new Map({ x: 1 })).to.have.key('x'); | ||
@@ -167,3 +234,3 @@ expect({ x: 1 }).to.have.key('x'); | ||
it('should be false when given a non existing key', function () { | ||
it('should pass using `not` given an inexisting key', function () { | ||
expect(map).to.not.have.key('z'); | ||
@@ -173,3 +240,3 @@ expect(obj).to.not.have.key('z'); | ||
it('should be true when given multiple existing keys', function () { | ||
it('should pass given multiple existing keys', function () { | ||
expect(map).to.have.keys('x', 'y'); | ||
@@ -179,3 +246,3 @@ expect(obj).to.have.keys('x', 'y'); | ||
it('should be false when given multiple non existing keys', function () { | ||
it('should pass using `not` given multiple inexisting keys', function () { | ||
expect(map).to.not.have.keys('z1', 'z2'); | ||
@@ -190,11 +257,11 @@ expect(obj).to.not.have.keys('z1', 'z2'); | ||
it('should accept an List of keys to check against', function () { | ||
it('should accept a List of keys to check against', function () { | ||
expect(map).to.have.keys(new List(['x', 'y'])); | ||
}); | ||
it('should accept an Set of keys to check against', function () { | ||
it('should accept a Set of keys to check against', function () { | ||
expect(map).to.have.keys(new Set(['x', 'y'])); | ||
}); | ||
it('should accept an Stack of keys to check against', function () { | ||
it('should accept a Stack of keys to check against', function () { | ||
expect(map).to.have.keys(new Stack(['x', 'y'])); | ||
@@ -212,3 +279,3 @@ }); | ||
it('should be true when used with any and an existing key', function () { | ||
it('should pass using `any` given an existing key', function () { | ||
expect(map).to.have.any.keys('x', 'z'); | ||
@@ -218,3 +285,3 @@ expect(obj).to.have.any.keys('x', 'z'); | ||
it('should be false when used with any and inexisting keys', function () { | ||
it('should pass using `not` and `any` given inexisting keys', function () { | ||
expect(map).to.not.have.any.keys('z1', 'z2'); | ||
@@ -224,3 +291,3 @@ expect(obj).to.not.have.any.keys('z1', 'z2'); | ||
it('should be true when used with all and existing keys', function () { | ||
it('should pass using `all` given existing keys', function () { | ||
expect(map).to.have.all.keys('x', 'y'); | ||
@@ -230,3 +297,3 @@ expect(obj).to.have.all.keys('x', 'y'); | ||
it('should be false when used with all and inexisting keys', function () { | ||
it('should pass using `not` and `all` given inexisting keys', function () { | ||
expect(map).to.not.have.all.keys('z1', 'y'); | ||
@@ -236,3 +303,3 @@ expect(obj).to.not.have.all.keys('z1', 'y'); | ||
it('should be true when used with contain and an existing key', function () { | ||
it('should pass using `contain` given an existing key', function () { | ||
expect(map).to.contain.key('x'); | ||
@@ -253,10 +320,55 @@ expect(obj).to.contain.key('x'); | ||
}); | ||
it('should fail given an inexisting key', function () { | ||
fail(function () { expect(new Map({ x: 1 })).to.have.key('z'); }); | ||
fail(function () { expect({ x: 1 }).to.have.key('z'); }); | ||
}); | ||
it('should fail using `not` given an inexisting key', function () { | ||
fail(function () { expect(map).to.not.have.key('x'); }); | ||
fail(function () { expect(obj).to.not.have.key('x'); }); | ||
}); | ||
it('should fail given multiple inexisting keys', function () { | ||
fail(function () { expect(map).to.have.keys('z1', 'z2'); }); | ||
fail(function () { expect(obj).to.have.keys('z1', 'z2'); }); | ||
}); | ||
it('should fail using `not` given multiple existing keys', function () { | ||
fail(function () { expect(map).to.not.have.keys('x', 'y'); }); | ||
fail(function () { expect(obj).to.not.have.keys('x', 'y'); }); | ||
}); | ||
it('should fail using `any` given inexisting keys', function () { | ||
fail(function () { expect(map).to.have.any.keys('z1', 'z2'); }); | ||
fail(function () { expect(obj).to.have.any.keys('z1', 'z2'); }); | ||
}); | ||
it('should fail using `not` and `any` given an existing key', function () { | ||
fail(function () { expect(map).to.not.have.any.keys('x', 'z'); }); | ||
fail(function () { expect(obj).to.not.have.any.keys('x', 'z'); }); | ||
}); | ||
it('should fail using `all` given an inexisting key', function () { | ||
fail(function () { expect(map).to.have.all.keys('z1', 'y'); }); | ||
fail(function () { expect(obj).to.have.all.keys('z1', 'y'); }); | ||
}); | ||
it('should fail using `not` and `all` given existing keys', function () { | ||
fail(function () { expect(map).to.not.have.all.keys('x', 'y'); }); | ||
fail(function () { expect(obj).to.not.have.all.keys('x', 'y'); }); | ||
}); | ||
it('should fail using `contain` given an inexisting key', function () { | ||
fail(function () { expect(map).to.contain.key('z'); }); | ||
fail(function () { expect(obj).to.contain.key('z'); }); | ||
}); | ||
}); | ||
describe('size method', function () { | ||
it('should be true when given the right size', function () { | ||
it('should pass given the right size', function () { | ||
expect(list3).to.have.size(3); | ||
}); | ||
it('should be false when given the wrong size', function () { | ||
it('should pass using `not` given the wrong size', function () { | ||
expect(list3).to.not.have.size(42); | ||
@@ -269,10 +381,18 @@ }); | ||
}); | ||
it('should fail given the wrong size', function () { | ||
fail(function () { expect(list3).to.have.size(42); }); | ||
}); | ||
it('should fail using `not` given the right size', function () { | ||
fail(function () { expect(list3).to.not.have.size(3); }); | ||
}); | ||
}); | ||
describe('size property', function () { | ||
it('above should be true when given a good min size', function () { | ||
it('above should pass given a good min size', function () { | ||
expect(list3).to.have.size.above(2); | ||
}); | ||
it('above should be false when given a bad min size', function () { | ||
it('above should pass using `not` given a bad min size', function () { | ||
expect(list3).to.not.have.size.above(42); | ||
@@ -293,7 +413,15 @@ }); | ||
it('below should be true when given a good max size', function () { | ||
it('above should fail given a bad min size', function () { | ||
fail(function () { expect(list3).to.have.size.above(42); }); | ||
}); | ||
it('above should fail using `not` given a good min size', function () { | ||
fail(function () { expect(list3).to.not.have.size.above(2); }); | ||
}); | ||
it('below should pass given a good max size', function () { | ||
expect(list3).to.have.size.below(42); | ||
}); | ||
it('below should be false when given a bad max size', function () { | ||
it('below should pass using `not` given a bad max size', function () { | ||
expect(list3).to.not.have.size.below(1); | ||
@@ -314,7 +442,15 @@ }); | ||
it('within should be true when given a good range', function () { | ||
it('below should fail given a bad max size', function () { | ||
fail(function () { expect(list3).to.have.size.below(1); }); | ||
}); | ||
it('below should fail using `not` given a good max size', function () { | ||
fail(function () { expect(list3).to.not.have.size.below(42); }); | ||
}); | ||
it('within should pass given a good range', function () { | ||
expect(list3).to.have.size.within(2, 42); | ||
}); | ||
it('within should be false when given a bad range', function () { | ||
it('within should pass using `not` given a bad range', function () { | ||
expect(list3).to.not.have.size.within(10, 20); | ||
@@ -328,7 +464,15 @@ }); | ||
it('least should be true when given a good min size', function () { | ||
it('within should fail given a bad range', function () { | ||
fail(function () { expect(list3).to.have.size.within(10, 20); }); | ||
}); | ||
it('within should fail using `not` given a good range', function () { | ||
fail(function () { expect(list3).to.not.have.size.within(2, 42); }); | ||
}); | ||
it('least should pass given a good min size', function () { | ||
expect(list3).to.have.size.of.at.least(2); | ||
}); | ||
it('least should be false when given a bad min size', function () { | ||
it('least should pass using `not` given a bad min size', function () { | ||
expect(list3).to.not.have.size.of.at.least(42); | ||
@@ -347,7 +491,15 @@ }); | ||
it('most should be true when given a good max size', function () { | ||
it('least should fail given a bad min size', function () { | ||
fail(function () { expect(list3).to.have.size.of.at.least(42); }); | ||
}); | ||
it('least should fail using `not` given a good min size', function () { | ||
fail(function () { expect(list3).to.not.have.size.of.at.least(2); }); | ||
}); | ||
it('most should pass given a good max size', function () { | ||
expect(list3).to.have.size.of.at.most(42); | ||
}); | ||
it('most should be false when given a bad max size', function () { | ||
it('most should pass using `not` given a bad max size', function () { | ||
expect(list3).to.not.have.size.of.at.most(2); | ||
@@ -365,2 +517,10 @@ }); | ||
}); | ||
it('most should fail given a good max size', function () { | ||
fail(function () { expect(list3).to.have.size.of.at.most(2); }); | ||
}); | ||
it('most should fail using `not` given a bad max size', function () { | ||
fail(function () { expect(list3).to.not.have.size.of.at.most(42); }); | ||
}); | ||
}); | ||
@@ -371,16 +531,8 @@ }); | ||
describe('equal assertion', function () { | ||
it( | ||
'should fail when only the "expected" value is an Immutable collection', | ||
function () { | ||
var fn = function () { assert.equal([], List()); }; | ||
assert.throw(fn); | ||
} | ||
); | ||
it('should be true when compared structure is equal', function () { | ||
it('should pass given equal values', function () { | ||
assert.equal(list3, List.of(1, 2, 3)); | ||
}); | ||
it('should be false when compared structure not equal', function () { | ||
assert.notEqual(list3, new List()); | ||
it('should pass given deeply equal values', function () { | ||
assert.equal(deepMap, sameDeepMap); | ||
}); | ||
@@ -391,9 +543,46 @@ | ||
assert.equal(3, '3'); | ||
}); | ||
it('should fail given a non-Immutable value', function () { | ||
fail(function () { assert.equal([], List()); }); | ||
}); | ||
it('should fail given different values', function () { | ||
fail(function () { assert.equal(list3, new List()); }); | ||
}); | ||
it('should fail given deeply different values', function () { | ||
fail(function () { assert.equal(deepMap, differentDeepMap); }); | ||
}); | ||
}); | ||
describe('notEqual assertion', function () { | ||
it('should pass given different values', function () { | ||
assert.notEqual(list3, new List()); | ||
}); | ||
it('should pass given deeply different values', function () { | ||
assert.notEqual(deepMap, differentDeepMap); | ||
}); | ||
it('should not affect the original assertion', function () { | ||
assert.notEqual('oui', 'non'); | ||
assert.notEqual({ foo: 'bar' }, { foo: 'bar' }); | ||
}); | ||
it('should pass given a non-Immutable value', function () { | ||
assert.notEqual([], List()); | ||
}); | ||
it('should fail given equal values', function () { | ||
fail(function () { assert.notEqual(list3, List.of(1, 2, 3)); }); | ||
}); | ||
it('should fail given deeply equal values', function () { | ||
fail(function () { assert.notEqual(deepMap, sameDeepMap); }); | ||
}); | ||
}); | ||
describe('unoverridden strictEqual and deepEqual assertions', function () { | ||
it('should be true when compared structure is equal', function () { | ||
it('should pass given equal values', function () { | ||
assert.strictEqual(list3, List.of(1, 2, 3)); | ||
@@ -403,33 +592,43 @@ assert.deepEqual(list3, List.of(1, 2, 3)); | ||
it('should be false when compared structure not equal', function () { | ||
it('should pass given deeply equal values', function () { | ||
assert.strictEqual(deepMap, sameDeepMap); | ||
assert.deepEqual(deepMap, sameDeepMap); | ||
}); | ||
it('should fail given different values', function () { | ||
fail(function () { assert.strictEqual(list3, new List()); }); | ||
fail(function () { assert.deepEqual(list3, new List()); }); | ||
}); | ||
it('should fail given deeply different values', function () { | ||
fail(function () { assert.strictEqual(deepMap, differentDeepMap); }); | ||
fail(function () { assert.deepEqual(deepMap, differentDeepMap); }); | ||
}); | ||
}); | ||
describe('unoverridden notStrictEqual and notDeepEqual assertions', function () { | ||
it('should pass given different values', function () { | ||
assert.notStrictEqual(list3, new List()); | ||
assert.notDeepEqual(list3, new List()); | ||
}); | ||
}); | ||
it('should work on deep structures that are equal', function () { | ||
var sameDeepMap = new Map({ | ||
foo: 'bar', | ||
list: List.of(1, 2, 3) | ||
it('should pass given deeply different values', function () { | ||
assert.notStrictEqual(deepMap, differentDeepMap); | ||
assert.notDeepEqual(deepMap, differentDeepMap); | ||
}); | ||
assert.equal(deepMap, sameDeepMap); | ||
assert.strictEqual(deepMap, sameDeepMap); | ||
assert.deepEqual(deepMap, sameDeepMap); | ||
}); | ||
it('should fail given equal values', function () { | ||
fail(function () { assert.notStrictEqual(list3, List.of(1, 2, 3)); }); | ||
fail(function () { assert.notDeepEqual(list3, List.of(1, 2, 3)); }); | ||
}); | ||
it('should work on deep structures that are not equal', function () { | ||
var differentDeepMap = new Map({ | ||
foo: 'bar', | ||
list: List.of(42) | ||
it('should fail given deeply equal values', function () { | ||
fail(function () { assert.notStrictEqual(deepMap, sameDeepMap); }); | ||
fail(function () { assert.notDeepEqual(deepMap, sameDeepMap); }); | ||
}); | ||
assert.notEqual(deepMap, differentDeepMap); | ||
assert.notStrictEqual(deepMap, differentDeepMap); | ||
assert.notDeepEqual(deepMap, differentDeepMap); | ||
}); | ||
describe('sizeOf assertion', function () { | ||
it('should be true when given the right size', function () { | ||
assert.sizeOf(List.of(1, 2, 3), 3); | ||
it('should pass given the right size', function () { | ||
assert.sizeOf(list3, 3); | ||
}); | ||
@@ -440,4 +639,8 @@ | ||
}); | ||
it('should fail given the wrong size', function () { | ||
fail(function () { assert.sizeOf(list3, 42); }); | ||
}); | ||
}); | ||
}); | ||
}); |
52872
1035