diff --git a/History.md b/History.md index 32b6ef902..9d406f6ca 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,26 @@ +1.9.2 / 2014-09-29 +================== + + * Merge pull request #268 from charlierudolph/cr-lazyMessages + * Merge pull request #269 from charlierudolph/cr-codeCleanup + * Merge pull request #277 from charlierudolph/fix-doc + * Merge pull request #279 from mohayonao/fix-closeTo + * Merge pull request #292 from boneskull/mocha + * resolves #255: upgrade mocha + * Merge pull request #289 from charlierudolph/cr-dryUpCode + * Dry up code + * Merge pull request #275 from DrRataplan/master + * assert: .closeTo() verify value's type before assertion + * Rewrite pretty-printing HTML elements to prevent throwing internal errors Fixes errors occuring when using a non-native DOM implementation + * Fix assert documentation + * Remove unused argument + * Allow messages to be functions + * Merge pull request #267 from shinnn/master + * Use SVG badge + * Merge pull request #264 from cjthompson/keys_diff + * Show diff for keys assertion + 1.9.1 / 2014-03-19 ================== diff --git a/ReleaseNotes.md b/ReleaseNotes.md index fb2a1dc29..f945e039b 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,5 +1,30 @@ # Release Notes +## 1.9.2 / 2014-09-29 + +The following changes are required if you are upgrading from the previous version: + +- **Users:** + - No changes required +- **Plugin Developers:** + - No changes required +- **Core Contributors:** + - Refresh `node_modules` folder for updated dependencies. + +### Community Contributions + +- [#264](https://github.com/chaijs/chai/pull/264) Show diff for keys assertions [@cjthompson](https://github.com/cjthompson) +- [#267](https://github.com/chaijs/chai/pull/267) Use SVG badges [@shinnn](https://github.com/shinnn) +- [#268](https://github.com/chaijs/chai/pull/268) Allow messages to be functions (sinon-compat) [@charlierudolph](https://github.com/charlierudolph) +- [#269](https://github.com/chaijs/chai/pull/269) Remove unused argument for #lengthOf [@charlierudolph](https://github.com/charlierudolph) +- [#275](https://github.com/chaijs/chai/pull/275) Rewrite pretty-printing HTML elements to prevent throwing internal errors [@DrRataplan](https://github.com/DrRataplan) +- [#277](https://github.com/chaijs/chai/pull/277) Fix assert documentation for #sameMembers [@charlierudolph](https://github.com/charlierudolph) +- [#279](https://github.com/chaijs/chai/pull/279) closeTo should check value's type before assertion [@mohayonao](https://github.com/mohayonao) +- [#289](https://github.com/chaijs/chai/pull/289) satisfy is called twice [@charlierudolph](https://github.com/charlierudolph) +- [#292](https://github.com/chaijs/chai/pull/292) resolve conflicts with node-webkit and global usage [@boneskull](https://github.com/boneskull) + +Thank you to all who took time to contribute! + ## 1.9.1 / 2014-03-19 The following changes are required if you are upgrading from the previous version: diff --git a/bower.json b/bower.json index 8d7b3d548..cf9bb7d61 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "chai" - , "version": "1.9.1" + , "version": "1.9.2" , "description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic." , "license": "MIT" , "keywords": [ diff --git a/chai.js b/chai.js index a75da8596..33dba967d 100644 --- a/chai.js +++ b/chai.js @@ -736,7 +736,7 @@ var used = [] * Chai version */ -exports.version = '1.9.1'; +exports.version = '1.9.2'; /*! * Assertion Error @@ -903,8 +903,8 @@ module.exports = function (_chai, util) { * * @name assert * @param {Philosophical} expression to be tested - * @param {String} message to display if fails - * @param {String} negatedMessage to display if negated expression fails + * @param {String or Function} message or function that returns message to display if fails + * @param {String or Function} negatedMessage or function that returns negatedMessage to display if negated expression fails * @param {Mixed} expected value (remember to check for negation) * @param {Mixed} actual (optional) will default to `this.obj` * @api private @@ -1872,7 +1872,7 @@ module.exports = function (chai, _) { } Assertion.addChainableMethod('length', assertLength, assertLengthChain); - Assertion.addMethod('lengthOf', assertLength, assertLengthChain); + Assertion.addMethod('lengthOf', assertLength); /** * ### .match(regexp) @@ -1951,6 +1951,7 @@ module.exports = function (chai, _) { if (!keys.length) throw new Error('keys required'); var actual = Object.keys(obj) + , expected = keys , len = keys.length; // Inclusion @@ -1985,6 +1986,9 @@ module.exports = function (chai, _) { ok , 'expected #{this} to ' + str , 'expected #{this} to not ' + str + , expected.sort() + , actual.sort() + , true ); } @@ -2220,12 +2224,13 @@ module.exports = function (chai, _) { Assertion.addMethod('satisfy', function (matcher, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); + var result = matcher(obj); this.assert( - matcher(obj) + result , 'expected #{this} to satisfy ' + _.objDisplay(matcher) , 'expected #{this} to not satisfy' + _.objDisplay(matcher) , this.negate ? false : true - , matcher(obj) + , result ); }); @@ -2246,6 +2251,12 @@ module.exports = function (chai, _) { Assertion.addMethod('closeTo', function (expected, delta, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object'); + + new Assertion(obj, msg).is.a('number'); + if (_.type(expected) !== 'number' || _.type(delta) !== 'number') { + throw new Error('the arguments to closeTo must be numbers'); + } + this.assert( Math.abs(obj - expected) <= delta , 'expected #{this} to be close to ' + expected + ' +/- ' + delta @@ -3324,8 +3335,8 @@ module.exports = function (chai, util) { * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members'); * * @name sameMembers - * @param {Array} superset - * @param {Array} subset + * @param {Array} set1 + * @param {Array} set2 * @param {String} message * @api public */ @@ -3799,6 +3810,7 @@ module.exports = function (obj, args) { , msg = negate ? args[2] : args[1] , flagMsg = flag(obj, 'message'); + if(typeof msg === "function") msg = msg(); msg = msg || ''; msg = msg .replace(/#{this}/g, objDisplay(val)) @@ -4122,24 +4134,6 @@ function inspect(obj, showHidden, depth, colors) { return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth)); } -// https://gist.github.com/1044128/ -var getOuterHTML = function(element) { - if ('outerHTML' in element) return element.outerHTML; - var ns = "http://www.w3.org/1999/xhtml"; - var container = document.createElementNS(ns, '_'); - var elemProto = (window.HTMLElement || window.Element).prototype; - var xmlSerializer = new XMLSerializer(); - var html; - if (document.xmlVersion) { - return xmlSerializer.serializeToString(element); - } else { - container.appendChild(element.cloneNode(false)); - html = container.innerHTML.replace('><', '>' + element.innerHTML + '<'); - container.innerHTML = ''; - return html; - } -}; - // Returns true if object is a DOM element. var isDOMElement = function (object) { if (typeof HTMLElement === 'object') { @@ -4173,9 +4167,37 @@ function formatValue(ctx, value, recurseTimes) { return primitive; } - // If it's DOM elem, get outer HTML. + // If this is a DOM element, try to get the outer HTML. if (isDOMElement(value)) { - return getOuterHTML(value); + if ('outerHTML' in value) { + return value.outerHTML; + // This value does not have an outerHTML attribute, + // it could still be an XML element + } else { + // Attempt to serialize it + try { + if (document.xmlVersion) { + var xmlSerializer = new XMLSerializer(); + return xmlSerializer.serializeToString(value); + } else { + // Firefox 11- do not support outerHTML + // It does, however, support innerHTML + // Use the following to render the element + var ns = "http://www.w3.org/1999/xhtml"; + var container = document.createElementNS(ns, '_'); + + container.appendChild(value.cloneNode(false)); + html = container.innerHTML + .replace('><', '>' + value.innerHTML + '<'); + container.innerHTML = ''; + return html; + } + } catch (err) { + // This could be a non-native DOM implementation, + // continue with the normal flow: + // printing the element as if it is an object. + } + } } // Look up the keys of the object. diff --git a/component.json b/component.json index 33a867c74..3d9029bfe 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "chai" , "repo": "chaijs/chai" - , "version": "1.9.1" + , "version": "1.9.2" , "description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic." , "license": "MIT" , "keywords": [ diff --git a/lib/chai.js b/lib/chai.js index f2d84503e..54beeccaf 100644 --- a/lib/chai.js +++ b/lib/chai.js @@ -11,7 +11,7 @@ var used = [] * Chai version */ -exports.version = '1.9.1'; +exports.version = '1.9.2'; /*! * Assertion Error diff --git a/package.json b/package.json index a8a79dea7..92594b9c9 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "Veselin Todorov ", "John Firebaugh " ], - "version": "1.9.1", + "version": "1.9.2", "repository": { "type": "git", "url": "https://github.com/chaijs/chai"