Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai

Package Overview
Dependencies
Maintainers
1
Versions
97
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.0.0-canary.1 to 4.0.0-canary.2

lib/chai/utils/addLengthGuard.js

35

lib/chai/assertion.js

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

*
* `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, stack) {
flag(this, 'ssfi', stack || Assertion);
function Assertion (obj, msg, ssfi, lockSsfi) {
flag(this, 'ssfi', ssfi || Assertion);
flag(this, 'lockSsfi', lockSsfi);
flag(this, 'object', obj);

@@ -36,0 +67,0 @@ flag(this, 'message', msg);

67

lib/chai/utils/addChainableMethod.js

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

var addLengthGuard = require('./addLengthGuard');
var chai = require('../../chai');

@@ -21,9 +22,11 @@ var flag = require('./flag');

// Check whether `__proto__` is supported
var hasProtoSupport = '__proto__' in Object;
// Check whether `Object.setPrototypeOf` is supported
var canSetPrototype = typeof Object.setPrototypeOf === 'function';
// Without `__proto__` support, this module will need to add properties to a function.
// However, some Function.prototype methods cannot be overwritten,
// and there seems no easy cross-platform way to detect them (@see chaijs/chai/issues/69).
var excludeNames = /^(?:length|name|arguments|caller)$/;
// Without `Object.setPrototypeOf` support, this module will need to add properties to a function.
// However, some of functions' own props are not configurable and should be skipped.
var testFn = function() {};
var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) {
return !Object.getOwnPropertyDescriptor(testFn, name).configurable;
});

@@ -35,3 +38,3 @@ // Cache `Function` properties

/**
* ### addChainableMethod (ctx, name, method, chainingBehavior)
* ### .addChainableMethod(ctx, name, method, chainingBehavior)
*

@@ -64,3 +67,3 @@ * Adds a method to an object, such that the method can also be chained.

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

@@ -82,11 +85,26 @@ chainingBehavior = function () { };

Object.defineProperty(ctx, name,
{ get: function () {
{ get: function chainableMethodGetter() {
chainableBehavior.chainingBehavior.call(this);
var assert = function assert() {
var old_ssfi = flag(this, 'ssfi');
if (old_ssfi)
flag(this, 'ssfi', assert);
var chainableMethodWrapper = function () {
// Setting the `ssfi` flag to `chainableMethodWrapper` causes this
// function to be the starting point for removing implementation
// frames from the stack trace of a failed assertion.
//
// However, we only want to use this function as the starting point if
// the `lockSsfi` flag isn't set.
//
// If the `lockSsfi` flag is set, then this assertion is being
// invoked from inside of another assertion. In this case, the `ssfi`
// flag has already been set by the outer assertion.
//
// Note that overwriting a chainable method merely replaces the saved
// methods in `ctx.__methods` instead of completely replacing the
// overwritten assertion. Therefore, an overwriting assertion won't
// set the `ssfi` or `lockSsfi` flags.
if (!flag(this, 'lockSsfi')) {
flag(this, 'ssfi', chainableMethodWrapper);
}
var result = chainableBehavior.method.apply(this, arguments);
if (result !== undefined) {

@@ -101,9 +119,12 @@ return result;

// Use `__proto__` if available
if (hasProtoSupport) {
addLengthGuard(chainableMethodWrapper, name, true);
// Use `Object.setPrototypeOf` if available
if (canSetPrototype) {
// Inherit all properties from the object by replacing the `Function` prototype
var prototype = assert.__proto__ = Object.create(this);
var prototype = Object.create(this);
// Restore the `call` and `apply` methods from `Function`
prototype.call = call;
prototype.apply = apply;
Object.setPrototypeOf(chainableMethodWrapper, prototype);
}

@@ -114,11 +135,13 @@ // Otherwise, redefine all properties (slow!)

asserterNames.forEach(function (asserterName) {
if (!excludeNames.test(asserterName)) {
var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
Object.defineProperty(assert, asserterName, pd);
if (excludeNames.indexOf(asserterName) !== -1) {
return;
}
var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
Object.defineProperty(chainableMethodWrapper, asserterName, pd);
});
}
transferFlags(this, assert);
return proxify(assert);
transferFlags(this, chainableMethodWrapper);
return proxify(chainableMethodWrapper);
}

@@ -125,0 +148,0 @@ , configurable: true

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

var addLengthGuard = require('./addLengthGuard');
var chai = require('../../chai');

@@ -14,3 +15,3 @@ var flag = require('./flag');

/**
* ### .addMethod (ctx, name, method)
* ### .addMethod(ctx, name, method)
*

@@ -40,8 +41,19 @@ * Adds a method to the prototype of an object.

module.exports = function (ctx, name, method) {
var fn = function () {
var keep_ssfi = flag(this, 'keep_ssfi');
var old_ssfi = flag(this, 'ssfi');
if (!keep_ssfi && old_ssfi)
flag(this, 'ssfi', fn);
module.exports = function addMethod(ctx, name, method) {
var methodWrapper = function () {
// Setting the `ssfi` flag to `methodWrapper` causes this function to be the
// starting point for removing implementation frames from the stack trace of
// a failed assertion.
//
// However, we only want to use this function as the starting point if the
// `lockSsfi` flag isn't set.
//
// If the `lockSsfi` flag is set, then either this assertion has been
// overwritten by another assertion, or this assertion is being invoked from
// inside of another assertion. In the first case, the `ssfi` flag has
// already been set by the overwriting assertion. In the second case, the
// `ssfi` flag has already been set by the outer assertion.
if (!flag(this, 'lockSsfi')) {
flag(this, 'ssfi', methodWrapper);
}

@@ -57,3 +69,4 @@ var result = method.apply(this, arguments);

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

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

var flag = require('./flag');
var isProxyEnabled = require('./isProxyEnabled');
var transferFlags = require('./transferFlags');
/**
* ### addProperty (ctx, name, getter)
* ### .addProperty(ctx, name, getter)
*

@@ -38,11 +39,25 @@ * Adds a property to the prototype of an object.

module.exports = function (ctx, name, getter) {
module.exports = function addProperty(ctx, name, getter) {
getter = getter === undefined ? new Function() : getter;
Object.defineProperty(ctx, name,
{ get: function addProperty() {
var keep_ssfi = flag(this, 'keep_ssfi');
var old_ssfi = flag(this, 'ssfi');
if (!keep_ssfi && old_ssfi)
flag(this, 'ssfi', addProperty);
{ get: function propertyGetter() {
// Setting the `ssfi` flag to `propertyGetter` causes this function to
// be the starting point for removing implementation frames from the
// stack trace of a failed assertion.
//
// However, we only want to use this function as the starting point if
// the `lockSsfi` flag isn't set and proxy protection is disabled.
//
// If the `lockSsfi` flag is set, then either this assertion has been
// overwritten by another assertion, or this assertion is being invoked
// from inside of another assertion. In the first case, the `ssfi` flag
// has already been set by the overwriting assertion. In the second
// case, the `ssfi` flag has already been set by the outer assertion.
//
// If proxy protection is enabled, then the `ssfi` flag has already been
// set by the proxy getter.
if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
flag(this, 'ssfi', propertyGetter);
}

@@ -49,0 +64,0 @@ var result = getter.call(this);

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

/**
* ### .compareByInspect (mixed, mixed)
* ### .compareByInspect(mixed, mixed)
*

@@ -30,4 +30,4 @@ * To be used as a compareFunction with Array.prototype.sort. Compares elements

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

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

/**
* ### expectTypes(obj, types)
* ### .expectTypes(obj, types)
*

@@ -17,2 +17,4 @@ * Ensures that the object being tested against is of a valid type.

* @param {Array} type A list of allowed types for this assertion
* @param {Function} ssfi starting point for removing implementation frames from
* stack trace of AssertionError
* @namespace Utils

@@ -27,3 +29,7 @@ * @name expectTypes

module.exports = function (obj, types) {
module.exports = function expectTypes(obj, types, ssfi) {
var flagMsg = flag(obj, 'message');
flagMsg = flagMsg ? flagMsg + ': ' : '';
obj = flag(obj, 'object');

@@ -44,5 +50,7 @@ types = types.map(function (t) { return t.toLowerCase(); });

throw new AssertionError(
'object tested must be ' + str + ', but ' + objType + ' given'
flagMsg + 'object tested must be ' + str + ', but ' + objType + ' given',
undefined,
ssfi
);
}
};

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

/**
* ### flag(object, key, [value])
* ### .flag(object, key, [value])
*

@@ -27,3 +27,3 @@ * Get or set a flag value on an object. If a

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

@@ -30,0 +30,0 @@ if (arguments.length === 3) {

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

/**
* # getActual(object, [actual])
* ### .getActual(object, [actual])
*

@@ -19,4 +19,4 @@ * Returns the `actual` value for an Assertion.

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

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

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

@@ -38,0 +38,0 @@ , val = flag(obj, 'object')

@@ -157,2 +157,14 @@ /*!

/*!
* addLengthGuard util
*/
exports.addLengthGuard = require('./addLengthGuard');
/*!
* isProxyEnabled helper
*/
exports.isProxyEnabled = require('./isProxyEnabled');
/*!
* isNaN method

@@ -159,0 +171,0 @@ */

@@ -12,2 +12,4 @@ // This is (almost) directly from Node.js utils

/**
* ### .inspect(obj, [showHidden], [depth], [colors])
*
* Echoes the value of a value. Tries to print the value out

@@ -18,3 +20,3 @@ * in the best way possible given the different types.

* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
* properties of objects.
* properties of objects. Default is false.
* @param {Number} depth Depth in which to descend in object. Default is 2.

@@ -21,0 +23,0 @@ * @param {Boolean} colors Flag to turn on ANSI escape codes to color the

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

/**
* ### isNaN(value)
* ### .isNaN(value)
*

@@ -11,0 +11,0 @@ * Checks if the given value is NaN or not.

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

/**
* ### .objDisplay (object)
* ### .objDisplay(object)
*

@@ -28,3 +28,3 @@ * Determines if an object or an array matches

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

@@ -31,0 +31,0 @@ , type = Object.prototype.toString.call(obj);

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

/**
* ### overwriteChainableMethod (ctx, name, method, chainingBehavior)
* ### .overwriteChainableMethod(ctx, name, method, chainingBehavior)
*

@@ -19,3 +19,3 @@ * Overwites an already existing chainable method

*
* utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
* utils.overwriteChainableMethod(chai.Assertion.prototype, 'lengthOf',
* function (_super) {

@@ -33,4 +33,4 @@ * }

*
* expect(myFoo).to.have.length(3);
* expect(myFoo).to.have.length.above(3);
* expect(myFoo).to.have.lengthOf(3);
* expect(myFoo).to.have.lengthOf.above(3);
*

@@ -46,7 +46,7 @@ * @param {Object} ctx object whose method / property is to be overwritten

module.exports = function (ctx, name, method, chainingBehavior) {
module.exports = function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
var chainableBehavior = ctx.__methods[name];
var _chainingBehavior = chainableBehavior.chainingBehavior;
chainableBehavior.chainingBehavior = function () {
chainableBehavior.chainingBehavior = function overwritingChainableMethodGetter() {
var result = chainingBehavior(_chainingBehavior).call(this);

@@ -63,3 +63,3 @@ if (result !== undefined) {

var _method = chainableBehavior.method;
chainableBehavior.method = function () {
chainableBehavior.method = function overwritingChainableMethodWrapper() {
var result = method(_method).apply(this, arguments);

@@ -66,0 +66,0 @@ if (result !== undefined) {

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

var addLengthGuard = require('./addLengthGuard');
var chai = require('../../chai');

@@ -14,3 +15,3 @@ var flag = require('./flag');

/**
* ### overwriteMethod (ctx, name, fn)
* ### .overwriteMethod(ctx, name, fn)
*

@@ -48,3 +49,3 @@ * Overwites an already existing method and provides

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

@@ -58,11 +59,26 @@ , _super = function () {

var fn = function () {
var keep_ssfi = flag(this, 'keep_ssfi');
var old_ssfi = flag(this, 'ssfi');
if (!keep_ssfi && old_ssfi)
flag(this, 'ssfi', fn);
var overwritingMethodWrapper = function () {
// Setting the `ssfi` flag to `overwritingMethodWrapper` causes this
// function to be the starting point for removing implementation frames from
// the stack trace of a failed assertion.
//
// However, we only want to use this function as the starting point if the
// `lockSsfi` flag isn't set.
//
// If the `lockSsfi` flag is set, then either this assertion has been
// overwritten by another assertion, or this assertion is being invoked from
// inside of another assertion. In the first case, the `ssfi` flag has
// already been set by the overwriting assertion. In the second case, the
// `ssfi` flag has already been set by the outer assertion.
if (!flag(this, 'lockSsfi')) {
flag(this, 'ssfi', overwritingMethodWrapper);
}
flag(this, 'keep_ssfi', true);
// Setting the `lockSsfi` flag to `true` prevents the overwritten assertion
// from changing the `ssfi` flag. By this point, the `ssfi` flag is already
// set to the correct starting point for this assertion.
var origLockSsfi = flag(this, 'lockSsfi');
flag(this, 'lockSsfi', true);
var result = method(_super).apply(this, arguments);
flag(this, 'keep_ssfi', false);
flag(this, 'lockSsfi', origLockSsfi);

@@ -78,3 +94,4 @@ if (result !== undefined) {

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

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

var flag = require('./flag');
var isProxyEnabled = require('./isProxyEnabled');
var transferFlags = require('./transferFlags');
/**
* ### overwriteProperty (ctx, name, fn)
* ### .overwriteProperty(ctx, name, fn)
*

@@ -46,3 +47,3 @@ * Overwites an already existing property getter and provides

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

@@ -55,11 +56,29 @@ , _super = function () {};

Object.defineProperty(ctx, name,
{ get: function overwriteProperty() {
var keep_ssfi = flag(this, 'keep_ssfi');
var old_ssfi = flag(this, 'ssfi');
if (!keep_ssfi && old_ssfi)
flag(this, 'ssfi', overwriteProperty);
{ get: function overwritingPropertyGetter() {
// Setting the `ssfi` flag to `overwritingPropertyGetter` causes this
// function to be the starting point for removing implementation frames
// from the stack trace of a failed assertion.
//
// However, we only want to use this function as the starting point if
// the `lockSsfi` flag isn't set and proxy protection is disabled.
//
// If the `lockSsfi` flag is set, then either this assertion has been
// overwritten by another assertion, or this assertion is being invoked
// from inside of another assertion. In the first case, the `ssfi` flag
// has already been set by the overwriting assertion. In the second
// case, the `ssfi` flag has already been set by the outer assertion.
//
// If proxy protection is enabled, then the `ssfi` flag has already been
// set by the proxy getter.
if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
flag(this, 'ssfi', overwritingPropertyGetter);
}
flag(this, 'keep_ssfi', true);
// Setting the `lockSsfi` flag to `true` prevents the overwritten
// assertion from changing the `ssfi` flag. By this point, the `ssfi`
// flag is already set to the correct starting point for this assertion.
var origLockSsfi = flag(this, 'lockSsfi');
flag(this, 'lockSsfi', true);
var result = getter(_super).call(this);
flag(this, 'keep_ssfi', false);
flag(this, 'lockSsfi', origLockSsfi);

@@ -66,0 +85,0 @@ if (result !== undefined) {

var config = require('../config');
var flag = require('./flag');
var getProperties = require('./getProperties');
var isProxyEnabled = require('./isProxyEnabled');

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

/**
* # proxify(object)
* ### .proxify(object)
*

@@ -30,8 +32,9 @@ * Return a proxy of given object that throws an error when a non-existent

module.exports = function proxify (obj, nonChainableMethodName) {
if (!config.useProxy || typeof Proxy === 'undefined' || typeof Reflect === 'undefined')
return obj;
var builtins = ['__flags', '__methods', '_obj', 'assert'];
module.exports = function proxify(obj, nonChainableMethodName) {
if (!isProxyEnabled()) return obj;
return new Proxy(obj, {
get: function getProperty (target, property) {
get: function proxyGetter(target, property) {
// This check is here because we should not throw errors on Symbol properties

@@ -53,3 +56,3 @@ // such as `Symbol.toStringTag`.

return !Object.prototype.hasOwnProperty(property) &&
['__flags', '__methods', '_obj', 'assert'].indexOf(property) === -1;
builtins.indexOf(property) === -1;
}).sort(function(a, b) {

@@ -70,3 +73,19 @@ return stringDistance(property, a) - stringDistance(property, b);

return target[property];
// Use this proxy getter as the starting point for removing implementation
// frames from the stack trace of a failed assertion. For property
// assertions, this prevents the proxy getter from showing up in the stack
// trace since it's invoked before the property getter. For method and
// chainable method assertions, this flag will end up getting changed to
// the method wrapper, which is good since this frame will no longer be in
// the stack once the method is invoked. Note that Chai builtin assertion
// properties such as `__flags` are skipped since this is only meant to
// capture the starting point of an assertion. This step is also skipped
// if the `lockSsfi` flag is set, thus indicating that this assertion is
// being called from within another assertion. In that case, the `ssfi`
// flag is already set to the outer assertion's starting point.
if (builtins.indexOf(property) === -1 && !flag(target, 'lockSsfi')) {
flag(target, 'ssfi', proxyGetter);
}
return Reflect.get(target, property);
}

@@ -73,0 +92,0 @@ });

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

/**
* # test(object, expression)
* ### .test(object, expression)
*

@@ -25,3 +25,3 @@ * Test and object for expression.

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

@@ -28,0 +28,0 @@ , expr = args[0];

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

/**
* ### transferFlags(assertion, object, includeAll = true)
* ### .transferFlags(assertion, object, includeAll = true)
*
* Transfer all the flags for `assertion` to `object`. If
* `includeAll` is set to `false`, then the base Chai
* assertion flags (namely `object`, `ssfi`, and `message`)
* will not be transferred.
* assertion flags (namely `object`, `ssfi`, `lockSsfi`,
* and `message`) will not be transferred.
*

@@ -31,3 +31,3 @@ *

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

@@ -43,3 +43,3 @@

if (includeAll ||
(flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
(flag !== 'object' && flag !== 'ssfi' && flag !== 'lockSsfi' && flag != 'message')) {
object.__flags[flag] = flags[flag];

@@ -46,0 +46,0 @@ }

@@ -20,3 +20,3 @@ {

],
"version": "4.0.0-canary.1",
"version": "4.0.0-canary.2",
"repository": {

@@ -30,2 +30,3 @@ "type": "git",

"main": "./index",
"browser": "./chai.js",
"scripts": {

@@ -35,3 +36,3 @@ "test": "make test"

"engines": {
"node": ">=0.10"
"node": ">=4"
},

@@ -41,4 +42,4 @@ "dependencies": {

"check-error": "^1.0.1",
"deep-eql": "^1.0.3",
"get-func-name": "^1.0.0",
"deep-eql": "^2.0.1",
"get-func-name": "^2.0.0",
"pathval": "^1.0.0",

@@ -45,0 +46,0 @@ "type-detect": "^4.0.0"

<h1 align=center>
<a href="http://chaijs.com" title="Chai Documentation">
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png"/> chai
<img alt="ChaiJS" src="http://chaijs.com/img/chai-logo.png">
</a>
<br>
chai
</h1>

@@ -110,11 +112,52 @@

```js
var chai = require('chai');
// Using Assert style
var assert = chai.assert;
// Using Expect style
var expect = chai.expect;
// Using Should style
var should = chai.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_)
```js
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_)
```js
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_)
```js
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_)
```js
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
```bash
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](http://chaijs.com/guide/styles/).

@@ -121,0 +164,0 @@

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