Skip to content

Releases: chaijs/chai

4.3.1 / 2021-03-02

02 Mar 18:21
Compare
Choose a tag to compare

This releases fixed an engine incompatibility with 4.3.0

The 4.x.x series of releases will be compatible with Node 4.0. Please report any errors found in Node 4 as bugs, and they will be fixed.

The 5.x.x series, when released, will drop support for Node 4.0

This fix also ensures pathval is updated to 1.1.1 to fix CVE-2020-7751

4.3.0 / 2021-02-04

04 Feb 10:58
Compare
Choose a tag to compare

This is a minor release.

Not many changes have got in since the last release but this one contains a very important change (#1257) which will allow jest users to get better diffs. From this release onwards, jest users will be able to see which operator was used in their diffs. The operator is a property of the AssertionError thrown when assertions fail. This flag indicates what kind of comparison was made.

This is also an important change for plugin maintainers. Plugin maintainers will now have access to the operator flag, which they can have access to through an utilmethod calledgetOperator`.

Thanks to all the amazing people that contributed to this release.

New Features

  • Allow contain.oneOf to take an array of possible values (@voliva)
  • Adding operator attribute to assertion error (#1257) (@rpgeeganage)
  • The closeTo error message will now inform the user when a delta is required (@eouw0o83hf)

Docs

  • Add contains flag to oneOf documentation (@voliva)

Tests

  • Make sure that useProxy config is checked in overwriteProperty (@vieiralucas)
  • Add tests for contain.oneOf (@voliva )

Chores

  • Update mocha to version 6.1.4
  • Add node v10 and v12 to ci (@vieiralucas)
  • Drop support for node v4, v6 and v9 (@vieiralucas)
  • Fix sauce config for headless chrome (@meeber)
  • Update dev dependencies (@meeber)
  • Removed phantomjs dependency (#1204)

4.2.0 / 2018-09-25

26 Sep 09:40
Compare
Choose a tag to compare

This is a minor release. Thank you to all of our contributors and users!

New Features

Bug Fixes

Performance

Style

Tests

  • test(assert): increase coverage (#1084, #1085; @brutalcrozt)
  • test: stop modifying globals in Proxy tests (#1144; @meeber)

Docs

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

31 Aug 21:39
Compare
Choose a tag to compare

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

4.1.1 / 2017-08-05

05 Aug 07:29
Compare
Choose a tag to compare

This release includes a few bug and documentation fixes.

Bug Fixes

Docs

4.1.0 / 2017-07-11

12 Jul 00:13
Compare
Choose a tag to compare

This release includes one new feature and a few bug fixes.

New Features

Bug Fixes

  • Allow dates for isBelow and isAbove assertions (#980, #990; @v1adko)
  • fix: check target's type in .property assertion (#992; @meeber)

Chores

4.0.2 / 2017-06-05

05 Jun 19:31
Compare
Choose a tag to compare

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

31 May 21:18
Compare
Choose a tag to compare

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 / 2017-05-26

26 May 10:29
Compare
Choose a tag to compare

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 and Set, 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 example expect(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 the assert interface have been renamed. They all have had the deep word changed by the nested 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 if obj didn't have a property named name. This change causes the assertion to pass instead.
    The assert.propertyNotVal and assert.deepPropertyNotVal assertions were renamed to assert.notPropertyVal and assert.notDeepPropertyVal, respectively. (Related Issues: #16, #743, #758)

  • You can now use the deep flag for the .include assertion in order to perform a deep equality check to see if something is included on the target.
    Previously, .include was using strict equality (===) for non-negated property inclusion, but deep 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 is NaN (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 the config). (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 using ownProperty or own.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 the chai.use callback function) no longer exports the getPathValue function. If you want to use that please use the pathval module, which is what chai uses internally now. (Related Issues: #457, #737, PRs: #830)

  • (For plugin authors) Throw when calling _superon overwriteMethodif the method being overwritten is undefined.
    Currently if the method you are trying to overwrite is not defined and your new method calls _super it will throw an Error.(Related Issues: #467, PRs: #528)
    Before this change, calling _super would simply return this.

    // 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 the showDiff flag is anything other than false.
    This issue will mostly affect plugin creators or anyone that made extensions to the core, since this affects the Assertion.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 disable...

Read more

4.0.0-canary.2 / 2017-04-17

17 Apr 18:03
Compare
Choose a tag to compare
Pre-release

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 call global.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 (like TypeError) you will now get a more helpful error message about this. (before it would say Right-hand side of 'instanceof' is not an object, now it says The 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 in 4.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.