BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.

Overview

ChaiJS
chai

Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

license:mit tag:? node:?
Selenium Test Status
downloads:? build:? coverage:? devDependencies:?
Join the Slack chat Join the Gitter chat OpenCollective Backers

For more information or to download plugins, view the documentation.

What is Chai?

Chai is an assertion library, similar to Node's built-in assert. It makes testing much easier by giving you lots of assertions you can run against your code.

Installation

Node.js

chai is available on npm. To install it, type:

$ npm install --save-dev chai

Browsers

You can also use it within the browser; install via npm and use the chai.js file found within the download. For example:

<script src="./node_modules/chai/chai.js"></script>

Usage

Import the library in your code, and then pick one of the styles you'd like to use - either assert, expect or should:

var chai = require('chai');  
var assert = chai.assert;    // Using Assert style
var expect = chai.expect;    // Using Expect style
var should = chai.should();  // Using Should style

Pre-Native Modules Usage (registers the chai testing style globally)

require('chai/register-assert');  // Using Assert style
require('chai/register-expect');  // Using Expect style
require('chai/register-should');  // Using Should style

Pre-Native Modules Usage (as local variables)

const { assert } = require('chai');  // Using Assert style
const { expect } = require('chai');  // Using Expect style
const { should } = require('chai');  // Using Should style
should();  // Modifies `Object.prototype`

const { expect, use } = require('chai');  // Creates local variables `expect` and `use`; useful for plugin use

Native Modules Usage (registers the chai testing style globally)

import 'chai/register-assert';  // Using Assert style
import 'chai/register-expect';  // Using Expect style
import 'chai/register-should';  // Using Should style

Native Modules Usage (local import only)

import { assert } from 'chai';  // Using Assert style
import { expect } from 'chai';  // Using Expect style
import { should } from 'chai';  // Using Should style
should();  // Modifies `Object.prototype`

Usage with Mocha

mocha spec.js -r chai/register-assert  # Using Assert style
mocha spec.js -r chai/register-expect  # Using Expect style
mocha spec.js -r chai/register-should  # Using Should style

Read more about these styles in our docs.

Plugins

Chai offers a robust Plugin architecture for extending Chai's assertions and interfaces.

  • Need a plugin? View the official plugin list.
  • Want to build a plugin? Read the plugin api documentation.
  • Have a plugin and want it listed? Simply add the following keywords to your package.json:
    • chai-plugin
    • browser if your plugin works in the browser as well as Node.js
    • browser-only if your plugin does not work with Node.js

Related Projects

Contributing

Thank you very much for considering to contribute!

Please make sure you follow our Code Of Conduct and we also strongly recommend reading our Contributing Guide.

Here are a few issues other contributors frequently ran into when opening pull requests:

  • Please do not commit changes to the chai.js build. We do it once per release.
  • Before pushing your commits, please make sure you rebase them.

Contributors

Please see the full Contributors Graph for our list of contributors.

Core Contributors

Feel free to reach out to any of the core contributors with your questions or concerns. We will do our best to respond in a timely manner.

Jake Luer Veselin Todorov Keith Cirkel Lucas Fernandes da Costa Grant Snodgrass

Comments
  • How to test an ES7 async function

    How to test an ES7 async function

    Hey guys, I use ES7 async functions and tried to debug them. Having this method to test:

    // ...
    const local = new WeakMap();
    
    export default class User {
    
      // ...
    
      async password(password) {
        if (!password) return local.get(this).get('hash'); // remove this for security reasons!
        if (password.length < 6) throw new Error('New password must be at least 6 characters long');
        if (!password.match(passwordPattern)) throw new Error(`New password must match ${passwordPattern}`);
        local.get(this).set('hash', await Password.hash(password));
      }
    
      // ...
    
    }
    

    and this test case:

    import chai from 'chai';
    import chaiAsPromised from 'chai-as-promised';
    
    import User from '../../../server/User';
    
    chai.use(chaiAsPromised);
    const expect = chai.expect;
    
    describe('.password()', () => {
    
      const testuser = new User({username: 'Testuser', password: '123abc'});
    
      // FINDME
      it(`should throw when too short`, () => {
        return expect(testuser.password('1a')).to.eventually.throw();
      });
    
      // ...
    
    });
    

    ...the test case does not catch the error thrown - instead the case succeeds first and fails later (asynchronously) with an uncaught error because the method threw in the scope of the it() function not the expect().

    Any suggestions or advice?

    Thanks in advance!

    P.S.: Also I created a stackoverflow issue for this a few days ago, but now answer so far. That's why I am calling you guys. http://stackoverflow.com/questions/29334775/how-to-test-an-es7-async-function-using-mocha-chai-chai-as-promised

    more-discussion-needed 
    opened by krnlde 48
  • Chai Roadmap

    Chai Roadmap

    TL;DR

    Over the next few versions we're going to try to do the following:

    • Refactor messages to support advanced template strings (per chaijs/chai#393)
    • Refactor plugin declarations to support new interfaces (per chaijs/chai#117)
    • Split out chai codebase into various modules
    • Turn chai into a metapackage which combines these modules

    Refactor Messages

    @svallory has done some excellent work into refactoring the message syntax for chai assertions. This will make writing plugins simpler, as the need for message variants is removed.

    See chaijs/chai#393 for more.

    Refactor plugin declarations

    Right now the plugin system is simple to use, and has lead to a successful plugin community. But it could be better.

    Assertions should declare the flags they use in an up-front manner, allowing deeper introspection for interfaces. This will allow us to put effort into making interfaces which are pain points for the community - such as an assert interface that works with <=IE8, and expect/should interfaces which use method assertions over property assertions.

    Two of the biggest causes of fragmentation of chai users is due to low browser support, and the property assertions - which spawns off codebases like the following:

    While we can't be all things to all people, some of these libraries exist purely because Chai has failed them, and so we see a lot of duplication of effort.

    Some of this has been discussed in chaijs/chai#117.

    Split out chai codebase into various modules

    We've been putting efforts into splitting chai out into smaller modules, and it's been working well - but I think we can go further. The way I see things, we can split chai into the following:

    • chai-core (plugin loader interface, lib/assert, lib/chai/utils.[add/overwrite]*.js)
    • chai-common-assertions (existing assertions, lib/chai/core/assertions.js)
    • message-formatter (lib/chai/utils/getMessage.js, and @svallory's work)
    • checkError (complex logic within lib/chai/core/assertions.js .throw assertion)
    • loupe (lib/chai/utils/inspect.js, old code exists as loupe, but needs updating and removing from chai proper)
    • AssertionError (already modularised as assertion-error)
    • type-detect (already modularised as type-detect)
    • pathval (lib/chai/utils/getPathInfo, old code exists as pathval, but needs updating and removing from chai proper)
    • interfaces
      • assert (lib/chai/interface/assert)
      • expect (lib/chai/interface/expect)
      • should (lib/chai/interface/should)
      • assert-legacy (potential new interface for older browsers)
      • expect-method ("jshint friendly expect")
      • should-method ("jshint friendly should")

    Becoming more modular, we can also hope to facilitate some new and interesting use cases of our work, such as described in chaijs/chai#346

    Chai metapackage

    With modules pulled out of the main chai codebase, we can effectively turn the chai package into a metapackage of the rest of chai. It'll still be a first class part of chai, and we'd funnel all issues to this - but by having discrete modules for each part, we give the community a chance to pick and chose elements. We can innovate in areas, like having a chai-lite module which can be used in older browsers, while chai proper can innovate upon evergreen browsers.

    Roadmap:

    Based on the above, I see the roadmap as follows:

    3.0.0

    • [x] Move type-detect into its own library (thanks @davelosert!).

    4.0.0

    • [x] Move pathval into its own module (thanks @lucasfcosta!). [Issue: #737]
    • [x] Improve deep-eql for ES6 and more. [#837]
    • [x] Move checkError into its own module (thanks @lucasfcosta!). [#683]

    5.0.0

    • [ ] Switch to new declarative plugin syntax (where plugins define the flags they support upfront) [WIP #585]
    • [ ] Switch to new chai message formatting
    • [ ] Move loupe into its own module. [WIP]

    5.1.0

    • [ ] Trial new interfaces, assert-legacy, expect-methods and should-methods.
    • [ ] Move chai-core into its own module.
    • [ ] Move chai-common-assertions into its own module.
    opened by keithamus 47
  • Allow writing JSLint/JSHint friendly tests

    Allow writing JSLint/JSHint friendly tests

    When using expect() for writing asserting, some of the assertion are using properties as the mean for calling assert.

    For example

    expect(foo).to.exist

    JSLint/JSHint will complain about such code, since it expects an assignment or function call.

    Hiding a function call, behind getting a property can be sweet but in tests, it leads to such warnings.

    I know that one can use assert calls, or not use JSHint/JSLint or configure JSHint/JSLint to ignore such warnings, but I just want to know what is your feeling about this problem.

    opened by adiroiban 45
  • Throw using checkError module

    Throw using checkError module

    Hello everyone! This one is pretty big and we've got plenty of special cases at the throws assertion, so be careful when reviewing :smile:

    This one aims to solve an issue for the 4.0.0 release (as stated on our Roadmap #457) and finish #470 implementation. I thought that before moving checkError to a repository of its own it would be nice to have it reviewed and merged by more people here and only then we would move it to a new repo, but I'll do what you guys think it's better, this is just my opinion, please let me know if you disagree :wink:


    This PR includes:

    • [x] The checkError module including DocStrings, compatibleInstance, compatibleMessage, compatibleConstructor, getConstructorName and getMessage
    • [x] Tests for each one of the checkError functions
    • [x] A full BC refactor of the throws assertion in order for it to use checkError

    I couldn't make the throws assertion more simple than this, because we've got lots of edge/special cases, so this is the most generic and clean code I could get to while maintaining BC. If any of you can think of a better way to implement this please share your idea, it will certainly be welcome :smiley:

    I look forward to hearing your feedback :+1:


    EDIT: This will be added to the check-error repo as requested by @keithamus. I'll write the complete repo structure and submit a PR there as soon as it's done.

    Please don't merge this since it requires changes to use the external module instead of the local one.

    opened by lucasfcosta 39
  • Asserting that assertions were made

    Asserting that assertions were made

    Is there a way to assert whether any chai assertions have been made?

    We've been bitten a number of times by tests passing gloriously in Mocha, only to realize that it's because no assertions were made for whatever reason (a common one is the misspelling of assertions, such as calledwith instead of calledWith. This would easily be caught by having a test hook that runs after each test to make sure that assertions were indeed made. It won't help with situations where some assertions are made and others are broken by misspelling or such, but in our experience it's been less common (if occurring at all.)

    If not possible, I'm happy to contribute, just let me know!

    more-discussion-needed 
    opened by mstade 35
  • Add script that registers expect as a side-effect

    Add script that registers expect as a side-effect

    I've added expect and assert as side-effects to make mocha auto register expect and assert from CLI automatically and to use them effectively when importing within native modules.

    For more information see: #594 and #604

    Native Modules Usage

    import assert from 'chai/assert'
    // Using Assert style
    import expect from 'chai/expect'
    // Using Expect style
    import should from 'chai/should'
    // Using Should style
    

    Usage with Mocha

    mocha spec.js -r chai/assert
    # Using Assert style
    mocha spec.js -r chai/expect
    # Using Expect style
    mocha spec.js -r chai/should
    # Using Should style
    
    opened by inancgumus 31
  • Fixes an issues when both `.throws()` and `not.throws()` produce failures.

    Fixes an issues when both `.throws()` and `not.throws()` produce failures.

    This PR solves an issue when both .throws() and not.throws() produce failures. Exemple:

    expect(function() { throw new Error(); }).to.throw(Error, 'hello'); // fails
    expect(function() { throw new Error(); }).to.not.throw(Error, 'hello'); // fails too
    

    Imo the notspec above should pass.

    This PR solves this issue and also modify the initial behavior by perfoming lazy comparison on exceptions to allows this syntax to make it works out of the box:

    expect(function() { throw new Error('testing'); }).to.throw(new Error('testing')); 
    

    Indeed previoulsy a === comparison was made on objects which requires the following syntax:

    expect(function() { throw new Error('testing'); }).to.throw(Error, 'testing'); 
    

    Now both syntax can be used either way. the only difference is one is assuming the error message to be strictly identical since the second way only requires testing to be included in the error message.

    Solves https://github.com/chaijs/chai/issues/436, https://github.com/chaijs/chai/issues/430 and probaly https://github.com/chaijs/chai/pull/470

    opened by jails 28
  • Ability to show only changes and deletions in diffs, not additions

    Ability to show only changes and deletions in diffs, not additions

    I use chai assertion library and chai-like library for the partial comparing of objects: I am interested in existence and compliance only of those properties that are listed in an expected object. Existence of additional properties in an actual object permissibly. Unfortunately, when diff is created it is not considered in any way and those properties, existence which for the test it is indifferent get to diff. It would be desirable to have a way to suppress their generation in a diff. Example (runned with mocha):

    'use strict';
    
    let chai = require('chai');
    let expect = chai.expect;
    chai.use(require('chai-like'));
    
    describe("diff test", function() {
      let AST = {
        type: 'grammar',
        rules: [
          { type: 'rule', name: 'rule1' },
          { type: 'rule', name: 'rule2' },
        ],
        // it is a lot more other properties
      };
      it("chai-like", function() {
        expect(AST).like({
          rules: [
            { name: 'rule' },
            { name: 'rule2' }
          ]
        });
      });
    });
    

    This is current actual output of mocha which is too large in some cases and contains unnecessary details

      1) diff test
           chai-like:
    
          AssertionError: expected { Object (type, rules) } to be like { Object (rules) }
          + expected - actual
    
           {
             "rules": [
               {
          -      "name": "rule1"
          -      "type": "rule"
          +      "name": "rule"
               }
               {
                 "name": "rule2"
          -      "type": "rule"
               }
             ]
          -  "type": "grammar"
           }
    
          at Context.<anonymous> (test\test.js:24:17)
    

    But I want that diff looked here so:

     {
       "rules": [
         {
    -      "name": "rule1"
    +      "name": "rule"
         }
       ]
     }
    

    Now there is no opportunity to show diff in that look in what it is required as AssertionError has no signs that it is required. Mocha developers advised to create at first the task here before they are able to support this functionality (https://github.com/mochajs/mocha/issues/3193).

    I suppose add to an AssertionError object new property which could control such behavior of diff.

    If the idea is supported, I can make PRs for its implementation in all necessary libraries.

    opened by Mingun 27
  • .length(value) deprecation

    .length(value) deprecation

    I noticed that the documentation says:

    Deprecation notice: Using length as an assertion will be deprecated in version 2.4.0 and removed in 3.0.0. Code using the old style of asserting for length property value using length(value) should be switched to use lengthOf(value) instead.

    But I also noticed that chai is on 3.5.0 and .length(value) seems to still be a thing. Am I missing something here?

    more-discussion-needed 
    opened by lencioni 26
  • Make assert work in oldIE

    Make assert work in oldIE

    The assert interface depends on the expect and should interfaces. This is a real shame because it stops us from working in IE<=8. We should make it work!

    big-size more-discussion-needed 
    opened by domenic 26
  • Allow dates for isBelow and isAbove assertions

    Allow dates for isBelow and isAbove assertions

    Hi guys.

    This closes #980. I took #692 as an "inspiration" and extended the code to support dates as discussed in the issue.

    I have encountered some questions along the way and left comments (off course will delete them once we decided what to do at those moments) - I will expand on them within GitHub, to make them easier to notice. So it's a WIP for now, just need a bit of your guidance.

    This is my first attempt at actually PR-ing anything open-source, so sorry for mistakes. I'd really like to contribute :)

    Also need to fix up Phantom tests, but wanted to get some feedback and ask these questions first, to understand the general direction and the scope of this PR better.

    opened by v1adko 25
  • build(deps): bump flat and mocha

    build(deps): bump flat and mocha

    Bumps flat to 5.0.2 and updates ancestor dependency mocha. These dependencies need to be updated together.

    Updates flat from 4.1.0 to 5.0.2

    Commits
    • e5ffd66 Release 5.0.2
    • fdb79d5 Update dependencies, refresh lockfile, format with standard.
    • e52185d Test against node 14 in CI.
    • 0189cb1 Avoid arrow function syntax.
    • f25d3a1 Release 5.0.1
    • 54cc7ad use standard formatting
    • 779816e drop dependencies
    • 2eea6d3 Bump lodash from 4.17.15 to 4.17.19
    • a61a554 Bump acorn from 7.1.0 to 7.4.0
    • 20ef0ef Fix prototype pollution on unflatten
    • Additional commits viewable in compare view
    Maintainer changes

    This version was pushed to npm by timoxley, a new releaser for flat since your current version.


    Updates mocha from 7.1.2 to 10.2.0

    Release notes

    Sourced from mocha's releases.

    v10.2.0

    10.2.0 / 2022-12-11

    :tada: Enhancements

    • #4945: API: add possibility to decorate ESM name before import (@​j0tunn)

    :bug: Fixes

    :book: Documentation

    v10.1.0

    10.1.0 / 2022-10-16

    :tada: Enhancements

    :nut_and_bolt: Other

    v10.0.0

    10.0.0 / 2022-05-01

    :boom: Breaking Changes

    :nut_and_bolt: Other

    ... (truncated)

    Changelog

    Sourced from mocha's changelog.

    10.2.0 / 2022-12-11

    :tada: Enhancements

    • #4945: API: add possibility to decorate ESM name before import (@​j0tunn)

    :bug: Fixes

    :book: Documentation

    10.1.0 / 2022-10-16

    :tada: Enhancements

    :nut_and_bolt: Other

    10.0.0 / 2022-05-01

    :boom: Breaking Changes

    :nut_and_bolt: Other

    ... (truncated)

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • deep.include.oneOf not working correctly

    deep.include.oneOf not working correctly

    I would expect the following to pass, but it doesn't:

    chai.expect([ [1], [2] ]).to.deep.include.oneOf([ [1], [2] ]);
    

    I think this is related to #1241, but was under the impression that it had been fixed by #1334? I am using chai 4.3.7 which is the current latest.

    opened by BadIdeaException 0
  • Security vulnerability - Prototype pollution found in npm package - chai

    Security vulnerability - Prototype pollution found in npm package - chai

    A prototype pollution vulnerability is found in the Chai Npm package in the module - chai.js Here, one level of Object pollution is happening and not global pollution, but however, it is found that the affected function does not return anything.

    The vulnerable functionality is exported here: https:/github.com/chaijs/chai/blob/529b8b527ba99454471ac67d6aebca9d96cb5dd9/chai.js#L9181 A vulnerable line of code (Object assignment) from outside parameters is happening here: https:/github.com/chaijs/chai/blob/529b8b527ba99454471ac67d6aebca9d96cb5dd9/chai.js#L9191 in "key" variable.

    You can find the exploit code below:

    const chai = require('chai');
    const obj1 = JSON.parse('{"__proto__": {"toString": true}}');
    console.log(obj1.toString());
    try{
        const obj2 = chai.AssertionError("Error", obj1, 'ssfi');
        console.log({}.toString());  // One-level pollution only - returns the toString function
        console.log(obj2.toString());  // AssertionError does not return anything and is hence undefined, but polluted the object within the function
    }
    catch(e) {
        console.log(e.toString())
    }
    

    You can prevent this by adding any preventive measures like Object.preventExtensions, which I see is used but commented on in various parts of the code.

    Kindly address this issue and feel free to get back if you have any queries. I have raised a GitHub issue for the same.

    opened by Supraja9726 0
  • build(deps): bump qs from 6.5.2 to 6.5.3

    build(deps): bump qs from 6.5.2 to 6.5.3

    Bumps qs from 6.5.2 to 6.5.3.

    Changelog

    Sourced from qs's changelog.

    6.5.3

    • [Fix] parse: ignore __proto__ keys (#428)
    • [Fix] utils.merge`: avoid a crash with a null target and a truthy non-array source
    • [Fix] correctly parse nested arrays
    • [Fix] stringify: fix a crash with strictNullHandling and a custom filter/serializeDate (#279)
    • [Fix] utils: merge: fix crash when source is a truthy primitive & no options are provided
    • [Fix] when parseArrays is false, properly handle keys ending in []
    • [Fix] fix for an impossible situation: when the formatter is called with a non-string value
    • [Fix] utils.merge: avoid a crash with a null target and an array source
    • [Refactor] utils: reduce observable [[Get]]s
    • [Refactor] use cached Array.isArray
    • [Refactor] stringify: Avoid arr = arr.concat(...), push to the existing instance (#269)
    • [Refactor] parse: only need to reassign the var once
    • [Robustness] stringify: avoid relying on a global undefined (#427)
    • [readme] remove travis badge; add github actions/codecov badges; update URLs
    • [Docs] Clean up license text so it’s properly detected as BSD-3-Clause
    • [Docs] Clarify the need for "arrayLimit" option
    • [meta] fix README.md (#399)
    • [meta] add FUNDING.yml
    • [actions] backport actions from main
    • [Tests] always use String(x) over x.toString()
    • [Tests] remove nonexistent tape option
    • [Dev Deps] backport from main
    Commits
    • 298bfa5 v6.5.3
    • ed0f5dc [Fix] parse: ignore __proto__ keys (#428)
    • 691e739 [Robustness] stringify: avoid relying on a global undefined (#427)
    • 1072d57 [readme] remove travis badge; add github actions/codecov badges; update URLs
    • 12ac1c4 [meta] fix README.md (#399)
    • 0338716 [actions] backport actions from main
    • 5639c20 Clean up license text so it’s properly detected as BSD-3-Clause
    • 51b8a0b add FUNDING.yml
    • 45f6759 [Fix] fix for an impossible situation: when the formatter is called with a no...
    • f814a7f [Dev Deps] backport from main
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • build(deps): bump follow-redirects from 1.13.3 to 1.15.2

    build(deps): bump follow-redirects from 1.13.3 to 1.15.2

    Bumps follow-redirects from 1.13.3 to 1.15.2.

    Commits
    • 9655237 Release version 1.15.2 of the npm package.
    • 6e2b86d Default to localhost if no host given.
    • 449e895 Throw invalid URL error on relative URLs.
    • e30137c Use type functions.
    • 76ea31f ternary operator syntax fix
    • 84c00b0 HTTP header lines are separated by CRLF.
    • d28bcbf Create SECURITY.md (#202)
    • 62a551c Release version 1.15.1 of the npm package.
    • 7fe0779 Use for ... of.
    • 948c30c Fix redirecting to relative URL when using proxy
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Releases(v4.3.7)
  • v4.3.7(Nov 7, 2022)

    What's Changed

    • fix: deep-eql bump package to support symbols comparison by @snewcomer in https://github.com/chaijs/chai/pull/1483

    Full Changelog: https://github.com/chaijs/chai/compare/v4.3.6...v4.3.7

    Source code(tar.gz)
    Source code(zip)
  • v4.3.6(Jan 26, 2022)

  • v4.3.5(Jan 25, 2022)

    • build chaijs fca5bb1
    • build(deps-dev): bump codecov from 3.1.0 to 3.7.1 (#1446) 747eb4e
    • fix package.json exports 022c2fa
    • fix: package.json - deprecation warning on exports field (#1400) 5276af6
    • feat: use chaijs/loupe for inspection (#1401) (#1407) c8a4e00

    https://github.com/chaijs/chai/compare/v4.3.4...v4.3.5

    Source code(tar.gz)
    Source code(zip)
  • v4.3.4(Mar 12, 2021)

  • 4.3.3(Mar 3, 2021)

    This reintroduces Assertion as an export in the mjs file. See https://github.com/chaijs/chai/pull/1378 & https://github.com/chaijs/chai/issues/1375

    Source code(tar.gz)
    Source code(zip)
  • 4.3.2(Mar 3, 2021)

  • 4.3.1(Mar 2, 2021)

    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

    Source code(tar.gz)
    Source code(zip)
  • 4.3.0(Feb 4, 2021)

    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 anutilmethod 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)
    Source code(tar.gz)
    Source code(zip)
  • 4.2.0(Sep 26, 2018)

    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)
    Source code(tar.gz)
    Source code(zip)
  • 4.1.2(Aug 31, 2017)

    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)
    Source code(tar.gz)
    Source code(zip)
  • 4.1.1(Aug 5, 2017)

    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)
    Source code(tar.gz)
    Source code(zip)
  • 4.1.0(Jul 12, 2017)

    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 access ssfi flag (#993; @meeber)
    • Create CODEOWNERS (#1004; @keithamus)
    Source code(tar.gz)
    Source code(zip)
  • 4.0.2(Jun 5, 2017)

    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)
    Source code(tar.gz)
    Source code(zip)
  • 4.0.1(May 31, 2017)

    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)
    Source code(tar.gz)
    Source code(zip)
  • 4.0.0(May 26, 2017)

    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 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 disable config.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 the change, increase and decrease 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 on maps and sets. (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 and but 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 a WeakMap or WeakSet.

      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 register should 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 register assert 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 register expect 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 references function's built-in length property instead of Chai's length 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 given ssfi flag should retain its current value, even as assertions are chained off of this object. This is usually set to true when creating a new assertion from within another assertion. It's also temporarily set to true 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 and deepOwnInclude assertions and there negated pairs were added to the assert 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)
    Source code(tar.gz)
    Source code(zip)
  • 4.0.0-canary.2(Apr 17, 2017)

    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.
    Source code(tar.gz)
    Source code(zip)
  • 4.0.0-canary.1(Oct 24, 2016)

    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 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;
      
    • 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(); 
      
    • 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);
      }
      
    • 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 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 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 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)

    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 disable config.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 the change, increase and decrease 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 on maps and sets. (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 and but 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 a WeakMap or WeakSet.

      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)
    Source code(tar.gz)
    Source code(zip)
  • 3.5.0(Jan 28, 2016)

    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

    Documentation fixes

    Source code(tar.gz)
    Source code(zip)
  • 3.4.2(Nov 15, 2015)

    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

    Source code(tar.gz)
    Source code(zip)
  • 3.4.1(Nov 7, 2015)

  • 3.4.0(Oct 21, 2015)

    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. Before expect(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 example expect(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

    Source code(tar.gz)
    Source code(zip)
  • 3.3.0(Sep 11, 2015)

    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 or extensible 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

    Documentation fixes

    Source code(tar.gz)
    Source code(zip)
  • 3.2.0(Jul 19, 2015)

    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

    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Jul 16, 2015)

    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

    Source code(tar.gz)
    Source code(zip)
  • 3.0.0(Jun 3, 2015)

    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's Symbol.toStringTag affects the behaviour .to.be.a(). In addition to this, Errors have the type of 'error'.
    • assert.ifError() now follows Node's assert.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

    Documentation fixes

    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Apr 26, 2015)

    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

    Documentation fixes

    Source code(tar.gz)
    Source code(zip)
  • 2.2.0(Mar 27, 2015)

    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
    Source code(tar.gz)
    Source code(zip)
  • 2.1.2(Mar 15, 2015)

  • 2.1.1(Mar 4, 2015)

    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

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Feb 23, 2015)

    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

    Source code(tar.gz)
    Source code(zip)
Owner
Chai.js Assertion Library
Chai.js Assertion Library
🐐 Simple and complete React DOM testing utilities that encourage good testing practices.

React Testing Library Simple and complete React DOM testing utilities that encourage good testing practices. Read The Docs | Edit the docs Table of Co

Testing Library 17.3k Jan 4, 2023
🔮 Proxies nodejs require in order to allow overriding dependencies during testing.

proxyquire Proxies nodejs's require in order to make overriding dependencies during testing easy while staying totally unobtrusive. If you want to stu

Thorsten Lorenz 2.7k Dec 27, 2022
Test spies, stubs and mocks for JavaScript.

Sinon.JS Standalone and test framework agnostic JavaScript test spies, stubs and mocks (pronounced "sigh-non", named after Sinon, the warrior). Compat

Sinon.JS 9.2k Jan 4, 2023
Repositório do curso de TDD do Manguinho (Node + TS + SOLID + TDD + Clean Architecture)

Curso Rodrigo Manguinho - NodeJs, Typescript, TDD, DDD, Clean Architecture e SOLID Curso tem como objetivo aprender de verdade a criar uma API complet

Glaucia Lemos 4 Dec 15, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
Minimalistic BDD-style assertions for Node.JS and the browser.

Expect Minimalistic BDD assertion toolkit based on should.js expect(window.r).to.be(undefined); expect({ a: 'b' }).to.eql({ a: 'b' }) expect(5).to.be.

Automattic 2.1k Jan 4, 2023
Marry in Web3, Mint Paired Soulbound NFTs by MultiSign Flow, No transfer, No sell, a non-financial Dapp

ERC721-520 Token 是 NFT-like Soulbound Token Standard(灵魂绑定凭证) 的一种实现,是 ERC721 标准的扩展。 ERC721-520 Token 不可转让,不可售卖,一个人同时只能有一个有效 Token ERC721-520 Token 由二者通

Marry3 48 Dec 21, 2022
Small module that makes sure your catch, caught an actual error and not a programming mistake or assertion

safety-catch Small module that makes sure your catch, caught an actual error and not a programming mistake or assertion. npm install safety-catch Tri

Mathias Buus 31 May 4, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
🔥 TypeScript type assertion plugin for vitest

TypeScript type assertion plugin for vitest. ?? This plugin is in alpha version, and will probably stay that way for a long time, it lacks tests (a bi

null 74 Nov 23, 2022
Cypress Boilerplate with Cucumber (BDD)

Cypress Boilerplate with POM and Cucumber Download & Configuration npm init --> package.json npm install cypress cypress-cucumber-preprocessor --> pac

Sefa Batuhan Bayazitoğlu 7 Nov 4, 2022
A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Prisma ORM. Deploys to Fly.io

Live Demo · Twitter A testing focused Remix Stack, that integrates E2E & Unit testing with Playwright, Vitest, MSW and Testing Library. Driven by Pris

Remix Stacks 18 Oct 31, 2022
In this project I write the test for several functions and used the TDD with Jest and JavaScript.

JavaScript-Testing-with-Jest npm init -y npm install --save-dev jest Once installed, you should see it in already created Json file Change Jest Script

Ben Kiboma Omayio 2 Jun 11, 2022
A helper to send whatsapp without scheduling a contact, the project developed using TDD with Jest, Javascript classes, BotstrapVue and SweetAlert.

Project setup npm install Compiles and hot-reloads for development npm run serve Compiles and minifies for production npm run build Lints and fixes

Magascript 7 Sep 13, 2022
This repository serves as a starter kit for doing simple TDD exercise

This repository serves as a starter kit for doing simple TDD exercise

adylanrff 3 Feb 19, 2022
Project developed in typescript with clean architecture + tdd for demonstration purposes.

Description Project developed in typescript with clean architecture + tdd for demonstration purposes in Usystem. Installation $ yarn Running the app #

USystem - Desenvolvimento Ágil de Softwares 1 Oct 5, 2022