Socket
Socket
Sign inDemoInstall

chai

Package Overview
Dependencies
Maintainers
2
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai - npm Package Compare versions

Comparing version 4.3.10 to 5.0.0

karma.conf.cjs

8

CONTRIBUTING.md

@@ -24,2 +24,3 @@ # Chai Contribution Guidelines

- Issue reports should be **clear**, **concise** and **reproducible**. Check to see if your issue has already been resolved in the [master]() branch or already reported in Chai's [GitHub Issue Tracker](https://github.com/chaijs/chai/issues).
- Pull Requests must adhere to strict [coding style guidelines](https://github.com/chaijs/chai/wiki/Chai-Coding-Style-Guide).
- In general, avoid submitting PRs for new Assertions without asking core contributors first. More than likely it would be better implemented as a plugin.

@@ -94,3 +95,3 @@ - Additional support is available via the [Google Group](http://groups.google.com/group/chaijs) or on irc.freenode.net#chaijs.

Please adhere to the coding conventions used throughout a project (indentation, accurate comments, etc.) and any other requirements (such as test coverage).
Please adhere to the coding conventions used throughout a project (indentation, accurate comments, etc.) and any other requirements (such as test coverage). Please review the [Chai.js Coding Style Guide](https://github.com/chaijs/chai/wiki/Chai-Coding-Style-Guide).

@@ -189,2 +190,7 @@ Follow this process if you'd like your work considered for inclusion in the project:

Alternatively, the [wiki](https://github.com/chaijs/chai/wiki) might be what you are looking for.
- [Chai Coding Style Guide](https://github.com/chaijs/chai/wiki/Chai-Coding-Style-Guide)
- [Third-party Resources](https://github.com/chaijs/chai/wiki/Third-Party-Resources)
Or finally, you may find a core-contributor or like-minded developer in any of our support channels.

@@ -191,0 +197,0 @@

2

index.js

@@ -1,1 +0,1 @@

module.exports = require('./lib/chai');
export * from './lib/chai.js';

@@ -7,10 +7,13 @@ /*!

var used = [];
import * as util from './chai/utils/index.js';
import {AssertionError} from 'assertion-error';
import {config} from './chai/config.js';
import './chai/core/assertions.js';
import {expect} from './chai/interface/expect.js';
import {Assertion} from './chai/assertion.js';
import * as should from './chai/interface/should.js';
import {assert} from './chai/interface/assert.js';
/*!
* Chai version
*/
const used = [];
exports.version = '4.3.8';
/*!

@@ -20,10 +23,4 @@ * Assertion Error

exports.AssertionError = require('assertion-error');
export {AssertionError};
/*!
* Utils for plugins (not exported)
*/
var util = require('./chai/utils');
/**

@@ -39,3 +36,13 @@ * # .use(function)

exports.use = function (fn) {
export function use(fn) {
const exports = {
AssertionError,
util,
config,
expect,
assert,
Assertion,
...should
};
if (!~used.indexOf(fn)) {

@@ -53,3 +60,3 @@ fn(exports, util);

exports.util = util;
export {util};

@@ -60,4 +67,3 @@ /*!

var config = require('./chai/config');
exports.config = config;
export {config};

@@ -68,18 +74,9 @@ /*!

var assertion = require('./chai/assertion');
exports.use(assertion);
export * from './chai/assertion.js';
/*!
* Core Assertions
*/
var core = require('./chai/core/assertions');
exports.use(core);
/*!
* Expect interface
*/
var expect = require('./chai/interface/expect');
exports.use(expect);
export * from './chai/interface/expect.js';

@@ -90,4 +87,3 @@ /*!

var should = require('./chai/interface/should');
exports.use(should);
export * from './chai/interface/should.js';

@@ -98,3 +94,2 @@ /*!

var assert = require('./chai/interface/assert');
exports.use(assert);
export * from './chai/interface/assert.js';

@@ -8,169 +8,159 @@ /*!

var config = require('./config');
import {config} from './config.js';
import {AssertionError} from 'assertion-error';
import * as util from './utils/index.js';
module.exports = function (_chai, util) {
/*!
* Module dependencies.
*/
/*!
* Assertion Constructor
*
* Creates object for chaining.
*
* `Assertion` objects contain metadata in the form of flags. Three flags can
* be assigned during instantiation by passing arguments to this constructor:
*
* - `object`: This flag contains the target of the assertion. For example, in
* the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
* contain `numKittens` so that the `equal` assertion can reference it when
* needed.
*
* - `message`: This flag contains an optional custom error message to be
* prepended to the error message that's generated by the assertion when it
* fails.
*
* - `ssfi`: This flag stands for "start stack function indicator". It
* contains a function reference that serves as the starting point for
* removing frames from the stack trace of the error that's created by the
* assertion when it fails. The goal is to provide a cleaner stack trace to
* end users by removing Chai's internal functions. Note that it only works
* in environments that support `Error.captureStackTrace`, and only when
* `Chai.config.includeStack` hasn't been set to `false`.
*
* - `lockSsfi`: 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.
*
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
*
* @param {Mixed} obj target of the assertion
* @param {String} msg (optional) custom error message
* @param {Function} ssfi (optional) starting point for removing stack frames
* @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
* @api private
*/
var AssertionError = _chai.AssertionError
, flag = util.flag;
export function Assertion (obj, msg, ssfi, lockSsfi) {
util.flag(this, 'ssfi', ssfi || Assertion);
util.flag(this, 'lockSsfi', lockSsfi);
util.flag(this, 'object', obj);
util.flag(this, 'message', msg);
util.flag(this, 'eql', config.deepEqual ?? util.eql);
/*!
* Module export.
*/
return util.proxify(this);
}
_chai.Assertion = Assertion;
Object.defineProperty(Assertion, 'includeStack', {
get: function() {
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
return config.includeStack;
},
set: function(value) {
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
config.includeStack = value;
}
});
/*!
* Assertion Constructor
*
* Creates object for chaining.
*
* `Assertion` objects contain metadata in the form of flags. Three flags can
* be assigned during instantiation by passing arguments to this constructor:
*
* - `object`: This flag contains the target of the assertion. For example, in
* the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
* contain `numKittens` so that the `equal` assertion can reference it when
* needed.
*
* - `message`: This flag contains an optional custom error message to be
* prepended to the error message that's generated by the assertion when it
* fails.
*
* - `ssfi`: This flag stands for "start stack function indicator". It
* contains a function reference that serves as the starting point for
* removing frames from the stack trace of the error that's created by the
* assertion when it fails. The goal is to provide a cleaner stack trace to
* end users by removing Chai's internal functions. Note that it only works
* in environments that support `Error.captureStackTrace`, and only when
* `Chai.config.includeStack` hasn't been set to `false`.
*
* - `lockSsfi`: 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.
*
* @param {Mixed} obj target of the assertion
* @param {String} msg (optional) custom error message
* @param {Function} ssfi (optional) starting point for removing stack frames
* @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
* @api private
*/
function Assertion (obj, msg, ssfi, lockSsfi) {
flag(this, 'ssfi', ssfi || Assertion);
flag(this, 'lockSsfi', lockSsfi);
flag(this, 'object', obj);
flag(this, 'message', msg);
return util.proxify(this);
Object.defineProperty(Assertion, 'showDiff', {
get: function() {
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
return config.showDiff;
},
set: function(value) {
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
config.showDiff = value;
}
});
Object.defineProperty(Assertion, 'includeStack', {
get: function() {
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
return config.includeStack;
},
set: function(value) {
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
config.includeStack = value;
}
});
Assertion.addProperty = function (name, fn) {
util.addProperty(this.prototype, name, fn);
};
Object.defineProperty(Assertion, 'showDiff', {
get: function() {
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
return config.showDiff;
},
set: function(value) {
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
config.showDiff = value;
}
});
Assertion.addMethod = function (name, fn) {
util.addMethod(this.prototype, name, fn);
};
Assertion.addProperty = function (name, fn) {
util.addProperty(this.prototype, name, fn);
};
Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
};
Assertion.addMethod = function (name, fn) {
util.addMethod(this.prototype, name, fn);
};
Assertion.overwriteProperty = function (name, fn) {
util.overwriteProperty(this.prototype, name, fn);
};
Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
};
Assertion.overwriteMethod = function (name, fn) {
util.overwriteMethod(this.prototype, name, fn);
};
Assertion.overwriteProperty = function (name, fn) {
util.overwriteProperty(this.prototype, name, fn);
};
Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
};
Assertion.overwriteMethod = function (name, fn) {
util.overwriteMethod(this.prototype, name, fn);
};
/**
* ### .assert(expression, message, negateMessage, expected, actual, showDiff)
*
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
*
* @name assert
* @param {Philosophical} expression to be tested
* @param {String|Function} message or function that returns message to display if expression fails
* @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
* @param {Mixed} expected value (remember to check for negation)
* @param {Mixed} actual (optional) will default to `this.obj`
* @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
* @api private
*/
Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
};
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
var ok = util.test(this, arguments);
if (false !== showDiff) showDiff = true;
if (undefined === expected && undefined === _actual) showDiff = false;
if (true !== config.showDiff) showDiff = false;
/**
* ### .assert(expression, message, negateMessage, expected, actual, showDiff)
*
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
*
* @name assert
* @param {Philosophical} expression to be tested
* @param {String|Function} message or function that returns message to display if expression fails
* @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
* @param {Mixed} expected value (remember to check for negation)
* @param {Mixed} actual (optional) will default to `this.obj`
* @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
* @api private
*/
if (!ok) {
msg = util.getMessage(this, arguments);
var actual = util.getActual(this, arguments);
var assertionErrorObjectProperties = {
actual: actual
, expected: expected
, showDiff: showDiff
};
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
var ok = util.test(this, arguments);
if (false !== showDiff) showDiff = true;
if (undefined === expected && undefined === _actual) showDiff = false;
if (true !== config.showDiff) showDiff = false;
var operator = util.getOperator(this, arguments);
if (operator) {
assertionErrorObjectProperties.operator = operator;
}
if (!ok) {
msg = util.getMessage(this, arguments);
var actual = util.getActual(this, arguments);
var assertionErrorObjectProperties = {
actual: actual
, expected: expected
, showDiff: showDiff
};
throw new AssertionError(
msg,
assertionErrorObjectProperties,
(config.includeStack) ? this.assert : util.flag(this, 'ssfi'));
}
};
var operator = util.getOperator(this, arguments);
if (operator) {
assertionErrorObjectProperties.operator = operator;
}
/*!
* ### ._obj
*
* Quick reference to stored `actual` value for plugin developers.
*
* @api private
*/
throw new AssertionError(
msg,
assertionErrorObjectProperties,
(config.includeStack) ? this.assert : flag(this, 'ssfi'));
Object.defineProperty(Assertion.prototype, '_obj',
{ get: function () {
return util.flag(this, 'object');
}
};
/*!
* ### ._obj
*
* Quick reference to stored `actual` value for plugin developers.
*
* @api private
*/
Object.defineProperty(Assertion.prototype, '_obj',
{ get: function () {
return flag(this, 'object');
}
, set: function (val) {
flag(this, 'object', val);
}
});
};
, set: function (val) {
util.flag(this, 'object', val);
}
});

@@ -1,2 +0,2 @@

module.exports = {
export const config = {

@@ -93,3 +93,29 @@ /**

proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON']
proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'],
/**
* ### config.deepEqual
*
* User configurable property, defines which a custom function to use for deepEqual
* comparisons.
* By default, the function used is the one from the `deep-eql` package without custom comparator.
*
* // use a custom comparator
* chai.config.deepEqual = (expected, actual) => {
* return chai.util.eql(expected, actual, {
* comparator: (expected, actual) => {
* // for non number comparison, use the default behavior
* if(typeof expected !== 'number') return null;
* // allow a difference of 10 between compared numbers
* return typeof actual === 'number' && Math.abs(actual - expected) < 10
* }
* })
* };
*
* @param {Function}
* @api public
*/
deepEqual: null
};

@@ -7,42 +7,45 @@ /*!

module.exports = function (chai, util) {
chai.expect = function (val, message) {
return new chai.Assertion(val, message);
};
import * as chai from '../../../index.js';
import {Assertion} from '../assertion.js';
import {AssertionError} from 'assertion-error';
/**
* ### .fail([message])
* ### .fail(actual, expected, [message], [operator])
*
* Throw a failure.
*
* expect.fail();
* expect.fail("custom error message");
* expect.fail(1, 2);
* expect.fail(1, 2, "custom error message");
* expect.fail(1, 2, "custom error message", ">");
* expect.fail(1, 2, undefined, ">");
*
* @name fail
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @param {String} operator
* @namespace BDD
* @api public
*/
function expect(val, message) {
return new Assertion(val, message);
}
chai.expect.fail = function (actual, expected, message, operator) {
if (arguments.length < 2) {
message = actual;
actual = undefined;
}
export {expect};
/**
* ### .fail([message])
* ### .fail(actual, expected, [message], [operator])
*
* Throw a failure.
*
* expect.fail();
* expect.fail("custom error message");
* expect.fail(1, 2);
* expect.fail(1, 2, "custom error message");
* expect.fail(1, 2, "custom error message", ">");
* expect.fail(1, 2, undefined, ">");
*
* @name fail
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @param {String} operator
* @namespace BDD
* @api public
*/
message = message || 'expect.fail()';
throw new chai.AssertionError(message, {
actual: actual
, expected: expected
, operator: operator
}, chai.expect.fail);
};
expect.fail = function (actual, expected, message, operator) {
if (arguments.length < 2) {
message = actual;
actual = undefined;
}
message = message || 'expect.fail()';
throw new AssertionError(message, {
actual: actual
, expected: expected
, operator: operator
}, chai.expect.fail);
};

@@ -7,214 +7,213 @@ /*!

module.exports = function (chai, util) {
var Assertion = chai.Assertion;
import {Assertion} from '../assertion.js';
import {AssertionError} from 'assertion-error';
function loadShould () {
// explicitly define this method as function as to have it's name to include as `ssfi`
function shouldGetter() {
if (this instanceof String
|| this instanceof Number
|| this instanceof Boolean
|| typeof Symbol === 'function' && this instanceof Symbol
|| typeof BigInt === 'function' && this instanceof BigInt) {
return new Assertion(this.valueOf(), null, shouldGetter);
}
return new Assertion(this, null, shouldGetter);
function loadShould () {
// explicitly define this method as function as to have it's name to include as `ssfi`
function shouldGetter() {
if (this instanceof String
|| this instanceof Number
|| this instanceof Boolean
|| typeof Symbol === 'function' && this instanceof Symbol
|| typeof BigInt === 'function' && this instanceof BigInt) {
return new Assertion(this.valueOf(), null, shouldGetter);
}
function shouldSetter(value) {
// See https://github.com/chaijs/chai/issues/86: this makes
// `whatever.should = someValue` actually set `someValue`, which is
// especially useful for `global.should = require('chai').should()`.
//
// Note that we have to use [[DefineProperty]] instead of [[Put]]
// since otherwise we would trigger this very setter!
Object.defineProperty(this, 'should', {
value: value,
enumerable: true,
configurable: true,
writable: true
});
}
// modify Object.prototype to have `should`
Object.defineProperty(Object.prototype, 'should', {
set: shouldSetter
, get: shouldGetter
, configurable: true
return new Assertion(this, null, shouldGetter);
}
function shouldSetter(value) {
// See https://github.com/chaijs/chai/issues/86: this makes
// `whatever.should = someValue` actually set `someValue`, which is
// especially useful for `global.should = require('chai').should()`.
//
// Note that we have to use [[DefineProperty]] instead of [[Put]]
// since otherwise we would trigger this very setter!
Object.defineProperty(this, 'should', {
value: value,
enumerable: true,
configurable: true,
writable: true
});
}
// modify Object.prototype to have `should`
Object.defineProperty(Object.prototype, 'should', {
set: shouldSetter
, get: shouldGetter
, configurable: true
});
var should = {};
var should = {};
/**
* ### .fail([message])
* ### .fail(actual, expected, [message], [operator])
*
* Throw a failure.
*
* should.fail();
* should.fail("custom error message");
* should.fail(1, 2);
* should.fail(1, 2, "custom error message");
* should.fail(1, 2, "custom error message", ">");
* should.fail(1, 2, undefined, ">");
*
*
* @name fail
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @param {String} operator
* @namespace BDD
* @api public
*/
/**
* ### .fail([message])
* ### .fail(actual, expected, [message], [operator])
*
* Throw a failure.
*
* should.fail();
* should.fail("custom error message");
* should.fail(1, 2);
* should.fail(1, 2, "custom error message");
* should.fail(1, 2, "custom error message", ">");
* should.fail(1, 2, undefined, ">");
*
*
* @name fail
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @param {String} operator
* @namespace BDD
* @api public
*/
should.fail = function (actual, expected, message, operator) {
if (arguments.length < 2) {
message = actual;
actual = undefined;
}
should.fail = function (actual, expected, message, operator) {
if (arguments.length < 2) {
message = actual;
actual = undefined;
}
message = message || 'should.fail()';
throw new chai.AssertionError(message, {
actual: actual
, expected: expected
, operator: operator
}, should.fail);
};
message = message || 'should.fail()';
throw new AssertionError(message, {
actual: actual
, expected: expected
, operator: operator
}, should.fail);
};
/**
* ### .equal(actual, expected, [message])
*
* Asserts non-strict equality (`==`) of `actual` and `expected`.
*
* should.equal(3, '3', '== coerces values to strings');
*
* @name equal
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @namespace Should
* @api public
*/
/**
* ### .equal(actual, expected, [message])
*
* Asserts non-strict equality (`==`) of `actual` and `expected`.
*
* should.equal(3, '3', '== coerces values to strings');
*
* @name equal
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @namespace Should
* @api public
*/
should.equal = function (val1, val2, msg) {
new Assertion(val1, msg).to.equal(val2);
};
should.equal = function (val1, val2, msg) {
new Assertion(val1, msg).to.equal(val2);
};
/**
* ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
*
* Asserts that `function` will throw an error that is an instance of
* `constructor`, or alternately that it will throw an error with message
* matching `regexp`.
*
* should.throw(fn, 'function throws a reference error');
* should.throw(fn, /function throws a reference error/);
* should.throw(fn, ReferenceError);
* should.throw(fn, ReferenceError, 'function throws a reference error');
* should.throw(fn, ReferenceError, /function throws a reference error/);
*
* @name throw
* @alias Throw
* @param {Function} function
* @param {ErrorConstructor} constructor
* @param {RegExp} regexp
* @param {String} message
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @namespace Should
* @api public
*/
/**
* ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
*
* Asserts that `function` will throw an error that is an instance of
* `constructor`, or alternately that it will throw an error with message
* matching `regexp`.
*
* should.throw(fn, 'function throws a reference error');
* should.throw(fn, /function throws a reference error/);
* should.throw(fn, ReferenceError);
* should.throw(fn, ReferenceError, 'function throws a reference error');
* should.throw(fn, ReferenceError, /function throws a reference error/);
*
* @name throw
* @alias Throw
* @param {Function} function
* @param {ErrorConstructor} constructor
* @param {RegExp} regexp
* @param {String} message
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @namespace Should
* @api public
*/
should.Throw = function (fn, errt, errs, msg) {
new Assertion(fn, msg).to.Throw(errt, errs);
};
should.Throw = function (fn, errt, errs, msg) {
new Assertion(fn, msg).to.Throw(errt, errs);
};
/**
* ### .exist
*
* Asserts that the target is neither `null` nor `undefined`.
*
* var foo = 'hi';
*
* should.exist(foo, 'foo exists');
*
* @name exist
* @namespace Should
* @api public
*/
/**
* ### .exist
*
* Asserts that the target is neither `null` nor `undefined`.
*
* var foo = 'hi';
*
* should.exist(foo, 'foo exists');
*
* @name exist
* @namespace Should
* @api public
*/
should.exist = function (val, msg) {
new Assertion(val, msg).to.exist;
}
should.exist = function (val, msg) {
new Assertion(val, msg).to.exist;
}
// negation
should.not = {}
// negation
should.not = {}
/**
* ### .not.equal(actual, expected, [message])
*
* Asserts non-strict inequality (`!=`) of `actual` and `expected`.
*
* should.not.equal(3, 4, 'these numbers are not equal');
*
* @name not.equal
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @namespace Should
* @api public
*/
/**
* ### .not.equal(actual, expected, [message])
*
* Asserts non-strict inequality (`!=`) of `actual` and `expected`.
*
* should.not.equal(3, 4, 'these numbers are not equal');
*
* @name not.equal
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @namespace Should
* @api public
*/
should.not.equal = function (val1, val2, msg) {
new Assertion(val1, msg).to.not.equal(val2);
};
should.not.equal = function (val1, val2, msg) {
new Assertion(val1, msg).to.not.equal(val2);
};
/**
* ### .throw(function, [constructor/regexp], [message])
*
* Asserts that `function` will _not_ throw an error that is an instance of
* `constructor`, or alternately that it will not throw an error with message
* matching `regexp`.
*
* should.not.throw(fn, Error, 'function does not throw');
*
* @name not.throw
* @alias not.Throw
* @param {Function} function
* @param {ErrorConstructor} constructor
* @param {RegExp} regexp
* @param {String} message
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @namespace Should
* @api public
*/
/**
* ### .throw(function, [constructor/regexp], [message])
*
* Asserts that `function` will _not_ throw an error that is an instance of
* `constructor`, or alternately that it will not throw an error with message
* matching `regexp`.
*
* should.not.throw(fn, Error, 'function does not throw');
*
* @name not.throw
* @alias not.Throw
* @param {Function} function
* @param {ErrorConstructor} constructor
* @param {RegExp} regexp
* @param {String} message
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
* @namespace Should
* @api public
*/
should.not.Throw = function (fn, errt, errs, msg) {
new Assertion(fn, msg).to.not.Throw(errt, errs);
};
should.not.Throw = function (fn, errt, errs, msg) {
new Assertion(fn, msg).to.not.Throw(errt, errs);
};
/**
* ### .not.exist
*
* Asserts that the target is neither `null` nor `undefined`.
*
* var bar = null;
*
* should.not.exist(bar, 'bar does not exist');
*
* @name not.exist
* @namespace Should
* @api public
*/
/**
* ### .not.exist
*
* Asserts that the target is neither `null` nor `undefined`.
*
* var bar = null;
*
* should.not.exist(bar, 'bar does not exist');
*
* @name not.exist
* @namespace Should
* @api public
*/
should.not.exist = function (val, msg) {
new Assertion(val, msg).to.not.exist;
}
should.not.exist = function (val, msg) {
new Assertion(val, msg).to.not.exist;
}
should['throw'] = should['Throw'];
should.not['throw'] = should.not['Throw'];
should['throw'] = should['Throw'];
should.not['throw'] = should.not['Throw'];
return should;
};
return should;
};
chai.should = loadShould;
chai.Should = loadShould;
};
export const should = loadShould;
export const Should = loadShould;

@@ -11,7 +11,7 @@ /*!

var addLengthGuard = require('./addLengthGuard');
var chai = require('../../chai');
var flag = require('./flag');
var proxify = require('./proxify');
var transferFlags = require('./transferFlags');
import {Assertion} from '../assertion.js';
import {addLengthGuard} from './addLengthGuard.js';
import {flag} from './flag.js';
import {proxify} from './proxify.js';
import {transferFlags} from './transferFlags.js';

@@ -74,3 +74,3 @@ /*!

module.exports = function addChainableMethod(ctx, name, method, chainingBehavior) {
export function addChainableMethod(ctx, name, method, chainingBehavior) {
if (typeof chainingBehavior !== 'function') {

@@ -120,3 +120,3 @@ chainingBehavior = function () { };

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);

@@ -155,2 +155,2 @@ return newAssertion;

});
};
}

@@ -1,2 +0,2 @@

var fnLengthDesc = Object.getOwnPropertyDescriptor(function () {}, 'length');
const fnLengthDesc = Object.getOwnPropertyDescriptor(function () {}, 'length');

@@ -43,3 +43,3 @@ /*!

module.exports = function addLengthGuard (fn, assertionName, isChainable) {
export function addLengthGuard(fn, assertionName, isChainable) {
if (!fnLengthDesc.configurable) return fn;

@@ -61,2 +61,2 @@

return fn;
};
}

@@ -7,7 +7,7 @@ /*!

var addLengthGuard = require('./addLengthGuard');
var chai = require('../../chai');
var flag = require('./flag');
var proxify = require('./proxify');
var transferFlags = require('./transferFlags');
import {addLengthGuard} from './addLengthGuard.js';
import {flag} from './flag.js';
import {proxify} from './proxify.js';
import {transferFlags} from './transferFlags.js';
import {Assertion} from '../assertion.js';

@@ -40,3 +40,3 @@ /**

module.exports = function addMethod(ctx, name, method) {
export function addMethod(ctx, name, method) {
var methodWrapper = function () {

@@ -63,3 +63,3 @@ // Setting the `ssfi` flag to `methodWrapper` causes this function to be the

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);

@@ -71,2 +71,2 @@ return newAssertion;

ctx[name] = proxify(methodWrapper, name);
};
}

@@ -7,6 +7,6 @@ /*!

var chai = require('../../chai');
var flag = require('./flag');
var isProxyEnabled = require('./isProxyEnabled');
var transferFlags = require('./transferFlags');
import {Assertion} from '../assertion.js';
import {flag} from './flag.js';
import {isProxyEnabled} from './isProxyEnabled.js';
import {transferFlags} from './transferFlags.js';

@@ -39,3 +39,3 @@ /**

module.exports = function addProperty(ctx, name, getter) {
export function addProperty(ctx, name, getter) {
getter = getter === undefined ? function () {} : getter;

@@ -68,3 +68,3 @@

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);

@@ -75,2 +75,2 @@ return newAssertion;

});
};
}

@@ -11,3 +11,3 @@ /*!

var inspect = require('./inspect');
import {inspect} from './inspect.js';

@@ -30,4 +30,4 @@ /**

module.exports = function compareByInspect(a, b) {
export function compareByInspect(a, b) {
return inspect(a) < inspect(b) ? -1 : 1;
};
}

@@ -21,7 +21,7 @@ /*!

var AssertionError = require('assertion-error');
var flag = require('./flag');
var type = require('type-detect');
import {AssertionError} from 'assertion-error';
import {flag} from './flag.js';
import {type} from './type-detect.js';
module.exports = function expectTypes(obj, types) {
export function expectTypes(obj, types) {
var flagMsg = flag(obj, 'message');

@@ -52,2 +52,2 @@ var ssfi = flag(obj, 'ssfi');

}
};
}

@@ -26,3 +26,3 @@ /*!

module.exports = function flag(obj, key, value) {
export function flag(obj, key, value) {
var flags = obj.__flags || (obj.__flags = Object.create(null));

@@ -34,2 +34,2 @@ if (arguments.length === 3) {

}
};
}

@@ -18,4 +18,4 @@ /*!

module.exports = function getActual(obj, args) {
export function getActual(obj, args) {
return args.length > 4 ? args[4] : obj._obj;
};
}

@@ -11,5 +11,5 @@ /*!

var flag = require('./flag')
, getActual = require('./getActual')
, objDisplay = require('./objDisplay');
import {flag} from './flag.js';
import {getActual} from './getActual.js';
import {objDisplay} from './objDisplay.js';

@@ -35,3 +35,3 @@ /**

module.exports = function getMessage(obj, args) {
export function getMessage(obj, args) {
var negate = flag(obj, 'negate')

@@ -52,2 +52,2 @@ , val = flag(obj, 'object')

return flagMsg ? flagMsg + ': ' + msg : msg;
};
}

@@ -1,8 +0,7 @@

var type = require('type-detect');
import {flag} from './flag.js';
import {type} from './type-detect.js';
var flag = require('./flag');
function isObjectType(obj) {
var objectType = type(obj);
var objectTypes = ['Array', 'Object', 'function'];
var objectTypes = ['Array', 'Object', 'Function'];

@@ -28,3 +27,3 @@ return objectTypes.indexOf(objectType) !== -1;

module.exports = function getOperator(obj, args) {
export function getOperator(obj, args) {
var operator = flag(obj, 'operator');

@@ -56,2 +55,2 @@ var negate = flag(obj, 'negate');

return isObject ? 'deepStrictEqual' : 'strictEqual';
};
}

@@ -11,3 +11,3 @@ /*!

var getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
import {getOwnEnumerablePropertySymbols} from './getOwnEnumerablePropertySymbols.js';

@@ -28,4 +28,4 @@ /**

module.exports = function getOwnEnumerableProperties(obj) {
export function getOwnEnumerableProperties(obj) {
return Object.keys(obj).concat(getOwnEnumerablePropertySymbols(obj));
};
}

@@ -21,3 +21,3 @@ /*!

module.exports = function getOwnEnumerablePropertySymbols(obj) {
export function getOwnEnumerablePropertySymbols(obj) {
if (typeof Object.getOwnPropertySymbols !== 'function') return [];

@@ -28,2 +28,2 @@

});
};
}

@@ -20,3 +20,3 @@ /*!

module.exports = function getProperties(object) {
export function getProperties(object) {
var result = Object.getOwnPropertyNames(object);

@@ -37,2 +37,2 @@

return result;
};
}

@@ -11,3 +11,3 @@ /*!

var pathval = require('pathval');
import * as checkError from 'check-error';

@@ -18,3 +18,3 @@ /*!

exports.test = require('./test');
export {test} from './test.js';

@@ -25,3 +25,3 @@ /*!

exports.type = require('type-detect');
export {type} from './type-detect.js';

@@ -31,3 +31,3 @@ /*!

*/
exports.expectTypes = require('./expectTypes');
export {expectTypes} from './expectTypes.js';

@@ -38,3 +38,3 @@ /*!

exports.getMessage = require('./getMessage');
export {getMessage} from './getMessage.js';

@@ -45,3 +45,3 @@ /*!

exports.getActual = require('./getActual');
export {getActual} from './getActual.js';

@@ -52,3 +52,3 @@ /*!

exports.inspect = require('./inspect');
export {inspect} from './inspect.js';

@@ -59,3 +59,3 @@ /*!

exports.objDisplay = require('./objDisplay');
export {objDisplay} from './objDisplay.js';

@@ -66,3 +66,3 @@ /*!

exports.flag = require('./flag');
export {flag} from './flag.js';

@@ -73,3 +73,3 @@ /*!

exports.transferFlags = require('./transferFlags');
export {transferFlags} from './transferFlags.js';

@@ -80,3 +80,3 @@ /*!

exports.eql = require('deep-eql');
export {default as eql} from 'deep-eql';

@@ -87,15 +87,11 @@ /*!

exports.getPathInfo = pathval.getPathInfo;
export {getPathInfo, hasProperty} from 'pathval';
/*!
* Check if a property exists
*/
exports.hasProperty = pathval.hasProperty;
/*!
* Function name
*/
exports.getName = require('get-func-name');
export function getName(fn) {
return fn.name
}

@@ -106,3 +102,3 @@ /*!

exports.addProperty = require('./addProperty');
export {addProperty} from './addProperty.js';

@@ -113,3 +109,3 @@ /*!

exports.addMethod = require('./addMethod');
export {addMethod} from './addMethod.js';

@@ -120,3 +116,3 @@ /*!

exports.overwriteProperty = require('./overwriteProperty');
export {overwriteProperty} from './overwriteProperty.js';

@@ -127,3 +123,3 @@ /*!

exports.overwriteMethod = require('./overwriteMethod');
export {overwriteMethod} from './overwriteMethod.js';

@@ -134,3 +130,3 @@ /*!

exports.addChainableMethod = require('./addChainableMethod');
export {addChainableMethod} from './addChainableMethod.js';

@@ -141,3 +137,3 @@ /*!

exports.overwriteChainableMethod = require('./overwriteChainableMethod');
export {overwriteChainableMethod} from './overwriteChainableMethod.js';

@@ -148,3 +144,3 @@ /*!

exports.compareByInspect = require('./compareByInspect');
export {compareByInspect} from './compareByInspect.js';

@@ -155,3 +151,3 @@ /*!

exports.getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
export {getOwnEnumerablePropertySymbols} from './getOwnEnumerablePropertySymbols.js';

@@ -162,3 +158,3 @@ /*!

exports.getOwnEnumerableProperties = require('./getOwnEnumerableProperties');
export {getOwnEnumerableProperties} from './getOwnEnumerableProperties.js';

@@ -169,3 +165,3 @@ /*!

exports.checkError = require('check-error');
export {checkError};

@@ -176,3 +172,3 @@ /*!

exports.proxify = require('./proxify');
export {proxify} from './proxify.js';

@@ -183,3 +179,3 @@ /*!

exports.addLengthGuard = require('./addLengthGuard');
export {addLengthGuard} from './addLengthGuard.js';

@@ -190,3 +186,3 @@ /*!

exports.isProxyEnabled = require('./isProxyEnabled');
export {isProxyEnabled} from './isProxyEnabled.js';

@@ -197,3 +193,3 @@ /*!

exports.isNaN = require('./isNaN');
export {isNaN} from './isNaN.js';

@@ -204,2 +200,2 @@ /*!

exports.getOperator = require('./getOperator');
export {getOperator} from './getOperator.js';
// This is (almost) directly from Node.js utils
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
var getName = require('get-func-name');
var loupe = require('loupe');
var config = require('../config');
import {inspect as _inspect} from 'loupe';
import {config} from '../config.js';
module.exports = inspect;
/**

@@ -25,3 +22,3 @@ * ### .inspect(obj, [showHidden], [depth], [colors])

*/
function inspect(obj, showHidden, depth, colors) {
export function inspect(obj, showHidden, depth, colors) {
var options = {

@@ -33,3 +30,3 @@ colors: colors,

};
return loupe.inspect(obj, options);
return _inspect(obj, options);
}

@@ -19,3 +19,3 @@ /*!

function isNaN(value) {
function _isNaN(value) {
// Refer http://www.ecma-international.org/ecma-262/6.0/#sec-isnan-number

@@ -27,2 +27,2 @@ // section's NOTE.

// If ECMAScript 6's Number.isNaN is present, prefer that.
module.exports = Number.isNaN || isNaN;
export const isNaN = Number.isNaN || _isNaN;

@@ -1,2 +0,2 @@

var config = require('../config');
import {config} from '../config.js';

@@ -20,6 +20,6 @@ /*!

module.exports = function isProxyEnabled() {
export function isProxyEnabled() {
return config.useProxy &&
typeof Proxy !== 'undefined' &&
typeof Reflect !== 'undefined';
};
}

@@ -11,4 +11,4 @@ /*!

var inspect = require('./inspect');
var config = require('../config');
import {inspect} from './inspect.js';
import {config} from '../config.js';

@@ -29,3 +29,3 @@ /**

module.exports = function objDisplay(obj) {
export function objDisplay(obj) {
var str = inspect(obj)

@@ -53,2 +53,2 @@ , type = Object.prototype.toString.call(obj);

}
};
}

@@ -7,4 +7,4 @@ /*!

var chai = require('../../chai');
var transferFlags = require('./transferFlags');
import {Assertion} from '../assertion.js';
import {transferFlags} from './transferFlags.js';

@@ -44,3 +44,3 @@ /**

module.exports = function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
export function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
var chainableBehavior = ctx.__methods[name];

@@ -55,3 +55,3 @@

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);

@@ -68,6 +68,6 @@ return newAssertion;

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);
return newAssertion;
};
};
}

@@ -7,7 +7,7 @@ /*!

var addLengthGuard = require('./addLengthGuard');
var chai = require('../../chai');
var flag = require('./flag');
var proxify = require('./proxify');
var transferFlags = require('./transferFlags');
import {Assertion} from '../assertion.js';
import {addLengthGuard} from './addLengthGuard.js';
import {flag} from './flag.js';
import {proxify} from './proxify.js';
import {transferFlags} from './transferFlags.js';

@@ -48,3 +48,3 @@ /**

module.exports = function overwriteMethod(ctx, name, method) {
export function overwriteMethod(ctx, name, method) {
var _method = ctx[name]

@@ -87,3 +87,3 @@ , _super = function () {

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);

@@ -95,2 +95,2 @@ return newAssertion;

ctx[name] = proxify(overwritingMethodWrapper, name);
};
}

@@ -7,6 +7,6 @@ /*!

var chai = require('../../chai');
var flag = require('./flag');
var isProxyEnabled = require('./isProxyEnabled');
var transferFlags = require('./transferFlags');
import {Assertion} from '../assertion.js';
import {flag} from './flag.js';
import {isProxyEnabled} from './isProxyEnabled.js';
import {transferFlags} from './transferFlags.js';

@@ -47,3 +47,3 @@ /**

module.exports = function overwriteProperty(ctx, name, getter) {
export function overwriteProperty(ctx, name, getter) {
var _get = Object.getOwnPropertyDescriptor(ctx, name)

@@ -88,3 +88,3 @@ , _super = function () {};

var newAssertion = new chai.Assertion();
var newAssertion = new Assertion();
transferFlags(this, newAssertion);

@@ -95,2 +95,2 @@ return newAssertion;

});
};
}

@@ -1,5 +0,5 @@

var config = require('../config');
var flag = require('./flag');
var getProperties = require('./getProperties');
var isProxyEnabled = require('./isProxyEnabled');
import {config} from '../config.js';
import {flag} from './flag.js';
import {getProperties} from './getProperties.js';
import {isProxyEnabled} from './isProxyEnabled.js';

@@ -31,5 +31,5 @@ /*!

var builtins = ['__flags', '__methods', '_obj', 'assert'];
const builtins = ['__flags', '__methods', '_obj', 'assert'];
module.exports = function proxify(obj, nonChainableMethodName) {
export function proxify(obj ,nonChainableMethodName) {
if (!isProxyEnabled()) return obj;

@@ -102,3 +102,3 @@

});
};
}

@@ -105,0 +105,0 @@ /**

@@ -11,3 +11,3 @@ /*!

var flag = require('./flag');
import {flag} from './flag.js';

@@ -25,6 +25,6 @@ /**

module.exports = function test(obj, args) {
export function test(obj, args) {
var negate = flag(obj, 'negate')
, expr = args[0];
return negate ? !expr : expr;
};
}

@@ -30,3 +30,3 @@ /*!

module.exports = function transferFlags(assertion, object, includeAll) {
export function transferFlags(assertion, object, includeAll) {
var flags = assertion.__flags || (assertion.__flags = Object.create(null));

@@ -46,2 +46,2 @@

}
};
}
{
"author": "Jake Luer <jake@alogicalparadox.com>",
"name": "chai",
"type": "module",
"description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic.",

@@ -20,3 +21,3 @@ "keywords": [

],
"version": "4.3.10",
"version": "5.0.0",
"repository": {

@@ -29,37 +30,32 @@ "type": "git",

},
"main": "./index",
"exports": {
".": {
"require": "./index.js",
"import": "./index.mjs"
},
"./*": "./*"
},
"main": "./chai.js",
"scripts": {
"test": "make test"
"prebuild": "npm run clean",
"build": "npm run build:esm",
"build:esm": "esbuild --bundle --format=esm --keep-names --outfile=chai.js index.js",
"pretest": "npm run build",
"test": "npm run test-node && npm run test-chrome",
"test-node": "mocha --require ./test/bootstrap/index.js --reporter dot test/*.js",
"test-chrome": "web-test-runner --playwright",
"clean": "rm -f chai.js coverage"
},
"engines": {
"node": ">=4"
"node": ">=12"
},
"dependencies": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.3",
"deep-eql": "^4.1.3",
"get-func-name": "^2.0.2",
"loupe": "^2.3.6",
"pathval": "^1.1.1",
"type-detect": "^4.0.8"
"assertion-error": "^2.0.1",
"check-error": "^2.0.0",
"deep-eql": "^5.0.1",
"loupe": "^3.0.0",
"pathval": "^2.0.0"
},
"devDependencies": {
"browserify": "^16.5.2",
"bump-cli": "^2.7.1",
"codecov": "^3.8.3",
"istanbul": "^0.4.5",
"karma": "^6.4.2",
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.3.0",
"karma-mocha": "^2.0.1",
"karma-sauce-launcher": "^4.1.4",
"mocha": "^10.2.0"
"@rollup/plugin-commonjs": "^25.0.7",
"@web/dev-server-rollup": "^0.5.4",
"@web/test-runner": "^0.17.2",
"@web/test-runner-playwright": "^0.10.2",
"bump-cli": "^1.1.3",
"esbuild": "^0.17.3",
"mocha": "^8.3.0"
}
}

@@ -14,14 +14,8 @@ <h1 align=center>

<p align=center>
<a href="./LICENSE">
<a href="https://www.npmjs.com/package/chai">
<img
alt="license:mit"
src="https://img.shields.io/badge/license-mit-green.svg?style=flat-square"
alt="downloads:?"
src="https://img.shields.io/npm/dm/chai.svg?style=flat-square"
/>
</a>
<a href="https://github.com/chaijs/chai/releases">
<img
alt="tag:?"
src="https://img.shields.io/github/tag/chaijs/chai.svg?style=flat-square"
/>
</a>
<a href="https://www.npmjs.com/package/chai">

@@ -34,34 +28,2 @@ <img

<br/>
<a href="https://saucelabs.com/u/chaijs">
<img
alt="Selenium Test Status"
src="https://saucelabs.com/browser-matrix/chaijs.svg"
/>
</a>
<br/>
<a href="https://www.npmjs.com/packages/chai">
<img
alt="downloads:?"
src="https://img.shields.io/npm/dm/chai.svg?style=flat-square"
/>
</a>
<a href="https://travis-ci.org/chaijs/chai">
<img
alt="build:?"
src="https://img.shields.io/travis/chaijs/chai/master.svg?style=flat-square"
/>
</a>
<a href="https://codecov.io/gh/chaijs/chai">
<img
alt="coverage:?"
src="https://img.shields.io/codecov/c/github/chaijs/chai.svg?style=flat-square"
/>
</a>
<a href="">
<img
alt="devDependencies:?"
src="https://img.shields.io/david/chaijs/chai.svg?style=flat-square"
/>
</a>
<br/>
<a href="https://chai-slack.herokuapp.com/">

@@ -182,7 +144,5 @@ <img

- [chaijs / deep-eql](https://github.com/chaijs/deep-eql): Improved deep equality testing for Node.js and the browser.
- [chaijs / type-detect](https://github.com/chaijs/type-detect): Improved typeof detection for Node.js and the browser.
- [chaijs / check-error](https://github.com/chaijs/check-error): Error comparison and information related utility for Node.js and the browser.
- [chaijs / loupe](https://github.com/chaijs/loupe): Inspect utility for Node.js and browsers.
- [chaijs / pathval](https://github.com/chaijs/pathval): Object value retrieval given a string path.
- [chaijs / get-func-name](https://github.com/chaijs/get-func-name): Utility for getting a function's name for node and the browser.

@@ -189,0 +149,0 @@ ### Contributing

@@ -1,1 +0,3 @@

global.assert = require('./').assert;
import {assert} from './index.js';
globalThis.assert = assert;

@@ -1,1 +0,3 @@

global.expect = require('./').expect;
import {expect} from './index.js';
globalThis.expect = expect;

@@ -1,1 +0,3 @@

global.should = require('./').should();
import {should} from './index.js';
globalThis.should = should();

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc