chai-immutable
Advanced tools
Comparing version 1.6.0 to 2.0.0-alpha.1
@@ -228,3 +228,3 @@ 'use strict'; | ||
switch (utils.type(keys)) { | ||
case 'object': | ||
case 'Object': | ||
if (Immutable.Iterable.isIndexed(keys)) | ||
@@ -235,3 +235,3 @@ keys = keys.toJS(); | ||
else keys = Object.keys(keys); | ||
case 'array': | ||
case 'Array': | ||
if (arguments.length > 1) throw new Error( | ||
@@ -258,3 +258,3 @@ 'keys must be given single argument of ' + | ||
ok = keys.every(has); | ||
if (!contains && !utils.flag(this, 'negate')) { | ||
if (!contains) { | ||
ok = ok && keys.length === obj.count(); | ||
@@ -337,4 +337,4 @@ } | ||
* Immutable object. | ||
* If the `deep` flag is set, you can use dot- and bracket-notation for deep | ||
* references into objects and arrays. | ||
* If the `nested` flag is set, you can use dot- and bracket-notation for | ||
* nested references into objects and arrays. | ||
* | ||
@@ -348,3 +348,3 @@ * ```js | ||
* // Deep referencing | ||
* var deepMap = new Map({ | ||
* var nestedMap = new Map({ | ||
* green: new Map({ tea: 'matcha' }), | ||
@@ -354,14 +354,14 @@ * teas: new List(['chai', 'matcha', new Map({ tea: 'konacha' })]) | ||
* | ||
* expect(deepMap).to.have.deep.property('green.tea', 'matcha'); | ||
* expect(deepMap).to.have.deep.property(['green', 'tea'], 'matcha'); | ||
* expect(deepMap).to.have.deep.property(new List(['green', 'tea']), 'matcha'); | ||
* expect(deepMap).to.have.deep.property('teas[1]', 'matcha'); | ||
* expect(deepMap).to.have.deep.property(['teas', 1], 'matcha'); | ||
* expect(deepMap).to.have.deep.property(new List(['teas', 1]), 'matcha'); | ||
* expect(deepMap).to.have.deep.property('teas[2].tea', 'konacha'); | ||
* expect(deepMap).to.have.deep.property(['teas', 2, 'tea'], 'konacha'); | ||
* expect(deepMap).to.have.deep.property(new List(['teas', 2, 'tea']), 'konacha'); | ||
* expect(nestedMap).to.have.nested.property('green.tea', 'matcha'); | ||
* expect(nestedMap).to.have.nested.property(['green', 'tea'], 'matcha'); | ||
* expect(nestedMap).to.have.nested.property(new List(['green', 'tea']), 'matcha'); | ||
* expect(nestedMap).to.have.nested.property('teas[1]', 'matcha'); | ||
* expect(nestedMap).to.have.nested.property(['teas', 1], 'matcha'); | ||
* expect(nestedMap).to.have.nested.property(new List(['teas', 1]), 'matcha'); | ||
* expect(nestedMap).to.have.nested.property('teas[2].tea', 'konacha'); | ||
* expect(nestedMap).to.have.nested.property(['teas', 2, 'tea'], 'konacha'); | ||
* expect(nestedMap).to.have.nested.property(new List(['teas', 2, 'tea']), 'konacha'); | ||
* ``` | ||
* | ||
* You can also use a `List` as the starting point of a `deep.property` | ||
* You can also use a `List` as the starting point of a `nested.property` | ||
* assertion, or traverse nested `List`s. | ||
@@ -379,8 +379,8 @@ * | ||
* | ||
* expect(list).to.have.deep.property('[0][1]', 'matcha'); | ||
* expect(list).to.have.deep.property([0, 1], 'matcha'); | ||
* expect(list).to.have.deep.property(new List([0, 1]), 'matcha'); | ||
* expect(list).to.have.deep.property('[1][2].tea', 'konacha'); | ||
* expect(list).to.have.deep.property([1, 2, 'tea'], 'konacha'); | ||
* expect(list).to.have.deep.property(new List([1, 2, 'tea']), 'konacha'); | ||
* expect(list).to.have.nested.property('[0][1]', 'matcha'); | ||
* expect(list).to.have.nested.property([0, 1], 'matcha'); | ||
* expect(list).to.have.nested.property(new List([0, 1]), 'matcha'); | ||
* expect(list).to.have.nested.property('[1][2].tea', 'konacha'); | ||
* expect(list).to.have.nested.property([1, 2, 'tea'], 'konacha'); | ||
* expect(list).to.have.nested.property(new List([1, 2, 'tea']), 'konacha'); | ||
* ``` | ||
@@ -395,8 +395,8 @@ * | ||
* .that.is.a('string'); | ||
* expect(deepMap).to.have.property('green') | ||
* expect(nestedMap).to.have.property('green') | ||
* .that.is.an.instanceof(Map) | ||
* .that.equals(new Map({ tea: 'matcha' })); | ||
* expect(deepMap).to.have.property('teas') | ||
* expect(nestedMap).to.have.property('teas') | ||
* .that.is.an.instanceof(List) | ||
* .with.deep.property([2]) | ||
* .with.nested.property([2]) | ||
* .that.equals(new Map({ tea: 'konacha' })); | ||
@@ -406,4 +406,4 @@ * ``` | ||
* Note that dots and brackets in `name` must be backslash-escaped when | ||
* the `deep` flag is set, while they must NOT be escaped when the `deep` | ||
* flag is not set. | ||
* the `nested` flag is set, while they must NOT be escaped when the | ||
* `nested` flag is not set. | ||
* | ||
@@ -416,4 +416,4 @@ * ```js | ||
* // Deep referencing | ||
* var deepCss = new Map({ '.link': new Map({ '[target]': 42 }) }); | ||
* expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42); | ||
* var nestedCss = new Map({ '.link': new Map({ '[target]': 42 }) }); | ||
* expect(nestedCss).to.have.nested.property('\\.link.\\[target\\]', 42); | ||
* ``` | ||
@@ -432,3 +432,3 @@ * | ||
if (Immutable.Iterable.isIterable(this._obj)) { | ||
var isDeep = Boolean(utils.flag(this, 'deep')); | ||
var isNested = Boolean(utils.flag(this, 'nested')); | ||
var negate = Boolean(utils.flag(this, 'negate')); | ||
@@ -440,4 +440,4 @@ | ||
if (isDeep) { | ||
descriptor = 'deep property '; | ||
if (isNested) { | ||
descriptor = 'nested property '; | ||
if (typeof path === 'string') { | ||
@@ -444,0 +444,0 @@ path = parsePath(path); |
{ | ||
"name": "chai-immutable", | ||
"version": "1.6.0", | ||
"version": "2.0.0-alpha.1", | ||
"description": "Chai assertions for Facebook's Immutable library for JavaScript collections", | ||
"publishConfig": { | ||
"tag": "next" | ||
}, | ||
"main": "chai-immutable.js", | ||
@@ -11,5 +14,6 @@ "directories": { | ||
"check-style": "jscs chai-immutable.js test/test.js", | ||
"test": "npm run test-mocha; npm run test-phantomjs; npm run check-style", | ||
"test": "npm run test-mocha; npm run test-phantomjs; npm run test-readme; npm run check-style", | ||
"test-readme": "mocha --compilers md:fulky/mocha-md-compiler README.md", | ||
"test-mocha": "mocha", | ||
"test-phantomjs": "echo 'mocha-phantomjs is temporarily disabled.' # mocha-phantomjs test/index.html", | ||
"test-phantomjs": "mocha-phantomjs test/index.html", | ||
"coverage": "istanbul cover _mocha", | ||
@@ -40,12 +44,14 @@ "coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls" | ||
"peerDependencies": { | ||
"chai": ">= 2.0.0 < 4" | ||
"chai": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.4.0", | ||
"chai": "^4.0.0", | ||
"coveralls": "^2.11.9", | ||
"fulky": "^0.1.0", | ||
"immutable": "^3.7.5", | ||
"istanbul": "^0.4.3", | ||
"jscs": "^2.5.0", | ||
"mocha": "^2.4.5" | ||
"mocha": "^2.4.5", | ||
"mocha-phantomjs": "^4.1.0" | ||
} | ||
} |
@@ -6,4 +6,4 @@ [![npm Version](https://img.shields.io/npm/v/chai-immutable.svg)](https://npmjs.org/package/chai-immutable) | ||
[![Coverage Status](https://coveralls.io/repos/astorije/chai-immutable/badge.svg)](https://coveralls.io/r/astorije/chai-immutable) | ||
[![devDependency Status](https://david-dm.org/astorije/chai-immutable/dev-status.svg)](https://david-dm.org/astorije/chai-immutable#info=devDependencies) | ||
[![peerDependency Status](https://david-dm.org/astorije/chai-immutable/peer-status.svg)](https://david-dm.org/astorije/chai-immutable#info=peerDependencies) | ||
[![devDependencies Status](https://david-dm.org/astorije/chai-immutable/dev-status.svg)](https://david-dm.org/astorije/chai-immutable?type=dev) | ||
[![peerDependencies Status](https://david-dm.org/astorije/chai-immutable/peer-status.svg)](https://david-dm.org/astorije/chai-immutable?type=peer) | ||
@@ -14,2 +14,16 @@ # Chai Immutable | ||
<!-- fulky:globals | ||
var chai = require('chai'); | ||
var assert = chai.assert; | ||
var expect = chai.expect; | ||
var Immutable = require('immutable'); | ||
var List = Immutable.List; | ||
var Map = Immutable.Map; | ||
var Set = Immutable.Set; | ||
var Stack = Immutable.Stack; | ||
chai.use(require('./chai-immutable')); | ||
--> | ||
## Installation | ||
@@ -27,2 +41,3 @@ | ||
<!-- fulky:skip-test --> | ||
```js | ||
@@ -51,2 +66,3 @@ var chai = require('chai'); | ||
<!-- fulky:skip-test --> | ||
```js | ||
@@ -164,5 +180,6 @@ var chai = require('chai'); | ||
Immutable object. | ||
If the `deep` flag is set, you can use dot- and bracket-notation for deep | ||
If the `nested` flag is set, you can use dot- and bracket-notation for nested | ||
references into objects and arrays. | ||
<!-- fulky:define maps --> | ||
```js | ||
@@ -175,19 +192,19 @@ // Simple referencing | ||
// Deep referencing | ||
var deepMap = new Map({ | ||
green: new Map({ tea: 'matcha' }), | ||
teas: new List(['chai', 'matcha', new Map({ tea: 'konacha' })]) | ||
var nestedMap = new Map({ | ||
green: new Map({ tea: 'matcha' }), | ||
teas: new List(['chai', 'matcha', new Map({ tea: 'konacha' })]) | ||
}); | ||
expect(deepMap).to.have.deep.property('green.tea', 'matcha'); | ||
expect(deepMap).to.have.deep.property(['green', 'tea'], 'matcha'); | ||
expect(deepMap).to.have.deep.property(new List(['green', 'tea']), 'matcha'); | ||
expect(deepMap).to.have.deep.property('teas[1]', 'matcha'); | ||
expect(deepMap).to.have.deep.property(['teas', 1], 'matcha'); | ||
expect(deepMap).to.have.deep.property(new List(['teas', 1]), 'matcha'); | ||
expect(deepMap).to.have.deep.property('teas[2].tea', 'konacha'); | ||
expect(deepMap).to.have.deep.property(['teas', 2, 'tea'], 'konacha'); | ||
expect(deepMap).to.have.deep.property(new List(['teas', 2, 'tea']), 'konacha'); | ||
expect(nestedMap).to.have.nested.property('green.tea', 'matcha'); | ||
expect(nestedMap).to.have.nested.property(['green', 'tea'], 'matcha'); | ||
expect(nestedMap).to.have.nested.property(new List(['green', 'tea']), 'matcha'); | ||
expect(nestedMap).to.have.nested.property('teas[1]', 'matcha'); | ||
expect(nestedMap).to.have.nested.property(['teas', 1], 'matcha'); | ||
expect(nestedMap).to.have.nested.property(new List(['teas', 1]), 'matcha'); | ||
expect(nestedMap).to.have.nested.property('teas[2].tea', 'konacha'); | ||
expect(nestedMap).to.have.nested.property(['teas', 2, 'tea'], 'konacha'); | ||
expect(nestedMap).to.have.nested.property(new List(['teas', 2, 'tea']), 'konacha'); | ||
``` | ||
You can also use a `List` as the starting point of a `deep.property` | ||
You can also use a `List` as the starting point of a `nested.property` | ||
assertion, or traverse nested `List`s. | ||
@@ -205,8 +222,8 @@ | ||
expect(list).to.have.deep.property('[0][1]', 'matcha'); | ||
expect(list).to.have.deep.property([0, 1], 'matcha'); | ||
expect(list).to.have.deep.property(new List([0, 1]), 'matcha'); | ||
expect(list).to.have.deep.property('[1][2].tea', 'konacha'); | ||
expect(list).to.have.deep.property([1, 2, 'tea'], 'konacha'); | ||
expect(list).to.have.deep.property(new List([1, 2, 'tea']), 'konacha'); | ||
expect(list).to.have.nested.property('[0][1]', 'matcha'); | ||
expect(list).to.have.nested.property([0, 1], 'matcha'); | ||
expect(list).to.have.nested.property(new List([0, 1]), 'matcha'); | ||
expect(list).to.have.nested.property('[1][2].tea', 'konacha'); | ||
expect(list).to.have.nested.property([1, 2, 'tea'], 'konacha'); | ||
expect(list).to.have.nested.property(new List([1, 2, 'tea']), 'konacha'); | ||
``` | ||
@@ -218,11 +235,12 @@ | ||
<!-- fulky:use maps --> | ||
```js | ||
expect(map).to.have.property('foo') | ||
.that.is.a('string'); | ||
expect(deepMap).to.have.property('green') | ||
expect(nestedMap).to.have.property('green') | ||
.that.is.an.instanceof(Map) | ||
.that.equals(new Map({ tea: 'matcha' })); | ||
expect(deepMap).to.have.property('teas') | ||
expect(nestedMap).to.have.property('teas') | ||
.that.is.an.instanceof(List) | ||
.with.deep.property([2]) | ||
.with.nested.property([2]) | ||
.that.equals(new Map({ tea: 'konacha' })); | ||
@@ -232,3 +250,3 @@ ``` | ||
Note that dots and brackets in `name` must be backslash-escaped when | ||
the `deep` flag is set, while they must NOT be escaped when the `deep` | ||
the `nested` flag is set, while they must NOT be escaped when the `nested` | ||
flag is not set. | ||
@@ -242,4 +260,4 @@ | ||
// Deep referencing | ||
var deepCss = new Map({ '.link': new Map({ '[target]': 42 }) }); | ||
expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42); | ||
var nestedCss = new Map({ '.link': new Map({ '[target]': 42 }) }); | ||
expect(nestedCss).to.have.nested.property('\\.link.\\[target\\]', 42); | ||
``` | ||
@@ -246,0 +264,0 @@ |
@@ -362,7 +362,2 @@ 'use strict'; | ||
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 () { | ||
@@ -454,5 +449,5 @@ fail(function () { expect(map).to.have.keys('z1', 'z2'); }); | ||
describe('using the `deep` flag', function () { | ||
describe('using the `nested` flag', function () { | ||
it('should not affect the original assertion', function () { | ||
expect({ x: 1, y: { x: 2, y: 3 } }).to.have.deep.property('y.x', 2); | ||
expect({ x: 1, y: { x: 2, y: 3 } }).to.have.nested.property('y.x', 2); | ||
}); | ||
@@ -462,3 +457,3 @@ | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
fail(function () { expect(obj).to.have.deep.property(['y', 'z']); }); | ||
fail(function () { expect(obj).to.have.nested.property(['y', 'z']); }); | ||
}); | ||
@@ -468,3 +463,3 @@ | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
expect(obj).not.to.have.deep.property(['y', 'z']); | ||
expect(obj).not.to.have.nested.property(['y', 'z']); | ||
}); | ||
@@ -474,3 +469,3 @@ | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
expect(obj).to.have.deep.property(['y', 'x']); | ||
expect(obj).to.have.nested.property(['y', 'x']); | ||
}); | ||
@@ -482,3 +477,3 @@ | ||
}); | ||
expect(obj).to.have.deep.property(['items', 2], 'c'); | ||
expect(obj).to.have.nested.property(['items', 2], 'c'); | ||
}); | ||
@@ -488,3 +483,3 @@ | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
fail(function () { expect(obj).not.to.have.deep.property(['y', 'x']); }); | ||
fail(function () { expect(obj).not.to.have.nested.property(['y', 'x']); }); | ||
}); | ||
@@ -501,3 +496,3 @@ | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
expect(obj).to.have.deep.property(['y', 'x'], 2); | ||
expect(obj).to.have.nested.property(['y', 'x'], 2); | ||
}); | ||
@@ -508,3 +503,3 @@ | ||
fail(function () { | ||
expect(obj).not.to.have.deep.property(['y', 'x'], 'different'); | ||
expect(obj).not.to.have.nested.property(['y', 'x'], 'different'); | ||
}); | ||
@@ -516,3 +511,3 @@ }); | ||
fail(function () { | ||
expect(obj).not.to.have.deep.property(['y', 'x'], 2); | ||
expect(obj).not.to.have.nested.property(['y', 'x'], 2); | ||
}); | ||
@@ -523,3 +518,3 @@ }); | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2 } }); | ||
expect(obj).not.to.have.deep.property(['y', 'x'], 'different'); | ||
expect(obj).not.to.have.nested.property(['y', 'x'], 'different'); | ||
}); | ||
@@ -529,3 +524,3 @@ | ||
var obj = Immutable.fromJS({ foo: [{ bar: 42 }] }); | ||
expect(obj).to.have.deep.property('foo[0]', new Map({ bar: 42 })); | ||
expect(obj).to.have.nested.property('foo[0]', new Map({ bar: 42 })); | ||
}); | ||
@@ -543,9 +538,9 @@ }); | ||
it('should pass using `deep` given a single index', function () { | ||
expect(obj.get('items')).to.have.deep.property('[1]') | ||
it('should pass using `nested` given a single index', function () { | ||
expect(obj.get('items')).to.have.nested.property('[1]') | ||
.that.equals(new Map({ name: 'John' })); | ||
}); | ||
it('should pass using `deep` given a single key', function () { | ||
expect(obj).to.have.deep.property('items') | ||
it('should pass using `nested` given a single key', function () { | ||
expect(obj).to.have.nested.property('items') | ||
.that.equals(new List([ | ||
@@ -558,13 +553,13 @@ new Map({ name: 'Jane' }), | ||
it('should pass using `deep` starting with an index', function () { | ||
expect(obj.get('items')).to.have.deep.property('[0].name', 'Jane'); | ||
it('should pass using `nested` starting with an index', function () { | ||
expect(obj.get('items')).to.have.nested.property('[0].name', 'Jane'); | ||
}); | ||
it('should pass using `deep` ending with an index', function () { | ||
expect(obj).to.have.deep.property('items[1]') | ||
it('should pass using `nested` ending with an index', function () { | ||
expect(obj).to.have.nested.property('items[1]') | ||
.that.equals(new Map({ name: 'John' })); | ||
}); | ||
it('should pass using `deep` given a mix of keys and indices', function () { | ||
expect(obj).to.have.deep.property('items[2].name', 'Jim'); | ||
it('should pass using `nested` given mix of keys and indices', function () { | ||
expect(obj).to.have.nested.property('items[2].name', 'Jim'); | ||
}); | ||
@@ -577,5 +572,5 @@ | ||
it('should expect escaped path strings using `deep`', function () { | ||
var deepCss = new Map({ '.link': new Map({ '[target]': 42 }) }); | ||
expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42); | ||
it('should expect escaped path strings using `nested`', function () { | ||
var nestedCss = new Map({ '.link': new Map({ '[target]': 42 }) }); | ||
expect(nestedCss).to.have.nested.property('\\.link.\\[target\\]', 42); | ||
}); | ||
@@ -880,5 +875,5 @@ }); | ||
it('should succeed for equal deep property', function () { | ||
it('should succeed for equal nested property', function () { | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
assert.deepProperty(obj, ['y', 'x']); | ||
assert.nestedProperty(obj, ['y', 'x']); | ||
}); | ||
@@ -888,3 +883,5 @@ | ||
var obj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } }); | ||
fail(function () { assert.deepPropertyVal(obj, ['y', 'x'], 'different'); }); | ||
fail(function () { | ||
assert.nestedPropertyVal(obj, ['y', 'x'], 'different'); | ||
}); | ||
}); | ||
@@ -891,0 +888,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
79327
331
8
1475
1