Release History
4.2.0 / 2018-09-25
Version 4.2.0
This is a minor release. Thank you to all of our contributors and users!
New Features
- feat(assertions): add ‘still’ language chain (#1194; @ScottRudiger)
- .lengthOf for Maps and Sets (#1110, #1131; @asbish)
- feat: Add the assert.fail([message]) interface (#1116, #1117; @s-leroux)
Bug Fixes
- fix: remove Chai frames from
.deep.equal
stack (#1124; @meeber) - add ‘catch’ keyword to proxyExcludedKeys (#1050, #1101; @generalandrew)
- property assertion should only accept strings if nested (#1043, #1044; @solodynamo)
- fix: Make tests pass with
--use_strict
(#1034, #1040; @shvaikalesh)
Performance
- perf: Optimize proxify and stringDistance (#1098; @sophiebits)
- fix: Avoid repeated String#slice calls in stringDistance (#1095; @bmeurer)
Style
- Fix typos and remove trailing whitespaces (#1042; @simonewebdesign)
- Remove unnecessary code (#1049; @abetomo)
- Fix variable declaration (#1048; @abetomo)
Tests
- test(assert): increase coverage (#1084, #1085; @brutalcrozt)
- test: stop modifying globals in Proxy tests (#1144; @meeber)
Docs
- Fix unbalanced quotes in assert.notInclude example (#1200; @haykam821)
- docs: fix bad
.string
example (#1156, #1157; @meeber) - fixed package npm url (#1151; @wadie)
- Spelling (#1145; @jsoref)
- docs: corrected spelling (#1141; @Powell-v2)
- docs: fix wrong
.property
chaining examples (https://github.com/chaijs/chai/issues/193#issuecomment-360334369, #1130; @meeber) - docs: improve throws examples (#1113; @ColinEberhardt)
- Fix typos (#1107; @tbroadley)
- docs: correct
.ok
description (#1047; @shvaikalesh)
Chores
- chore: update package-lock.json (#1198; @meeber)
- Update mocha to the latest version (#1127)
- chore: update dependencies (#1157; @meeber)
- Update browserify to the latest version (#1135)
- chore: update Node versions in Travis config (#1126; @meeber)
- chore: remove Opera from Sauce config (#1125; @meeber)
- chore: update dependencies (#1118; @meeber)
- chore: update dependencies (#1074; @meeber)
- Chore: change coverage service (coverall to codecov) (#927, #1073; @brutalcrozt)
- chore: add package-lock.json (#1013; @meeber)
4.1.2 / 2017-08-31
Version 4.1.2
This release fixes a bug when running in certain environments, and includes a few minor documentation fixes.
Bug Fixes
- fix: update
deep-eql
to version 3.0.0 (#1020) - fix: replace code causing breakage under strict CSP (#1032; @Alhadis)
Docs
- docs: add missing assert parameters (#1017, #1023; @Hpauric)
- docs: update year in license file (#1025; @yanca018)
4.1.1 / 2017-08-05
Version 4.1.1
This release includes a few bug and documentation fixes.
Bug Fixes
- fix:
.instanceof
to allow DOM interfaces in IE11 (#1000, #1008; @meeber) - fix:
.include
to work with all objects (#1009, #1012; @meeber)
Docs
- fix: correct hasAnyKeys comment error (#1014; @zenHeart)
- docs: re-indent hasAnyKeys code (#1016; @keithamus)
4.1.0 / 2017-07-11
Version 4.1.0
This release includes one new feature and a few bug fixes.
New Features
- Add ES6 collection support to include() (#970, #994; @shvaikalesh)
Bug Fixes
- Allow dates for isBelow and isAbove assertions (#980, #990; @v1adko)
- fix: check target’s type in
.property
assertion (#992; @meeber)
Chores
- Add a missing var keyword found by lgtm.com (#988; @samlanning)
- refactor:
expectTypes
to accessssfi
flag (#993; @meeber) - Create CODEOWNERS (#1004; @keithamus)
4.0.2 / 2017-06-05
Version 4.0.2
We have another bugfix release, addressing some issues for WebPack 1 users.
Bug Fixes
- Revert getting version information from package.json, some bundler tools like Webpack do not come default with json loaders despite Node being able to handle this. This change moves back to hardcoding the version number in the codebase. (#985, #986)
4.0.1 / 2017-05-31
Version 4.0.1
4.0.1
Of course, any major release cannot go without a quick bugfix release shortly after - and here’s ours!
Bug Fixes
- Remove package.json
browser
field which was mistakenly added, and caused bundler tools like Browserify or Webpack to fail as it attempted to rebundle an already bundled file. (#978, #982)
4.0.0-canary.2 / 2017-04-17
Version 4.0.0-canary.2
4.0.0-canary.2 / 2017-04-17
The second release in the 4.0.0 canary release cycle. Around the end of April, barring any showstopper bugs, this will be released as 4.0.0
Breaking Changes
-
We’ve dropped support for Node 0.10 (See #816) and Node 0.12 (#901). The minimum supported version is now Node 4.0. If you wish to continue using older versions of Node with Chai, please continue to use the
3.5.0
release. Officially, version 4.0.0 of chai supports Nodes 4, 6, 7, as well as the moving LTS version (currently 6.10.2). We plan to support Node 4 until at-least April 2018 (inline with Node Foundation support). -
.not.keys
on its own is now the equivalent of.not.all.keys
(#924). The docs mention this, and suggest to always pair.keys
with something.
New Features
-
Added side-effectful “register” style scripts for each interface, (See #868). This allows one to
require('chai/should')
which will automatically callglobal.should = chai.should()
. This is useful for users who wish to automatically get a global for their codebase. Read the docs for more info! -
Added the
browser
field to the package json (#875). This will help with browser bundling tools. -
Added
.own.include
and.nested.include
(#926). -
If you attempt to call
.throws
with something that isn’t a constructor (likeTypeError
) you will now get a more helpful error message about this. (before it would sayRight-hand side of 'instanceof' is not an object
, now it saysThe instanceof assertion needs a constructor but <type> was given
). (#899).
Bug Fixes
-
Minor update deep-eql to 2.0.1 (#871) which fixes bugs around Memoization, and lets comparators override evaluation of primitives.
-
We’ve updated documentation and error handling around using
.length
(#897) - which can, in some cases, be problematic. Typically, you’ll want to use.lengthOf
instead - but the documentation now makes this clear, and errors are more helpful when bad things happen. -
We’ve improved stack traces to strip out chai’s internals, especially in newer environments which use Proxies (#884 and #922).
-
We’ve gone through and made sure every assertion honors the custom error message you pass it - some didn’t! (#947).
-
getFuncName
has had an update since we pulled out the behaviour in4.0.0-canary.1
(#915). Practically this doesn’t change anything in Chai.
Documentation
- Added LICENSE file (#854)
- Major documentation rewrite including the plugin docs (#911),
.throw
docs (#866), and, well, just about all other docs (#920). These docs are far more detailed now, explaining caveats, algorithms and best practices.
4.0.0-canary.1
Version 4.0.0-canary.1
4.0.0-canary.1
Breaking Changes
-
Instead of allowing the user to write the path of a property, now the deep flag performs a deep equality comparison when used with the
.property
assertion. If you want the old behavior of using the dot or bracket notation to denote the property you want to assert against you can use the new.nested
flag. (Related Issues: #745, #743, PRs: #758, #757)const obj = {a: 1}; // The `.deep` flag now does deep equality comparisons expect({foo: obj}).to.have.deep.property('foo', {a: 1}); // Use the `nested` flag if you want to assert against a nested property using the bracket or dot notation expect({foo: obj}).to.have.nested.property('foo.a', 1); // You can also use both flags combined const obj2 = {a: {b: 2}}; expect({foo: obj2}).to.have.deep.nested.property('foo.a', {b: 2});
Please notice that the old methods which used the old behavior of the
deep
flag on theassert
interface have been renamed. They all have had thedeep
word changed by thenested
word. If you want to know more about this please take a look at #757. - Previously,
expect(obj).not.property(name, val)
would throw an Error ifobj
didn’t have a property namedname
. This change causes the assertion to pass instead. Theassert.propertyNotVal
andassert.deepPropertyNotVal
assertions were renamed toassert.notPropertyVal
andassert.notDeepPropertyVal
, respectively. (Related Issues: #16, #743, #758) -
You can now use the
deep
flag for the.include
assertion in order to perform adeep
equality check to see if something is included on thetarget
. Previously,.include
was using strict equality (===
) for non-negated property inclusion, butdeep
equality for negated property inclusion and array inclusion. This change causes the .include assertion to always use strict equality unless the deep flag is set. Please take a look at this comment if you want to know more about it. (Related Issues: #743, PRs: #760, #761)const obj = {a: 1}; expect([obj]).to.deep.include({a:1}); expect({foo: obj}).to.deep.include({foo: {a:1}});
-
Fix unstable behavior of the
NaN
assertion. Now we use the suggested ES6 implementation. The new implementation is now more correct, strict and simple. While the old one threw false positives, the new implementation only checks if something isNaN
(or not if the.not
flag is used) and nothing else. (Related Issues: #498, #682, #681, PRs: #508)// Only `NaN` will be considered to be `NaN` and nothing else expect(NaN).to.be.NaN; // Anything that is not `NaN` cannot be considered as `NaN` expect('randomString').not.to.be.NaN; expect(true).not.to.be.NaN; expect({}).not.to.be.NaN; expect(4).not.to.be.NaN;
-
Throw when calling
_super
onoverwriteMethod
if the method being overwritten isundefined
. Currently if the method you are trying to overwrite is not defined and your new method calls_super
it will throw anError
.(Related Issues: #467, PRs: #528) Before this change, calling_super
would simply returnthis
.// Considering the method `imaginaryMethod` does not exist, this would throw an error for example: chai.use(function (chai, utilities) { chai.Assertion.overwriteMethod('imaginaryMethod', function (_super) { return function () { _super.apply(this, arguments); } }); }); // This will throw an error since you are calling `_super` which should be a method (in this case, the overwritten assertion) that does not exist expect('anything').to.imaginaryMethod();
-
Now
showDiff
is turned on by default whenever theshowDiff
flag is anything other thanfalse
. This issue will mostly affect plugin creators or anyone that made extensions to the core, since this affects theAssertion.assert
method. (Related Issues: #574, PRs: #515)// Now whenever you call `Assertion.assert` with anything that is not false for the `showDiff` flag it will be true // The assertion error that was thrown will have the `showDiff` flag turned on since it was not passed to the `assert` method try { new chai.Assertion().assert( 'one' === 'two' , 'expected #{this} to equal #{exp}' , 'expected #{this} to not equal #{act}' , 'one' , 'two' ); } catch(e) { assert.isTrue(e.showDiff); } // The assertion error that was thrown will have the `showDiff` flag turned off since here we passed `false` explicitly try { new chai.Assertion().assert( 'one' === 'two' , 'expected #{this} to equal #{exp}' , 'expected #{this} to not equal #{act}' , 'one' , 'two' , false ); } catch(e) { assert.isFalse(e.showDiff); }
-
The Typed Array types are now truncated if they’re too long (in this case, if they exceed the
truncateThreshold
value on theconfig
). (Related Issues: #441, PRs: #576)var arr = []; for (var i = 1; i <= 1000; i++) { arr.push(i); } // The assertion below will truncate the diff shown and the enourmous typed array will be shown as: // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... ] instead of printing the whole typed array chai.expect(new Float32Array(100)).to.equal(1);
-
The assertions:
within
,above
,least
,below
,most
,increase
,decrease
will throw an error if the assertion’s target or arguments are not numbers. (Related Issues: #691, PRs: #692, #796)// These will throw errors, for example: expect(null).to.be.within(0, 1); expect(null).to.be.above(10); expect(null).to.be.at.least(20); expect(null).to.be.below(20); expect(null).to.be.at.most(20); expect(null).to.increase.by(20); expect(null).to.decrease.by(20); // This will not: expect('string').to.have.a.length.of.at.least(3);
-
Previously, expect(obj).not.ownProperty(name, val) would throw an Error if obj didn’t have an own property (non-inherited) named name. This change causes the assertion to pass instead. (Related Issues: #795, #, PRs: #744, #810)*
expect({ foo: 'baz' }).to.not.have.own.property('quux', 'baz');
-
The
.empty
assertion will now throw when it is passed non-string primitives and functions (PRs: #763, #812)// These will throw TypeErrors: expect(Symbol()).to.be.empty; expect(function() {}).to.be.empty; expect(true).to.be.empty; expect(1).to.be.empty
-
Assertion subject (
obj
) changes when usingownProperty
orown.property
and thus enables chaining. (Related Issues: #281, PRs: #641)expect({val: 20}).to.have.own.property('val').above(10);
- The
utils
(second argument passed to thechai.use
callback function) no longer exports thegetPathValue
function. If you want to use that please use thepathval
module, which is what chai uses internally now. (Related Issues: #457, #737, PRs: #830)
New Features
-
Throw when non-existent property is read. (Related Issues: #407, #766 PRs: #721, #770) This is a potentially breaking change. Your build will fail if you have typos in your property assertions Before
4.x.x
when using property assertions they would not throw an error if you wrote it incorrectly. The example below, for example, would pass:expect(true).to.be.ture; // Oops, typo, now Chai will throw an Error
Since this implementation depends on ES6
Proxies
it will only work on platforms that support it.This property can be enabled (default) or disabled through the
config.useProxy
property, for example:chai.config.useProxy = false; // disable use of Proxy
-
Add fix suggestions when accessing a nonexistent property in proxy mode. (Related Issues: #771, PRs: #782) When a nonexistent property is accessed in proxy mode, Chai will compute the levenshtein distance to all possible properties in order to suggest the best fix to the user.
expect(false).to.be.fals; // Error: Invalid Chai property: fals. Did you mean "false"? expect('foo').to.be.undefind; // Error: Invalid Chai property: undefind. Did you mean "undefined"? // If the Levenshtein distance between the word and any Chai property is greater than 4, no fix will be suggested expect('foo').to.be.fdsakfdsafsagsadgagsdfasf // error thrown, no fix suggested
-
When non-chainable methods (including overwritten non-chainable methods) are used incorrectly an error will be thrown with a helpful error message. (PRs: #789)
expect(true).to.equal.true; // Invalid Chai property: equal.true. See docs for proper usage of "equal".
-
Add a new configuration setting that describes which keys will be ignored when checking for non-existing properties on an assertion before throwing an error. Since this implementation depends on ES6
Proxies
it will only work on platforms that support it. Also, if you disableconfig.useProxy
, this setting will have no effect. *(Related Issues: #765, PRs: #774)chai.config.proxyExcludedKeys.push('nonExistingProp'); expect('my string').to.nonExistingProp; // This won't throw an error now
-
Add script that registers should as a side-effect. (Related Issues: #594, #693 PRs: #604)
// You can now write: import 'chai/should'; // as opposed to: import {should} from 'chai'; should();
You can also register should via a
mocha
option:mocha --require chai/should
. -
The
change
assertion accepts a function as object. (Related Issues: #544, PRs: #607)// Now you can also check if the return value of a function changes, for example assert.increases( someOperation, () => getSomething().length )
-
You can also assert for a delta using the
by
assertion alongside thechange
,increase
anddecrease
assertions. (Related Issues: #339, PRs: #621)
// You can use `.by` to assert the amount you want something to change
var obj = { val: 10 };
var increaseByTwo = function() { obj.val += 2 };
var decreaseByTwo = function() { obj.val -= 2 };
var increaseByThree = function() { obj.val += 3 };
expect(increaseByThree).to.change(obj, 'val').by(3);
expect(increaseByTwo).to.increase(obj, 'val').by(2);
expect(decreaseByTwo).to.decrease(obj, 'val').by(2);
// Please notice that if you want to assert something did change but not by some amount you need to use `.not` **after** the `change` related assertion
// Take a look at the examples below:
expect(increaseByThree).to.change(obj, 'val').but.not.by(5)
expect(increaseByTwo).to.increase(obj, 'val').but.not.by(1)
expect(decreaseByTwo).to.decrease(obj, 'val').but.not.by(1)
- The
.keys
assertion can now operate onmap
s andset
s. (Related Issues: #632, PRs: #633, #668)
// The `.keys` assertion now works on `map`s and `set`s natively, like the examples below:
expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.key({objKey: 'value'});
expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.any.keys([{objKey: 'value'}, {anotherKey: 'anotherValue'}]);
expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.keys('firstKey', 1);
expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.keys('foo');
// You can also use `.deep` when asserting agains `Map`s and `Set`s
expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.any.deep.keys([{objKey: 'value'}, {anotherKey: 'anotherValue'}]);
expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.deep.keys('firstKey', 1);
expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.deep.keys('foo');
-
Add compatibility with strict mode. (Related Issues: #578, PRs: #665)
// This means you can now run your code with the `--use_strict` flag on Node // If want to understand more about this please read the issue related to this change
-
Add
does
andbut
as new no-op assertion. (Related Issues: #700, #339 PRs: #621, #701)// You can now write assertions forming phrases with these two new words: expect(increaseByThree).to.change(obj, 'val').but.not.by(5); expect(foobar).to.have.property("baz").which.does.not.have.property("thing");
-
Allow
use
to be imported using new ES6 module syntax. (Related Issues: #718, PRs: #724)// You can now import `use` using the ES6 module syntax, like the example below: import sinonChai from "sinon-chai"; import {expect, use} from "chai"; use(sinonChai);
You can also use
require
alongside the new ES6 destructuring feature:const sinonChai = require('sinon-chai'); const {expect, use} = require("chai"); use(sinonChai);
-
Add ordered flag for members assertion. (Related Issues: #717, PRs: #728)
// You can now use the `ordered` flag to assert the order of elements when using the `members` assertion: expect([1, 2, 3]).to.include.ordered.members([1, 2]); // This passes expect([1, 2, 3]).to.include.ordered.members([2, 3]); // This will fail! Read the docs to know more.
-
Add
.own
flag to.property
assertion. It does the same thing as.ownProperty
and cannot be used alongisde the new.nested
flag. (Related Issues: #795, PRs: #810)expect({a: 1}).to.have.own.property('a'); // The example below will thrown an Error expect({a: {b: 1}}).to.have.own.nested.property('a.b', 1);
-
Add
.deep
support to.property
assertion. (Related Issues: #795, PRs: #810)expect({ foo: { bar: 'baz' } }).to.have.deep.own.property('foo', { bar: 'baz' }); expect({ foo: { bar: { baz: 'quux' } } }).to.have.deep.nested.property('foo.bar', { baz: 'quux' });
-
The
.empty
assertion will now work with ES6 collections (PRs: #763, #812, #814) Please notice that this assertion will throw an error when it is passed aWeakMap
orWeakSet
.expect(new Set()).to.be.empty; expect(new Map()).to.be.empty; // The examples below will throw a TypeError: expect(new WeakSet()).to.be.empty; expect(new WeakMap()).to.be.empty;
Bug Fixes
- Fix missing msg argument for change related assertions. (Related Issues: None, PRs: #606)
- The addMethod function returns a new assertion with flags copied over instead of
this
. (Related Issues: #562, #684, #723, PRs: #642, #660) - Fix stacktraces for overwritten properties and methods. (Related Issues: #659, #661)
- Fix bug when testing Symbol equality with should syntax. (Related Issues: #669, PRs: #672)
- Fix bug when asserting some valid ES6 keys. (Related Issues: #674, PRs: #676)
- Fix bug caused when custom inspect method is used and this method calls stylize. (PRs: #680)
- Fix ownProperty on objects with no prototype. (Related Issues: #688, PRs: #689)
- Fix swapped expected and actual results for the
.members
assertion. (Related Issues: #511, PRs: #702) - Fix
same.members
to properly handle duplicates by treating each one as a unique member. (Related Issues: #590, PRs: #739) - Fix deep.have.same.members() that was not printing a diff. (PRs: #509)
- Diff will be shown for assert’s equal and notEqual methods. (Related Issues: #790, PRs: #794)
- The
overwriteMethod
,overwriteProperty
,addChainableMethod
,overwriteChainableMethod
functions will return new assertion with flags copied over instead of this. (Related Issues: #562, #642, #791, PRs: #799)
3.5.0 / 2016-01-28
Version 3.5.0
For assert
fans: you now have assert.includeDeepMembers()
which matches expect().to.include.deep.members()
and .should.include.deep.members()
!
This release also includes a variety of small bugfixes and documentation fixes. Most notably, we are now governed by a Code Of Conduct - which gives Chai contributors (including those who files issues, work on code, or documentation, or even just hang out on our Slack & Gitter channels) safety from harassment and discrimination.
Full changes below:
Community Contributions
- #589 Add
assert.includeDeepMembers()
. By @qbolec - #570 Fix error when using $ signs in messages. By @jurko-gospodnetic
- #575 Clean browser before karma in Makefile. By @lucasfcosta
- #577 Fix non ES5 compliant regexp. By @zetaben
- #579 Update karma for build. By @greenkeeperio-bot
Documentation fixes
- #561 (docs) Added JSDocs to ‘should’ interface. By @DavidBR-SW
- #565 Add Code of Conduct. By @keithamus
- #566 Fix typo in .change() docs. By @lizhengnacl
- #567 Add badges for Slack and Gitter. By @outsideris
- #574 clarified assert.isObject & assert.isNotObject documentation. By @gdelmas
3.4.2 / 2015-11-15
Version 3.4.2
This is a small documentation bug fix release - it adds extra metatags to each public method to allow us to generate the docs easier for the website.
Community Contributions
Documentation fixes
- #552 (docs) Add namespace to all public methods. By @keithamus
3.4.1 / 2015-11-07
Version 3.4.1
This is a small documentation bug fix release - it just fixes a couple of issues with the documentation.
Community Contributions
Documentation fixes
- #546 Remove incorrect
.throws()
example. By @Pklong - #547 Fix documentation syntax errors. By @keithamus
3.4.0 / 2015-10-21
Version 3.4.0
This release improves some confusing error messages, and adds some new assertions. Key points:
- Feature: New assertion:
expect(1).oneOf([1,2,3])
- for asserting that a given value is one of a set. - Feature:
.include()
(and variants) will now give better error messages for bad object types. Beforeexpect(undefined).to.include(1)
would say “expected undefined to include 1”, now says “object tested must be an array, an object, or a string but undefined given” - Feature:
.throw()
(and variants) can now better determine the Error types, for exampleexpect(foo).to.throw(node_assert.AssertionError)
now works. - Feature:
.closeTo
is now aliased as.approximately
- BugFix:
.empty
changes from 3.3.0 have been reverted, as they caused breaking changes to arrays which manually set keys.
Community Contributions
Code Features & Fixes
- #503 Checking that argument given to expect is of the right type when using with include. By @astorije
- #446 Make chai able to cope with AssertionErrors raised from node’s assert. By @danielbprice
- #527 Added approximately alias to close to. By @danielbprice
- #534
expect(inList).to.be.oneOf
assertion. By @Droogans - #538 Revert .empty assertion change from PR #499. By @tusbar
Documentation fixes
- #521 document how the
new Error
type gets detected by thea
/an
matcher. By @jurko-gospodnetic - #522 Fixes spelling error “everthing” -> “everything”. By @austinpray
- #529 Fix assert lengthOf example. By @dxuehu
- #533 Fix typo in README.md. By @astorije
3.3.0 / 2015-09-08
Version 3.3.0
This release adds some new assertions and fixes some quite important, long standing bugs. Here are the cliff notes:
- Bugfix: Property assertions that fail now show a stack trace!
- Bugfix: If you’ve used the
frozen
,sealed
orextensible
assertions to test primitives (e.g.expect(1).to.be.frozen
), you may have noticed that in older browsers (ES5) these fail, and in new ones (ES6) they pass. They have now been fixed to consistently pass - The
assert
interface has been given the following new methods, to align better with other interfaces:,assert.isAtMost
,assert.isAtLeast
,assert.isNotTrue
,assert.isNotFalse
.
Community Contributions
Code Features & Fixes
- #494 Add
assert.isNotTrue
andassert.isNotFalse
. By @cezarykluczynski - #496
frozen
/extensible
/sealed
assertions behave the same in ES6 and ES5 environments. By @astorije - #499 Simplify the
.empty
assertion. By @Daveloper87 - #500 Add
assert.isAtMost
andassert.isAtLeast
. By @wraithan - #512 fixed expect(‘’).to.contain(‘’) so it passes. By @dereke
- #514 Fix stack trace tracking for property assertions. By @kpdecker
Documentation fixes
- #495 Correct misplaced docs for assertions (
isBelow
,isAbove
,isTrue
). By @cezarykluczynski
3.2.0 / 2015-07-19
Version 3.2.0
This release fixes a bug with the previous additions in 3.1.0
. assert.frozen
/expect().to.be.frozen
/.should.be.frozen
all accidentally called Object.isSealed()
instead. Now they correctly call Object.isFrozen()
.
If you’re using these features, please upgrade immediately.
It also adds aliases for a lot of assert
methods:
- expect/should..respondTo: respondsTo
- expect/should..satisfy: satisfies
- assert.ok: assert.isOk
- assert.notOk: assert.isNotOk
- assert.extensible: assert.isExtensible
- assert.notExtensible: assert.isNotExtensible
- assert.sealed: assert.isSealed
- assert.notSealed: assert.isNotSealed
- assert.frozen: assert.isFrozen
- assert.notFrozen: assert.isNotFrozen
Community Contributions
Code Features & Fixes
- #482 Re-encrypt travis API key By @keithamus
- #482 Add respondsTo and satisfies as aliases By @couchand
- #485 Fixing a typo in the
getProperties()
utility By @jluchiji - #486 Added links to contribution guidelines to README By @jluchiji
- #489 Various work on aliases By @astorije
- #490 Fix wrong call to the underlying method when checking if an object is frozen By @astorije
3.1.0 / 2015-07-16
Version 3.1.0
This release adds assertions for extensibility/freezing/sealing on objects:
assert.extensible({});
assert.notExtensible(Object.preventExtensions({}));
expect(Object.preventExtensions({})).to.not.be.extensible;
Object.preventExtensions({}).should.not.be.extensible;
assert.notSealed({});
assert.sealed(Object.seal({}));
expect(Object.seal({})).to.be.sealed;
Object.seal({}).should.be.sealed;
assert.notFrozen({});
assert.frozen(Object.freeze({}));
expect(Object.freeze({})).to.be.frozen;
Object.freeze({}).should.be.frozen;
It also adds assertions for checking if a number is NaN:
assert.isNaN(NaN);
assert.isNotNaN(5);
expect(NaN).to.be.NaN;
expect(5).to.not.be.NaN;
NaN.should.be.NaN;
5.should.not.be.NaN;
Community Contributions
Code Features & Fixes
- #480 Added tests and expectations for NaN By @bradcypert
- #479 Assertions to test if objects are extensible/sealed/frozen. By @matthewlucock
- #468 Remove moot
version
property from bower.json. By @kkirsche
4.0.0 / 2017-05-26
Version 4.0.0
4.0.0
4.0 has been a huge undertaking by the chai community! A lot has changed to ensure Chai 4 is a stable, reliable, well documented codebase. Here are just some of the major improvements:
-
almost all documentation has been rewritten, with detailed instructions on how assertions work, which flags they can be combined with and the best practices for how to use them.
-
deep equality has been rewritten from the ground up to support ES6 types like
Map
andSet
, and better support existing types. It is now also much, much faster than before and allows us to bring some great improvements in upcoming releases. -
we have made sure the
deep
flag now only ever does deep equality. Beforehand, it would sometimes also be used to test nested properties (for exampleexpect(foo).to.have.deep.property('bar.baz')
. For nested assertions, please now use the.nested
flag. -
many assertions have become more strict, which means you get better error messages explaining where things have gone wrong. For the most part, this wont mean error messages where there weren’t error messages before, but it will mean better error messages to replace the, sometimes cryptic, default
TypeError
messages. -
we’ve added detections and helpful error messages for common mistakes and typos. The error messages will, in some cases, point you to documentation or in other cases suggest alternatives. These messages will continue to be improved in future releases, so let us know if you have any suggestions!
Breaking Changes
- We no longer support Node v0.10 and v0.12 (since their LTS has ended) (PRs: #816, #901)
-
Instead of allowing the user to write the path of a property, now the deep flag performs a deep equality comparison when used with the
.property
assertion. If you want the old behavior of using the dot or bracket notation to denote the property you want to assert against you can use the new.nested
flag. (Related Issues: #745, #743, PRs: #758, #757)const obj = {a: 1}; // The `.deep` flag now does deep equality comparisons expect({foo: obj}).to.have.deep.property('foo', {a: 1}); // Use the `nested` flag if you want to assert against a nested property using the bracket or dot notation expect({foo: obj}).to.have.nested.property('foo.a', 1); // You can also use both flags combined const obj2 = {a: {b: 2}}; expect({foo: obj2}).to.have.deep.nested.property('foo.a', {b: 2});
Please notice that the old methods which used the old behavior of the
deep
flag on theassert
interface have been renamed. They all have had thedeep
word changed by thenested
word. If you want to know more about this please take a look at #757. -
Previously,
expect(obj).not.property(name, val)
would throw an Error ifobj
didn’t have a property namedname
. This change causes the assertion to pass instead. Theassert.propertyNotVal
andassert.deepPropertyNotVal
assertions were renamed toassert.notPropertyVal
andassert.notDeepPropertyVal
, respectively. (Related Issues: #16, #743, #758) -
You can now use the
deep
flag for the.include
assertion in order to perform adeep
equality check to see if something is included on thetarget
. Previously,.include
was using strict equality (===
) for non-negated property inclusion, butdeep
equality for negated property inclusion and array inclusion. This change causes the .include assertion to always use strict equality unless the deep flag is set. Please take a look at this comment if you want to know more about it. (Related Issues: #743, PRs: #760, #761)const obj = {a: 1}; expect([obj]).to.deep.include({a:1}); expect({foo: obj}).to.deep.include({foo: {a:1}});
-
Fix unstable behavior of the
NaN
assertion. Now we use the suggested ES6 implementation. The new implementation is now more correct, strict and simple. While the old one threw false positives, the new implementation only checks if something isNaN
(or not if the.not
flag is used) and nothing else. (Related Issues: #498, #682, #681, PRs: #508)// Only `NaN` will be considered to be `NaN` and nothing else expect(NaN).to.be.NaN; // Anything that is not `NaN` cannot be considered as `NaN` expect('randomString').not.to.be.NaN; expect(true).not.to.be.NaN; expect({}).not.to.be.NaN; expect(4).not.to.be.NaN;
-
The Typed Array types are now truncated if they’re too long (in this case, if they exceed the
truncateThreshold
value on theconfig
). (Related Issues: #441, PRs: #576)var arr = []; for (var i = 1; i <= 1000; i++) { arr.push(i); } // The assertion below will truncate the diff shown and the enormous typed array will be shown as: // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... ] instead of printing the whole typed array chai.expect(new Float32Array(100)).to.equal(1);
-
The assertions:
within
,above
,least
,below
,most
,increase
,decrease
will throw an error if the assertion’s target or arguments are not numbers. (Related Issues: #691, PRs: #692, #796)// These will throw errors, for example: expect(null).to.be.within(0, 1); expect(null).to.be.above(10); expect(null).to.be.at.least(20); expect(null).to.be.below(20); expect(null).to.be.at.most(20); expect(null).to.increase.by(20); expect(null).to.decrease.by(20); // This will not: expect('string').to.have.a.lengthOf.at.least(3);
-
Previously,
expect(obj).not.ownProperty(name, val)
would throw an Error if obj didn’t have an own property (non-inherited) named name. This change causes the assertion to pass instead. (Related Issues: #795, #, PRs: #744, #810)*expect({ foo: 'baz' }).to.not.have.own.property('quux', 'baz');
-
The
.empty
assertion will now throw when it is passed non-string primitives and functions (PRs: #763, #812)// These will throw TypeErrors: expect(Symbol()).to.be.empty; expect(function() {}).to.be.empty; expect(true).to.be.empty; expect(1).to.be.empty
-
Assertion subject (
obj
) changes when usingownProperty
orown.property
and thus enables chaining. (Related Issues: #281, PRs: #641)expect({val: 20}).to.have.own.property('val').above(10);
- The
.change
,.increase
, and.decrease
assertions changed from chainable method assertions to method assertions. They don’t have any chaining behavior, and there’s no generic semantic benefit to chaining them. (Related Issues: #917, PRs: #925)
// This will not work anymore because there is no benefit to chaining these assertions:
expect(function() {}).to.change.by(2)
expect(function() {}).to.increase.by(2)
expect(function() {}).to.decrease.by(2)
-
The
utils
(second argument passed to thechai.use
callback function) no longer exports thegetPathValue
function. If you want to use that please use thepathval
module, which is what chai uses internally now. (Related Issues: #457, #737, PRs: #830) -
(For plugin authors) Throw when calling
_super
onoverwriteMethod
if the method being overwritten isundefined
. Currently if the method you are trying to overwrite is not defined and your new method calls_super
it will throw anError
.(Related Issues: #467, PRs: #528) Before this change, calling_super
would simply returnthis
.// Considering the method `imaginaryMethod` does not exist, this would throw an error for example: chai.use(function (chai, utilities) { chai.Assertion.overwriteMethod('imaginaryMethod', function (_super) { return function () { _super.apply(this, arguments); } }); }); // This will throw an error since you are calling `_super` which should be a method (in this case, the overwritten assertion) that does not exist expect('anything').to.imaginaryMethod();
-
(For plugin authors) Now
showDiff
is turned on by default whenever theshowDiff
flag is anything other thanfalse
. This issue will mostly affect plugin creators or anyone that made extensions to the core, since this affects theAssertion.assert
method. (Related Issues: #574, PRs: #515)// Now whenever you call `Assertion.assert` with anything that is not false for the `showDiff` flag it will be true // The assertion error that was thrown will have the `showDiff` flag turned on since it was not passed to the `assert` method try { new chai.Assertion().assert( 'one' === 'two' , 'expected #{this} to equal #{exp}' , 'expected #{this} to not equal #{act}' , 'one' , 'two' ); } catch(e) { assert.isTrue(e.showDiff); } // The assertion error that was thrown will have the `showDiff` flag turned off since here we passed `false` explicitly try { new chai.Assertion().assert( 'one' === 'two' , 'expected #{this} to equal #{exp}' , 'expected #{this} to not equal #{act}' , 'one' , 'two' , false ); } catch(e) { assert.isFalse(e.showDiff); }
New Features
-
Throw when non-existent property is read. (Related Issues: #407, #766 PRs: #721, #770) This is a potentially breaking change. Your build will fail if you have typos in your property assertions Before
4.x.x
when using property assertions they would not throw an error if you wrote it incorrectly. The example below, for example, would pass:expect(true).to.be.ture; // Oops, typo, now Chai will throw an Error
Since this implementation depends on ES6
Proxies
it will only work on platforms that support it.This property can be enabled (default) or disabled through the
config.useProxy
property, for example:chai.config.useProxy = false; // disable use of Proxy
-
Add fix suggestions when accessing a nonexistent property in proxy mode. (Related Issues: #771, PRs: #782) When a nonexistent property is accessed in proxy mode, Chai will compute the levenshtein distance to all possible properties in order to suggest the best fix to the user.
expect(false).to.be.fals; // Error: Invalid Chai property: fals. Did you mean "false"? expect('foo').to.be.undefind; // Error: Invalid Chai property: undefind. Did you mean "undefined"? // If the Levenshtein distance between the word and any Chai property is greater than 4, no fix will be suggested expect('foo').to.be.fdsakfdsafsagsadgagsdfasf // error thrown, no fix suggested
-
When non-chainable methods (including overwritten non-chainable methods) are used incorrectly an error will be thrown with a helpful error message. (PRs: #789)
expect(true).to.equal.true; // Invalid Chai property: equal.true. See docs for proper usage of "equal".
-
Add a new configuration setting that describes which keys will be ignored when checking for non-existing properties on an assertion before throwing an error. Since this implementation depends on ES6
Proxies
it will only work on platforms that support it. Also, if you disableconfig.useProxy
, this setting will have no effect. (Related Issues: #765, PRs: #774)chai.config.proxyExcludedKeys.push('nonExistingProp'); expect('my string').to.nonExistingProp; // This won't throw an error now
-
Add script that registers should as a side-effect. (Related Issues: #594, #693 PRs: #604)
// You can now write: import 'chai/should'; // as opposed to: import {should} from 'chai'; should();
You can also register should via a
mocha
option:mocha --require chai/should
. -
The
change
assertion accepts a function as object. (Related Issues: #544, PRs: #607)// Now you can also check if the return value of a function changes, for example assert.increases( someOperation, () => getSomething().length )
-
You can also assert for a delta using the
by
assertion alongside thechange
,increase
anddecrease
assertions. (Related Issues: #339, PRs: #621)
// You can use `.by` to assert the amount you want something to change
var obj = { val: 10 };
var increaseByTwo = function() { obj.val += 2 };
var decreaseByTwo = function() { obj.val -= 2 };
var increaseByThree = function() { obj.val += 3 };
expect(increaseByThree).to.change(obj, 'val').by(3);
expect(increaseByTwo).to.increase(obj, 'val').by(2);
expect(decreaseByTwo).to.decrease(obj, 'val').by(2);
// Please notice that if you want to assert something did change but not by some amount you need to use `.not` **after** the `change` related assertion
// Take a look at the examples below:
expect(increaseByThree).to.change(obj, 'val').but.not.by(5)
expect(increaseByTwo).to.increase(obj, 'val').but.not.by(1)
expect(decreaseByTwo).to.decrease(obj, 'val').but.not.by(1)
- The
.keys
assertion can now operate onmap
s andset
s. (Related Issues: #632, PRs: #633, #668)
// The `.keys` assertion now works on `map`s and `set`s natively, like the examples below:
expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.key({objKey: 'value'});
expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.any.keys([{objKey: 'value'}, {anotherKey: 'anotherValue'}]);
expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.keys('firstKey', 1);
expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.keys('foo');
// You can also use `.deep` when asserting agains `Map`s and `Set`s
expect(new Map([[{objKey: 'value'}, 'value'], [1, 2]])).to.contain.any.deep.keys([{objKey: 'value'}, {anotherKey: 'anotherValue'}]);
expect(new Map([['firstKey', 'firstValue'], [1, 2]])).to.contain.all.deep.keys('firstKey', 1);
expect(new Set([['foo', 'bar'], ['example', 1]])).to.have.any.deep.keys('foo');
-
Add compatibility with strict mode. (Related Issues: #578, PRs: #665)
// This means you can now run your code with the `--use_strict` flag on Node // If want to understand more about this please read the issue related to this change
-
Add
does
andbut
as new no-op assertion. (Related Issues: #700, #339 PRs: #621, #701)// You can now write assertions forming phrases with these two new words: expect(increaseByThree).to.change(obj, 'val').but.not.by(5); expect(foobar).to.have.property("baz").which.does.not.have.property("thing");
-
Allow
use
to be imported using new ES6 module syntax. (Related Issues: #718, PRs: #724)// You can now import `use` using the ES6 module syntax, like the example below: import sinonChai from "sinon-chai"; import {expect, use} from "chai"; use(sinonChai);
You can also use
require
alongside the new ES6 destructuring feature:const sinonChai = require('sinon-chai'); const {expect, use} = require("chai"); use(sinonChai);
-
Add ordered flag for members assertion. (Related Issues: #717, PRs: #728)
// You can now use the `ordered` flag to assert the order of elements when using the `members` assertion: expect([1, 2, 3]).to.include.ordered.members([1, 2]); // This passes expect([1, 2, 3]).to.include.ordered.members([2, 3]); // This will fail! Read the docs to know more.
-
Add
.own
flag to.property
assertion. It does the same thing as.ownProperty
and cannot be used alongisde the new.nested
flag. (Related Issues: #795, PRs: #810)expect({a: 1}).to.have.own.property('a'); // The example below will thrown an Error expect({a: {b: 1}}).to.have.own.nested.property('a.b', 1);
-
Add
.deep
support to.property
assertion. (Related Issues: #795, PRs: #810)expect({ foo: { bar: 'baz' } }).to.have.deep.own.property('foo', { bar: 'baz' }); expect({ foo: { bar: { baz: 'quux' } } }).to.have.deep.nested.property('foo.bar', { baz: 'quux' });
-
The
.empty
assertion will now work with ES6 collections (PRs: #763, #812, #814) Please notice that this assertion will throw an error when it is passed aWeakMap
orWeakSet
.expect(new Set()).to.be.empty; expect(new Map()).to.be.empty; // The examples below will throw a TypeError: expect(new WeakSet()).to.be.empty; expect(new WeakMap()).to.be.empty;
-
Add script that registers
should
as a side-effect. This change allows you to registershould
via a mocha option by using:mocha spec.js -r chai/register-should
and also allows you to register the testing style globally. (Issues: #693, PRs: #868)require('chai/register-should'); // Using Should style
-
Add script that registers
assert
as a side-effect. This change allows you to registerassert
via a mocha option by using:mocha spec.js -r chai/register-assert
(Issues: #693, PRs: #868, #872)
require('chai/register-assert'); // Using Assert style
-
Add script that registers
expect
as a side-effect. This change allows you to registerexpect
via a mocha option by using:mocha spec.js -r chai/register-expect
(Issues: #693, PRs: #868, #872)require('chai/register-expect'); // Using Expect style
-
When the
length
assertion is chained directly off of an uninvoked method, it referencesfunction
’s built-inlength
property instead of Chai’slength
assertion. This commit adds a guard to Chai methods to detect this problem and throw a helpful error message that advises the user on how to correct it. (Issues: #684, #841, PRs: #897) -
Allows the
lockSsfi
flag to be set when creating new Assertion. This flag controls whether or not the givenssfi
flag should retain its current value, even as assertions are chained off of this object. This is usually set totrue
when creating a new assertion from within another assertion. It’s also temporarily set totrue
before an overwritten assertion gets called by the overwriting assertion. (Issues: #878, #904, PRs: #922)// This will lock the stack stack function from this line on // The SSFI is the reference to the starting point for removing irrelevant frames from the stack trace new Assertion(obj, msg, ssfi, true).to.have.property('length')
-
The
nestedInclude
,deepNestedInclude
,ownInclude
anddeepOwnInclude
assertions and there negated pairs were added to theassert
interface. (Issues: #905, PRs: #964)// '[]' and '.' in property names can be escaped using double backslashes. assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'}); assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'}); assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}}); assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}}); assert.ownInclude({ a: 1 }, { a: 1 }); assert.notOwnInclude({ a: 1 }, { b: 2 }); assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}}); assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
Bug Fixes
- Fix missing msg argument for change related assertions. (Related Issues: None, PRs: #606)
- The addMethod function returns a new assertion with flags copied over instead of
this
. (Related Issues: #562, #684, #723, PRs: #642, #660) - Fix stacktraces for overwritten properties and methods. (Related Issues: #659, #661)
- Fix bug when testing Symbol equality with should syntax. (Related Issues: #669, PRs: #672)
- Fix bug when asserting some valid ES6 keys. (Related Issues: #674, PRs: #676)
- Fix bug caused when custom inspect method is used and this method calls stylize. (PRs: #680)
- Fix ownProperty on objects with no prototype. (Related Issues: #688, PRs: #689)
- Fix swapped expected and actual results for the
.members
assertion. (Related Issues: #511, PRs: #702) - Fix
same.members
to properly handle duplicates by treating each one as a unique member. (Related Issues: #590, PRs: #739) - Fix deep.have.same.members() that was not printing a diff. (PRs: #509)
- Diff will be shown for assert’s equal and notEqual methods. (Related Issues: #790, PRs: #794)
- The
overwriteMethod
,overwriteProperty
,addChainableMethod
,overwriteChainableMethod
functions will return new assertion with flags copied over instead of this. (Related Issues: #562, #642, #791, PRs: #799) - Proxy-related implementation frames were showing up in the stack traces for failed property assertions. Now we remove them by setting the proxy getter (instead of the property getter) as the starting point to remove all implementation frames. (PRs: #884)
- Negated
keys
assertions will now consider size of sets. (Related Issues: #919, PRs: #924) - Whenever passed something that is not an instance of a function, the instanceof assertion will now throw an error informing the user that he should pass a constructor to this assertion, but instead he has passed
. _(Related Issues: #893, PRs: #924)_ - Fix all issues on expect/should interfaces that were causing implementation frames to leak through. Also improve the internal Chai error test helper to validate stack traces. (Issues: #878, #904, PRs: #922)
- This fixes custom messages not always being respected. (Issues: #922, #947, #904, PRs: #916, #923)
- Fix PhantomJS 1.x incompatibility (Issues: #966, PRs: #890)
3.0.0 / 2015-06-04
Version 3.0.0
This release contains some small breaking changes. Most people are unlikely to notice them - but here are the breaking changes:
- Switched from “Component” builds to “Browserify” builds for Browsers. If
you’re using RequireJS with Chai, you might notice a change (chai used to
be a global, now it won’t be - instead you’ll have to
require
it). .has.property('foo', undefined)
will now specifically test to make sure that the value'foo'
is actually undefined - before it simply tested that the key existed (but could have a value)..to.be.a('type')
has changed to support more types, including ES6 types such as'promise'
,'symbol'
,'float32array'
etc, this also means using ES6’sSymbol.toStringTag
affects the behaviour.to.be.a()
. In addition to this, Errors have the type of'error'
.assert.ifError()
now follows Node’sassert.ifError()
behaviour - in other words, if the first argument is truthy, it’ll throw it.- ReleaseNotes.md is no longer maintained, see the Github Releases Page instead.
- History.md is no longer maintained, see the Github Commit Log instead.
Community Contributions
Code Features & Fixes
- #403
assert.ifError()
behaves like Node.js: it throws if the first argument is present. By @cjqed - #419 assertion-error bumped to
^1.0.1
By @keithamus (special thanks to @simonzack for his work on assertion-error) - #421 replace type.js with type-detect module. By @Charminbear
- #439 Add
.matches()
as alias for.match()
. By @thejameskyle - #451 Switch to using Browserify for the build system. By @csnover
- #452
.property('foo', undefined)
now actually checks to see ifobj.foo === undefined
(before it did not). By @onefifth - #460 Automate release process as much as possible By @keithamus
Documentation fixes
- #397 Improve docs for
.assert()
By @astorije - #401 Add some badges to the Readme. By @keithamus
- #424 Fix typo in docs for
.keys()
By @astorije - #429 Deprecate
.length(n)
from the docs - use.lengthOf(n)
instead. By @valscion - #444 Change
.length(n)
examples to.lengthOf(n)
instead. By @keithamus - #458 Remove stray character in
assert.notInclude
docs By @BinaryMuse
2.3.0 / 2015-04-26
Version 2.3.0
Added ownPropertyDescriptor
assertion:
expect('test').to.have.ownPropertyDescriptor('length');
expect('test').to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 4 });
expect('test').not.to.have.ownPropertyDescriptor('length', { enumerable: false, configurable: false, writable: false, value: 3 });
expect('test').ownPropertyDescriptor('length').to.have.property('enumerable', false);
expect('test').ownPropertyDescriptor('length').to.have.keys('value');
Community Contributions
Code Features & Fixes
- #408 Add
ownPropertyDescriptor
assertion. By @ljharb - #422 Improve ownPropertyDescriptor tests. By @ljharb
Documentation fixes
2.2.0 / 2015-03-26
Version 2.2.0
Deep property strings can now be escaped using \\
- for example:
var deepCss = { '.link': { '[target]': 42 }};
expect(deepCss).to.have.deep.property('\\.link.\\[target\\]', 42)
Community Contributions
Code Features & Fixes
Documentation fixes
- #405 Tweak documentation around deep property escaping. By @keithamus
2.1.2 / 2015-03-15
Version 2.1.2
A minor bug fix. No new features.
Community Contributions
Code Features & Fixes
2.1.1 / 2015-03-04
Version 2.1.1
Two minor bugfixes. No new features.
Community Contributions
Code Features & Fixes
- #385 Fix a bug (also described in
#387) where
deep.property
would not work with single key names. By @eldritch-fossicker - #379 Fix bug where tools which overwrite primitive prototypes, such as Babel or core-js would fail. By @dcneiner
Documentation fixes
- #382 Add doc for showDiff argument in assert. By @astorije
- #383 Improve wording for truncateTreshold docs By @gurdiga
- #381 Improve wording for assert.empty docs By @astorije
2.1.0 / 2015-02-23
Version 2.1.0
Small release; fixes an issue where the Chai lib was incorrectly reporting the version number.
Adds new should.fail()
and expect.fail()
methods, which are convenience
methods to throw Assertion Errors.
Community Contributions
Code Features & Fixes
2.0.0 / 2015-02-09
Version 2.0.0
Unfortunately with 1.10.0 - compatibility broke with older versions because of
the addChainableNoop
. This change has been reverted.
Any plugins using addChainableNoop
should cease to do so.
Any developers wishing for this behaviour can use dirty-chai by @joshperry
Community Contributions
Code Features & Fixes
- #361
.keys()
now accepts Objects, extracting keys from them. By @gregglind - #359
.keys()
no longer mutates passed arrays. By @gregglind - #349 Add a new chainable keyword -
.which
. By @toastynerd - #333 Add
.change
,.increase
and.decrease
assertions. By @cmpolis - #335
chai.util
is now exposed @DingoEatingFuzz - #328 Add
.includes
and.contains
aliases (for.include
and.contain
). By @lo1tuma - #313 Add
.any.keys()
and.all.keys()
qualifiers. By @cjqed - #312 Add
assert.sameDeepMembers()
. By @cjqed - #311 Add
assert.isAbove()
andassert.isBelow()
. By @cjqed - #308
property
anddeep.property
now pass if a value is set toundefined
. By @prodatakey - #309 optimize deep equal in Arrays. By @ericdouglas
- #306 revert #297 - allowing lint-friendly tests. By @keithamus
Documentation fixes
- #357 Copyright year updated in docs. By @danilovaz
- #325 Fix documentation for overwriteChainableMethod. By @chasenlehara
- #334 Typo fix. By @hurrymaplelad
- #317 Typo fix. By @jasonkarns
- #318 Typo fix. By @jasonkarns
- #316 Typo fix. By @jasonkarns
1.10.0 / 2014-11-10
Version 1.10.0
The following changes are required if you are upgrading from the previous version:
- Users:
- No changes required
- Plugin Developers:
- Review
addChainableNoop
notes below.
- Review
- Core Contributors:
- Refresh
node_modules
folder for updated dependencies.
- Refresh
Noop Function for Terminating Assertion Properties
The following assertions can now also be used in the function-call form:
- ok
- true
- false
- null
- undefined
- exist
- empty
- arguments
- Arguments
The above list of assertions are property getters that assert immediately on access. Because of that, they were written to be used by terminating the assertion chain with a property access.
expect(true).to.be.true;
foo.should.be.ok;
This syntax is definitely aesthetically pleasing but, if you are linting your test code, your linter will complain with an error something like “Expected an assignment or function call and instead saw an expression.” Since the linter doesn’t know about the property getter it assumes this line has no side-effects, and throws a warning in case you made a mistake.
Squelching these errors is not a good solution as test code is getting to be just as important as, if not more than, production code. Catching syntactical errors in tests using static analysis is a great tool to help make sure that your tests are well-defined and free of typos.
A better option was to provide a function-call form for these assertions so that the code’s intent is more clear and the linters stop complaining about something looking off. This form is added in addition to the existing property access form and does not impact existing test code.
expect(true).to.be.true();
foo.should.be.ok();
These forms can also be mixed in any way, these are all functionally identical:
expect(true).to.be.true.and.not.false();
expect(true).to.be.true().and.not.false;
expect(true).to.be.true.and.not.false;
Plugin Authors
If you would like to provide this function-call form for your terminating assertion properties, there is a new function to register these types of asserts. Instead of using addProperty
to register terminating assertions, simply use addChainableNoop
instead; the arguments to both are identical. The latter will make the assertion available in both the attribute and function-call forms and should have no impact on existing users of your plugin.
Community Contributions
- #297 Allow writing lint-friendly tests. @joshperry
- #298 Add check for logging
-0
. @dasilvacontin - #300 Fix #299: the test is defining global variables @julienw
Thank you to all who took time to contribute!
1.9.2 / 2014-09-29
Version 1.9.2
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.
- Refresh
Community Contributions
- #264 Show diff for keys assertions @cjthompson
- #267 Use SVG badges @shinnn
- #268 Allow messages to be functions (sinon-compat) @charlierudolph
- #269 Remove unused argument for #lengthOf @charlierudolph
- #275 Rewrite pretty-printing HTML elements to prevent throwing internal errors @DrRataplan
- #277 Fix assert documentation for #sameMembers @charlierudolph
- #279 closeTo should check value’s type before assertion @mohayonao
- #289 satisfy is called twice @charlierudolph
- #292 resolve conflicts with node-webkit and global usage @boneskull
Thank you to all who took time to contribute!
1.9.1 / 2014-03-19
Version 1.9.1
The following changes are required if you are upgrading from the previous version:
- Users:
- Migrate configuration options to new interface. (see notes)
- Plugin Developers:
- No changes required
- Core Contributors:
- Refresh
node_modules
folder for updated dependencies.
- Refresh
Configuration
There have been requests for changes and additions to the configuration mechanisms
and their impact in the Chai architecture. As such, we have decoupled the
configuration from the Assertion
constructor. This not only allows for centralized
configuration, but will allow us to shift the responsibility from the Assertion
constructor to the assert
interface in future releases.
These changes have been implemented in a non-breaking way, but a depretiation
warning will be presented to users until they migrate. The old config method will
be removed in either v1.11.0
or v2.0.0
, whichever comes first.
Quick Migration
// change this:
chai.Assertion.includeStack = true;
chai.Assertion.showDiff = false;
// ... to this:
chai.config.includeStack = true;
chai.config.showDiff = false;
All Config Options
config.includeStack
- @param {Boolean}
- @default
false
User configurable property, influences whether stack trace is included in
Assertion error message. Default of false
suppresses stack trace in the error
message.
config.showDiff
- @param {Boolean}
- @default
true
User configurable property, influences whether or not the showDiff
flag
should be included in the thrown AssertionErrors. false
will always be false
;
true
will be true when the assertion has requested a diff be shown.
config.truncateThreshold (NEW)
- @param {Number}
- @default
40
User configurable property, sets length threshold for actual and expected values in assertion errors. If this threshold is exceeded, the value is truncated.
Set it to zero if you want to disable truncating altogether.
chai.config.truncateThreshold = 0; // disable truncating
Community Contributions
- #228 Deep equality check for memebers. @duncanbeevers
- #247 Proofreading. @didorellano
- #244 Fix
contain
/include
1.9.0 regression. @leider - #233 Improvements to
ssfi
forassert
interface. @refack - #251 New config option: object display threshold. @romario333
Thank you to all who took time to contribute!
Other Bug Fixes
- #183 Allow
undefined
for actual. (internal api) - Update Karam(+plugins)/Istanbul to most recent versions.
1.9.0 / 2014-01-29
Version 1.9.0
The following changes are required if you are upgrading from the previous version:
- Users:
- No changes required
- Plugin Developers:
- Review #219.
- Core Contributors:
- Refresh
node_modules
folder for updated dependencies.
- Refresh
Community Contributions
- #202 Improve error message for .throw(). @andreineculau
- #217 Chai tests can be run with
--watch
. @demands - #219 Add overwriteChainableMethod utility. @demands
- #224 Return error on throw method to chain on error properties. @vbardales
- #226 Add
has
to language chains. @duncanbeevers - #230 Support
{a:1,b:2}.should.include({a:1})
@jkroso - #231 Update Copyright notices to 2014 @duncanbeevers
- #232 Avoid error instantiation if possible on assert.throws. @laconbass
Thank you to all who took time to contribute!