Skip to content

Commit

Permalink
Merge pull request #411 from chaijs/release-2.2.0
Browse files Browse the repository at this point in the history
Release v2.2.0
  • Loading branch information
keithamus committed Mar 27, 2015
2 parents 1abc384 + 2173e63 commit 57df388
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 28 deletions.
11 changes: 11 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2.2.0 / 2015-03-26
==================

* Merge pull request #405 from chaijs/deep-escape-doc-tweaks
* Tweak documentation on `.deep` flag.
* Merge pull request #402 from umireon/escaping-dot-should-be-taken
* Documentation of escaping in `.deep` flag.
* take regular expression apart
* Feature: backslash-escaping in `.deep.property`
* Escaping dot should be taken in deep property

2.1.2 / 2015-03-15
==================

Expand Down
24 changes: 24 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Release Notes

## 2.2.0 / 2015-03-26

Deep property strings can now be escaped using `\\` - for example:

```js
var deepCss = { '.link': { '[target]': 42 }};
expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42)
```

### Community Contributions

#### Code Features & Fixes

* [#402](https://github.com/chaijs/chai/pull/402) Allow escaping of deep
property keys.
By [@umireon](https://github.com/umireon)

#### Documentation fixes

* [#405](https://github.com/chaijs/chai/pull/405) Tweak documentation around
deep property escaping.
By [@keithamus](https://github.com/keithamus)


## 2.1.2 / 2015-03-15

A minor bug fix. No new features.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chai",
"version": "2.1.2",
"version": "2.2.0",
"description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic.",
"license": "MIT",
"keywords": [
Expand Down
93 changes: 69 additions & 24 deletions chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ require.helper.semVerSort = function(a, b) {

/**
* Find and require a module which name starts with the provided name.
* If multiple modules exists, the highest semver is used.
* If multiple modules exists, the highest semver is used.
* This function can only be used for remote dependencies.
* @param {String} name - module name: `user~repo`
* @param {Boolean} returnPath - returns the canonical require path if true,
* @param {Boolean} returnPath - returns the canonical require path if true,
* otherwise it returns the epxorted module
*/
require.latest = function (name, returnPath) {
Expand All @@ -83,7 +83,7 @@ require.latest = function (name, returnPath) {
semVerCandidates.push({version: version, name: moduleName});
} else {
otherCandidates.push({version: version, name: moduleName});
}
}
}
}
if (semVerCandidates.concat(otherCandidates).length === 0) {
Expand Down Expand Up @@ -678,7 +678,7 @@ var used = []
* Chai version
*/

exports.version = '2.1.2';
exports.version = '2.2.0';

/*!
* Assertion Error
Expand Down Expand Up @@ -1033,6 +1033,12 @@ module.exports = function (chai, _) {
* expect({ foo: { bar: { baz: 'quux' } } })
* .to.have.deep.property('foo.bar.baz', 'quux');
*
* `.deep.property` special characters can be escaped
* by adding two slashes before the `.` or `[]`.
*
* var deepCss = { '.link': { '[target]': 42 }};
* expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
*
* @name deep
* @api public
*/
Expand All @@ -1045,7 +1051,7 @@ module.exports = function (chai, _) {
* ### .any
*
* Sets the `any` flag, (opposite of the `all` flag)
* later used in the `keys` assertion.
* later used in the `keys` assertion.
*
* expect(foo).to.have.any.keys('bar', 'baz');
*
Expand All @@ -1062,7 +1068,7 @@ module.exports = function (chai, _) {
/**
* ### .all
*
* Sets the `all` flag (opposite of the `any` flag)
* Sets the `all` flag (opposite of the `any` flag)
* later used by the `keys` assertion.
*
* expect(foo).to.have.all.keys('bar', 'baz');
Expand Down Expand Up @@ -1719,7 +1725,7 @@ module.exports = function (chai, _) {
* green: { tea: 'matcha' }
* , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
* };
*
* expect(deepObj).to.have.deep.property('green.tea', 'matcha');
* expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
* expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
Expand Down Expand Up @@ -1751,6 +1757,18 @@ module.exports = function (chai, _) {
* .with.deep.property('[2]')
* .that.deep.equals({ tea: 'konacha' });
*
* Note that dots and bracket 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.
*
* // simple referencing
* var css = { '.link[target]': 42 };
* expect(css).to.have.property('.link[target]', 42);
*
* // deep referencing
* var deepCss = { '.link': { '[target]': 42 }};
* expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42);
*
* @name property
* @alias deep.property
* @param {String} name
Expand Down Expand Up @@ -1929,23 +1947,23 @@ module.exports = function (chai, _) {
* ### .keys(key1, [key2], [...])
*
* Asserts that the target contains any or all of the passed-in keys.
* Use in combination with `any`, `all`, `contains`, or `have` will affect
* Use in combination with `any`, `all`, `contains`, or `have` will affect
* what will pass.
*
* When used in conjunction with `any`, at least one key that is passed
* in must exist in the target object. This is regardless whether or not
*
* When used in conjunction with `any`, at least one key that is passed
* in must exist in the target object. This is regardless whether or not
* the `have` or `contain` qualifiers are used. Note, either `any` or `all`
* should be used in the assertion. If neither are used, the assertion is
* defaulted to `all`.
*
* When both `all` and `contain` are used, the target object must have at
*
* When both `all` and `contain` are used, the target object must have at
* least all of the passed-in keys but may have more keys not listed.
*
*
* When both `all` and `have` are used, the target object must both contain
* all of the passed-in keys AND the number of keys in the target object must
* match the number of keys passed in (in other words, a target object must
* match the number of keys passed in (in other words, a target object must
* have all and only all of the passed-in keys).
*
*
* expect({ foo: 1, bar: 2 }).to.have.any.keys('foo', 'baz');
* expect({ foo: 1, bar: 2 }).to.have.any.keys('foo');
* expect({ foo: 1, bar: 2 }).to.contain.any.keys('bar', 'baz');
Expand Down Expand Up @@ -3500,10 +3518,36 @@ module.exports = function (chai, util) {
*/

assert.operator = function (val, operator, val2, msg) {
if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
throw new Error('Invalid operator "' + operator + '"');
var ok;
switch(operator) {
case '==':
ok = val == val2;
break;
case '===':
ok = val === val2;
break;
case '>':
ok = val > val2;
break;
case '>=':
ok = val >= val2;
break;
case '<':
ok = val < val2;
break;
case '<=':
ok = val <= val2;
break;
case '!=':
ok = val != val2;
break;
case '!==':
ok = val !== val2;
break;
default:
throw new Error('Invalid operator "' + operator + '"');
}
var test = new Assertion(eval(val + operator + val2), msg);
var test = new Assertion(ok, msg);
test.assert(
true === flag(test, 'object')
, 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
Expand Down Expand Up @@ -4286,7 +4330,7 @@ var getPathInfo = require('chai/lib/chai/utils/getPathInfo.js');
module.exports = function(path, obj) {
var info = getPathInfo(path, obj);
return info.value;
};
};

});

Expand Down Expand Up @@ -4347,20 +4391,21 @@ module.exports = function getPathInfo(path, obj) {
*
* * Can be as near infinitely deep and nested
* * Arrays are also valid using the formal `myobject.document[3].property`.
* * Literal dots and brackets (not delimiter) must be backslash-escaped.
*
* @param {String} path
* @returns {Object} parsed
* @api private
*/

function parsePath (path) {
var str = path.replace(/\[/g, '.[')
var str = path.replace(/([^\\])\[/g, '$1.[')
, parts = str.match(/(\\\.|[^.]+?)+/g);
return parts.map(function (value) {
var re = /\[(\d+)\]$/
var re = /^\[(\d+)\]$/
, mArr = re.exec(value);
if (mArr) return { i: parseFloat(mArr[1]) };
else return { p: value };
else return { p: value.replace(/\\([.\[\]])/g, '$1') };
});
}

Expand Down Expand Up @@ -4432,7 +4477,7 @@ var type = require('chai/lib/chai/utils/type.js');
* hasProperty('str', obj); // true
* hasProperty('constructor', obj); // true
* hasProperty('bar', obj); // false
*
*
* hasProperty('length', obj.str); // true
* hasProperty(1, obj.str); // true
* hasProperty(5, obj.str); // false
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "chai"
, "repo": "chaijs/chai"
, "version": "2.1.2"
, "version": "2.2.0"
, "description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic."
, "license": "MIT"
, "keywords": [
Expand Down
2 changes: 1 addition & 1 deletion lib/chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var used = []
* Chai version
*/

exports.version = '2.1.2';
exports.version = '2.2.0';

/*!
* Assertion Error
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"Veselin Todorov <[email protected]>",
"John Firebaugh <[email protected]>"
],
"version": "2.1.2",
"version": "2.2.0",
"repository": {
"type": "git",
"url": "https://github.com/chaijs/chai"
Expand Down

0 comments on commit 57df388

Please sign in to comment.