Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Chai v4.0 #69

Merged
merged 1 commit into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ expect(new Map({ foo: 1, bar: 2 })).to.contain.key('foo');
Asserts that the target has a property `name`, optionally asserting that
the value of that property is equal to `value`. `value` can be an
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 -->
Expand All @@ -184,23 +184,23 @@ expect(map).to.have.property('foo');
expect(map).to.have.property('foo', 'bar');

// Deep referencing
var deepMap = new Map({
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.

```js
Expand All @@ -213,12 +213,12 @@ var list = new List([
])
]);

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');
```

Furthermore, `property` changes the subject of the assertion
Expand All @@ -229,17 +229,17 @@ permits for further chainable assertions on that property.
```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' }));
```

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.

```js
Expand All @@ -248,8 +248,8 @@ var css = new Map({ '.link[target]': 42 });
expect(css).to.have.property('.link[target]', 42);

// 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);
```

### .size(value)
Expand Down
64 changes: 32 additions & 32 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@

if (Immutable.Iterable.isKeyed(obj)) {
switch (utils.type(keys)) {
case 'object':
case 'Object':
if (Immutable.Iterable.isIndexed(keys))
keys = keys.toJS();
else if (Immutable.Iterable.isIterable(keys))
keys = keys.keySeq().toJS();
else keys = Object.keys(keys);
case 'array':
case 'Array':
if (arguments.length > 1) throw new Error(
'keys must be given single argument of ' +
'Array|Object|String|Collection, ' +
Expand All @@ -253,7 +253,7 @@
if (any) ok = keys.some(has);
else {
ok = keys.every(has);
if (!contains && !utils.flag(this, 'negate')) {
if (!contains) {
ok = ok && keys.length === obj.count();
}
}
Expand Down Expand Up @@ -331,8 +331,8 @@
* Asserts that the target has a property `name`, optionally asserting that
* the value of that property is equal to `value`. `value` can be an
* 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.
*
* ```js
* // Simple referencing
Expand All @@ -341,23 +341,23 @@
* expect(map).to.have.property('foo', 'bar');
*
* // Deep referencing
* var deepMap = new Map({
* 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.
*
* ```js
Expand All @@ -370,12 +370,12 @@
* ])
* ]);
*
* 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');
* ```
*
* Furthermore, `property` changes the subject of the assertion
Expand All @@ -385,27 +385,27 @@
* ```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' }));
* ```
*
* 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.
*
* ```js
* // Simple referencing
* var css = new Map({ '.link[target]': 42 });
* expect(css).to.have.property('.link[target]', 42);
*
* // 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);
* ```
*
* @name property
Expand All @@ -419,15 +419,15 @@
var obj = this._obj;

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'));

var descriptor;
var hasProperty;
var value;

if (isDeep) {
descriptor = 'deep property ';
if (isNested) {
descriptor = 'nested property ';
if (typeof path === 'string') {
path = parsePath(path);
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
},
"homepage": "https://github.com/astorije/chai-immutable",
"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",
Expand Down
Loading