diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 2b9c0f90..415e1452 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -11,37 +11,25 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 - run: npm ci + - run: npx playwright install --with-deps + - run: npm run build --if-present - run: npm test publish-npm: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} - - publish-gpr: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: 18 - registry-url: https://npm.pkg.github.com/ - - run: npm ci - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/lib/chai.js b/lib/chai.js index 7569595c..ca7be863 100644 --- a/lib/chai.js +++ b/lib/chai.js @@ -15,10 +15,7 @@ import {assert} from './chai/interface/assert.js'; const used = []; -/*! - * Assertion Error - */ - +// Assertion Error export {AssertionError}; /** @@ -30,7 +27,6 @@ export {AssertionError}; * @returns {this} for chaining * @api public */ - export function use(fn) { const exports = { AssertionError, @@ -50,38 +46,20 @@ export function use(fn) { return exports; }; -/*! - * Utility Functions - */ - +// Utility Functions export {util}; -/*! - * Configuration - */ - +// Configuration export {config}; -/*! - * Primary `Assertion` prototype - */ - +// Primary `Assertion` prototype export * from './chai/assertion.js'; -/*! - * Expect interface - */ - +// Expect interface export * from './chai/interface/expect.js'; -/*! - * Should interface - */ - +// Should interface export * from './chai/interface/should.js'; -/*! - * Assert interface - */ - +// Assert interface export * from './chai/interface/assert.js'; diff --git a/lib/chai/assertion.js b/lib/chai/assertion.js index c8c416d1..e8e1e597 100644 --- a/lib/chai/assertion.js +++ b/lib/chai/assertion.js @@ -9,7 +9,7 @@ import {config} from './config.js'; import {AssertionError} from 'assertion-error'; import * as util from './utils/index.js'; -/*! +/** * Assertion Constructor * * Creates object for chaining. @@ -147,14 +147,13 @@ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, } }; -/*! +/** * ### ._obj * * Quick reference to stored `actual` value for plugin developers. * * @api private */ - Object.defineProperty(Assertion.prototype, '_obj', { get: function () { return util.flag(this, 'object'); diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index 0a55c58e..7b3b1a4b 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -3037,7 +3037,9 @@ Assertion.addMethod('closeTo', closeTo); Assertion.addMethod('approximately', closeTo); // Note: Duplicates are ignored if testing for inclusion instead of sameness. -function isSubsetOf(subset, superset, cmp, contains, ordered) { +function isSubsetOf(_subset, _superset, cmp, contains, ordered) { + let superset = Array.from(_superset); + let subset = Array.from(_subset); if (!contains) { if (subset.length !== superset.length) return false; superset = superset.slice(); @@ -3133,15 +3135,14 @@ function isSubsetOf(subset, superset, cmp, contains, ordered) { * @namespace BDD * @api public */ - Assertion.addMethod('members', function (subset, msg) { if (msg) flag(this, 'message', msg); var obj = flag(this, 'object') , flagMsg = flag(this, 'message') , ssfi = flag(this, 'ssfi'); - new Assertion(obj, flagMsg, ssfi, true).to.be.an('array'); - new Assertion(subset, flagMsg, ssfi, true).to.be.an('array'); + new Assertion(obj, flagMsg, ssfi, true).to.be.iterable; + new Assertion(subset, flagMsg, ssfi, true).to.be.iterable; var contains = flag(this, 'contains'); var ordered = flag(this, 'ordered'); @@ -3170,6 +3171,39 @@ Assertion.addMethod('members', function (subset, msg) { ); }); +/** + * ### .iterable + * + * Asserts that the target is an iterable, which means that it has a iterator. + * + * expect([1, 2]).to.be.iterable; + * expect("foobar").to.be.iterable; + * + * Add `.not` earlier in the chain to negate `.iterable`. + * + * expect(1).to.not.be.iterable; + * expect(true).to.not.be.iterable; + * + * A custom error message can be given as the second argument to `expect`. + * + * expect(1, 'nooo why fail??').to.be.iterable; + * + * @name iterable + * @namespace BDD + * @api public + */ +Assertion.addProperty('iterable', function(msg) { + if (msg) flag(this, 'message', msg); + var obj = flag(this, 'object'); + + this.assert( + obj != undefined && obj[Symbol.iterator] + , 'expected #{this} to be an iterable' + , 'expected #{this} to not be an iterable' + , obj + ); +}); + /** * ### .oneOf(list[, msg]) * diff --git a/lib/chai/interface/assert.js b/lib/chai/interface/assert.js index 24ceff36..2d9fd9a3 100644 --- a/lib/chai/interface/assert.js +++ b/lib/chai/interface/assert.js @@ -8,7 +8,6 @@ import * as chai from '../../../index.js'; import {Assertion} from '../assertion.js'; import {flag, inspect} from '../utils/index.js'; import {AssertionError} from 'assertion-error'; -import {type} from '../utils/type-detect.js'; /** * ### assert(expression, message) @@ -18,13 +17,12 @@ import {type} from '../utils/type-detect.js'; * assert('foo' !== 'bar', 'foo is not bar'); * assert(Array.isArray([]), 'empty arrays are arrays'); * - * @param {Mixed} expression to test for truthiness + * @param {unknown} expression to test for truthiness * @param {String} message to display on error * @name assert * @namespace Assert - * @api public + * @public */ - function assert(express, errmsg) { var test = new Assertion(null, null, chai.assert, true); test.assert( @@ -50,14 +48,13 @@ export {assert}; * assert.fail(1, 2, undefined, ">"); * * @name fail - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @param {String} operator * @namespace Assert - * @api public + * @public */ - assert.fail = function (actual, expected, message, operator) { if (arguments.length < 2) { // Comply with Node's fail([message]) interface @@ -84,12 +81,11 @@ assert.fail = function (actual, expected, message, operator) { * * @name isOk * @alias ok - * @param {Mixed} object to test + * @param {unknown} object to test * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isOk = function (val, msg) { new Assertion(val, msg, assert.isOk, true).is.ok; }; @@ -104,12 +100,11 @@ assert.isOk = function (val, msg) { * * @name isNotOk * @alias notOk - * @param {Mixed} object to test + * @param {unknown} object to test * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotOk = function (val, msg) { new Assertion(val, msg, assert.isNotOk, true).is.not.ok; }; @@ -122,13 +117,12 @@ assert.isNotOk = function (val, msg) { * assert.equal(3, '3', '== coerces values to strings'); * * @name equal - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.equal = function (act, exp, msg) { var test = new Assertion(act, msg, assert.equal, true); @@ -150,13 +144,12 @@ assert.equal = function (act, exp, msg) { * assert.notEqual(3, 4, 'these numbers are not equal'); * * @name notEqual - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notEqual = function (act, exp, msg) { var test = new Assertion(act, msg, assert.notEqual, true); @@ -178,13 +171,12 @@ assert.notEqual = function (act, exp, msg) { * assert.strictEqual(true, true, 'these booleans are strictly equal'); * * @name strictEqual - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.strictEqual = function (act, exp, msg) { new Assertion(act, msg, assert.strictEqual, true).to.equal(exp); }; @@ -197,13 +189,12 @@ assert.strictEqual = function (act, exp, msg) { * assert.notStrictEqual(3, '3', 'no coercion for strict equality'); * * @name notStrictEqual - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notStrictEqual = function (act, exp, msg) { new Assertion(act, msg, assert.notStrictEqual, true).to.not.equal(exp); }; @@ -216,14 +207,13 @@ assert.notStrictEqual = function (act, exp, msg) { * assert.deepEqual({ tea: 'green' }, { tea: 'green' }); * * @name deepEqual - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @alias deepStrictEqual * @namespace Assert - * @api public + * @public */ - assert.deepEqual = assert.deepStrictEqual = function (act, exp, msg) { new Assertion(act, msg, assert.deepEqual, true).to.eql(exp); }; @@ -236,13 +226,12 @@ assert.deepEqual = assert.deepStrictEqual = function (act, exp, msg) { * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' }); * * @name notDeepEqual - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notDeepEqual = function (act, exp, msg) { new Assertion(act, msg, assert.notDeepEqual, true).to.not.eql(exp); }; @@ -255,13 +244,12 @@ assert.notDeepEqual = function (act, exp, msg) { * assert.isAbove(5, 2, '5 is strictly greater than 2'); * * @name isAbove - * @param {Mixed} valueToCheck - * @param {Mixed} valueToBeAbove + * @param {unknown} valueToCheck + * @param {unknown} valueToBeAbove * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isAbove = function (val, abv, msg) { new Assertion(val, msg, assert.isAbove, true).to.be.above(abv); }; @@ -275,13 +263,12 @@ assert.isAbove = function (val, abv, msg) { * assert.isAtLeast(3, 3, '3 is greater or equal to 3'); * * @name isAtLeast - * @param {Mixed} valueToCheck - * @param {Mixed} valueToBeAtLeast + * @param {unknown} valueToCheck + * @param {unknown} valueToBeAtLeast * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isAtLeast = function (val, atlst, msg) { new Assertion(val, msg, assert.isAtLeast, true).to.be.least(atlst); }; @@ -294,13 +281,12 @@ assert.isAtLeast = function (val, atlst, msg) { * assert.isBelow(3, 6, '3 is strictly less than 6'); * * @name isBelow - * @param {Mixed} valueToCheck - * @param {Mixed} valueToBeBelow + * @param {unknown} valueToCheck + * @param {unknown} valueToBeBelow * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isBelow = function (val, blw, msg) { new Assertion(val, msg, assert.isBelow, true).to.be.below(blw); }; @@ -314,13 +300,12 @@ assert.isBelow = function (val, blw, msg) { * assert.isAtMost(4, 4, '4 is less than or equal to 4'); * * @name isAtMost - * @param {Mixed} valueToCheck - * @param {Mixed} valueToBeAtMost + * @param {unknown} valueToCheck + * @param {unknown} valueToBeAtMost * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isAtMost = function (val, atmst, msg) { new Assertion(val, msg, assert.isAtMost, true).to.be.most(atmst); }; @@ -334,12 +319,11 @@ assert.isAtMost = function (val, atmst, msg) { * assert.isTrue(teaServed, 'the tea has been served'); * * @name isTrue - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isTrue = function (val, msg) { new Assertion(val, msg, assert.isTrue, true).is['true']; }; @@ -353,12 +337,11 @@ assert.isTrue = function (val, msg) { * assert.isNotTrue(tea, 'great, time for tea!'); * * @name isNotTrue - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotTrue = function (val, msg) { new Assertion(val, msg, assert.isNotTrue, true).to.not.equal(true); }; @@ -372,12 +355,11 @@ assert.isNotTrue = function (val, msg) { * assert.isFalse(teaServed, 'no tea yet? hmm...'); * * @name isFalse - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isFalse = function (val, msg) { new Assertion(val, msg, assert.isFalse, true).is['false']; }; @@ -391,12 +373,11 @@ assert.isFalse = function (val, msg) { * assert.isNotFalse(tea, 'great, time for tea!'); * * @name isNotFalse - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotFalse = function (val, msg) { new Assertion(val, msg, assert.isNotFalse, true).to.not.equal(false); }; @@ -409,12 +390,11 @@ assert.isNotFalse = function (val, msg) { * assert.isNull(err, 'there was no error'); * * @name isNull - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNull = function (val, msg) { new Assertion(val, msg, assert.isNull, true).to.equal(null); }; @@ -428,12 +408,11 @@ assert.isNull = function (val, msg) { * assert.isNotNull(tea, 'great, time for tea!'); * * @name isNotNull - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotNull = function (val, msg) { new Assertion(val, msg, assert.isNotNull, true).to.not.equal(null); }; @@ -446,12 +425,11 @@ assert.isNotNull = function (val, msg) { * assert.isNaN(NaN, 'NaN is NaN'); * * @name isNaN - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNaN = function (val, msg) { new Assertion(val, msg, assert.isNaN, true).to.be.NaN; }; @@ -464,12 +442,11 @@ assert.isNaN = function (val, msg) { * assert.isNotNaN(4, '4 is not NaN'); * * @name isNotNaN - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public - */ -assert.isNotNaN = function (val, msg) { + * @public + */assert.isNotNaN = function (val, msg) { new Assertion(val, msg, assert.isNotNaN, true).not.to.be.NaN; }; @@ -483,12 +460,11 @@ assert.isNotNaN = function (val, msg) { * assert.exists(foo, 'foo is neither `null` nor `undefined`'); * * @name exists - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.exists = function (val, msg) { new Assertion(val, msg, assert.exists, true).to.exist; }; @@ -505,12 +481,11 @@ assert.exists = function (val, msg) { * assert.notExists(baz, 'baz is either null or undefined'); * * @name notExists - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notExists = function (val, msg) { new Assertion(val, msg, assert.notExists, true).to.not.exist; }; @@ -524,12 +499,11 @@ assert.notExists = function (val, msg) { * assert.isUndefined(tea, 'no tea defined'); * * @name isUndefined - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isUndefined = function (val, msg) { new Assertion(val, msg, assert.isUndefined, true).to.equal(undefined); }; @@ -543,12 +517,11 @@ assert.isUndefined = function (val, msg) { * assert.isDefined(tea, 'tea has been defined'); * * @name isDefined - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isDefined = function (val, msg) { new Assertion(val, msg, assert.isDefined, true).to.not.equal(undefined); }; @@ -562,12 +535,11 @@ assert.isDefined = function (val, msg) { * assert.isCallable(serveTea, 'great, we can have tea now'); * * @name isCallable - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public - */ -assert.isCallable = function (val, msg) { + * @public + */assert.isCallable = function (val, msg) { new Assertion(val, msg, assert.isCallable, true).is.callable; } @@ -580,12 +552,11 @@ assert.isCallable = function (val, msg) { * assert.isNotCallable(serveTea, 'great, we have listed the steps'); * * @name isNotCallable - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public - */ -assert.isNotCallable = function (val, msg) { + * @public + */assert.isNotCallable = function (val, msg) { new Assertion(val, msg, assert.isNotCallable, true).is.not.callable; }; @@ -599,12 +570,11 @@ assert.isNotCallable = function (val, msg) { * assert.isObject(selection, 'tea selection is an object'); * * @name isObject - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isObject = function (val, msg) { new Assertion(val, msg, assert.isObject, true).to.be.a('object'); }; @@ -619,12 +589,11 @@ assert.isObject = function (val, msg) { * assert.isNotObject(null, 'null is not an object'); * * @name isNotObject - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotObject = function (val, msg) { new Assertion(val, msg, assert.isNotObject, true).to.not.be.a('object'); }; @@ -638,12 +607,11 @@ assert.isNotObject = function (val, msg) { * assert.isArray(menu, 'what kind of tea do we want?'); * * @name isArray - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isArray = function (val, msg) { new Assertion(val, msg, assert.isArray, true).to.be.an('array'); }; @@ -657,12 +625,11 @@ assert.isArray = function (val, msg) { * assert.isNotArray(menu, 'what kind of tea do we want?'); * * @name isNotArray - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotArray = function (val, msg) { new Assertion(val, msg, assert.isNotArray, true).to.not.be.an('array'); }; @@ -676,12 +643,11 @@ assert.isNotArray = function (val, msg) { * assert.isString(teaOrder, 'order placed'); * * @name isString - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isString = function (val, msg) { new Assertion(val, msg, assert.isString, true).to.be.a('string'); }; @@ -695,12 +661,11 @@ assert.isString = function (val, msg) { * assert.isNotString(teaOrder, 'order placed'); * * @name isNotString - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotString = function (val, msg) { new Assertion(val, msg, assert.isNotString, true).to.not.be.a('string'); }; @@ -717,9 +682,8 @@ assert.isNotString = function (val, msg) { * @param {Number} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNumber = function (val, msg) { new Assertion(val, msg, assert.isNumber, true).to.be.a('number'); }; @@ -733,12 +697,11 @@ assert.isNumber = function (val, msg) { * assert.isNotNumber(cups, 'how many cups'); * * @name isNotNumber - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotNumber = function (val, msg) { new Assertion(val, msg, assert.isNotNumber, true).to.not.be.a('number'); }; @@ -757,9 +720,8 @@ assert.isNotNumber = function (val, msg) { * @param {Number} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isFinite = function (val, msg) { new Assertion(val, msg, assert.isFinite, true).to.be.finite; }; @@ -776,12 +738,11 @@ assert.isFinite = function (val, msg) { * assert.isBoolean(teaServed, 'has tea been served'); * * @name isBoolean - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isBoolean = function (val, msg) { new Assertion(val, msg, assert.isBoolean, true).to.be.a('boolean'); }; @@ -798,12 +759,11 @@ assert.isBoolean = function (val, msg) { * assert.isNotBoolean(teaServed, 'has tea been served'); * * @name isNotBoolean - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.isNotBoolean = function (val, msg) { new Assertion(val, msg, assert.isNotBoolean, true).to.not.be.a('boolean'); }; @@ -822,13 +782,12 @@ assert.isNotBoolean = function (val, msg) { * assert.typeOf(undefined, 'undefined', 'we have an undefined'); * * @name typeOf - * @param {Mixed} value + * @param {unknown} value * @param {String} name * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.typeOf = function (val, type, msg) { new Assertion(val, msg, assert.typeOf, true).to.be.a(type); }; @@ -842,13 +801,12 @@ assert.typeOf = function (val, type, msg) { * assert.notTypeOf('tea', 'number', 'strings are not numbers'); * * @name notTypeOf - * @param {Mixed} value + * @param {unknown} value * @param {String} typeof name * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notTypeOf = function (val, type, msg) { new Assertion(val, msg, assert.notTypeOf, true).to.not.be.a(type); }; @@ -868,9 +826,8 @@ assert.notTypeOf = function (val, type, msg) { * @param {Constructor} constructor * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.instanceOf = function (val, type, msg) { new Assertion(val, msg, assert.instanceOf, true).to.be.instanceOf(type); }; @@ -890,9 +847,8 @@ assert.instanceOf = function (val, type, msg) { * @param {Constructor} constructor * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notInstanceOf = function (val, type, msg) { new Assertion(val, msg, assert.notInstanceOf, true) .to.not.be.instanceOf(type); @@ -923,12 +879,11 @@ assert.notInstanceOf = function (val, type, msg) { * * @name include * @param {Array|String} haystack - * @param {Mixed} needle + * @param {unknown} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.include = function (exp, inc, msg) { new Assertion(exp, msg, assert.include, true).include(inc); }; @@ -959,12 +914,11 @@ assert.include = function (exp, inc, msg) { * * @name notInclude * @param {Array|String} haystack - * @param {Mixed} needle + * @param {unknown} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.notInclude, true).not.include(inc); }; @@ -984,12 +938,11 @@ assert.notInclude = function (exp, inc, msg) { * * @name deepInclude * @param {Array|String} haystack - * @param {Mixed} needle + * @param {unknown} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.deepInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.deepInclude, true).deep.include(inc); }; @@ -1009,12 +962,11 @@ assert.deepInclude = function (exp, inc, msg) { * * @name notDeepInclude * @param {Array|String} haystack - * @param {Mixed} needle + * @param {unknown} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notDeepInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc); }; @@ -1037,9 +989,8 @@ assert.notDeepInclude = function (exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.nestedInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc); }; @@ -1062,9 +1013,8 @@ assert.nestedInclude = function (exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notNestedInclude = function (exp, inc, msg) { new Assertion(exp, msg, assert.notNestedInclude, true) .not.nested.include(inc); @@ -1088,9 +1038,8 @@ assert.notNestedInclude = function (exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.deepNestedInclude = function(exp, inc, msg) { new Assertion(exp, msg, assert.deepNestedInclude, true) .deep.nested.include(inc); @@ -1114,9 +1063,8 @@ assert.deepNestedInclude = function(exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notDeepNestedInclude = function(exp, inc, msg) { new Assertion(exp, msg, assert.notDeepNestedInclude, true) .not.deep.nested.include(inc); @@ -1136,9 +1084,8 @@ assert.notDeepNestedInclude = function(exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.ownInclude = function(exp, inc, msg) { new Assertion(exp, msg, assert.ownInclude, true).own.include(inc); }; @@ -1146,7 +1093,7 @@ assert.ownInclude = function(exp, inc, msg) { /** * ### .notOwnInclude(haystack, needle, [message]) * - * Asserts that 'haystack' includes 'needle'. + * Asserts that 'haystack' does not include 'needle'. * Can be used to assert the absence of a subset of properties in an * object while ignoring inherited properties. * @@ -1159,9 +1106,8 @@ assert.ownInclude = function(exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notOwnInclude = function(exp, inc, msg) { new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc); }; @@ -1180,9 +1126,8 @@ assert.notOwnInclude = function(exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.deepOwnInclude = function(exp, inc, msg) { new Assertion(exp, msg, assert.deepOwnInclude, true) .deep.own.include(inc); @@ -1191,7 +1136,7 @@ assert.deepOwnInclude = function(exp, inc, msg) { /** * ### .notDeepOwnInclude(haystack, needle, [message]) * - * Asserts that 'haystack' includes 'needle'. + * Asserts that 'haystack' does not include 'needle'. * Can be used to assert the absence of a subset of properties in an * object while ignoring inherited properties and checking for deep equality. * @@ -1202,9 +1147,8 @@ assert.deepOwnInclude = function(exp, inc, msg) { * @param {Object} needle * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notDeepOwnInclude = function(exp, inc, msg) { new Assertion(exp, msg, assert.notDeepOwnInclude, true) .not.deep.own.include(inc); @@ -1218,13 +1162,12 @@ assert.notDeepOwnInclude = function(exp, inc, msg) { * assert.match('foobar', /^foo/, 'regexp matches'); * * @name match - * @param {Mixed} value + * @param {unknown} value * @param {RegExp} regexp * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.match = function (exp, re, msg) { new Assertion(exp, msg, assert.match, true).to.match(re); }; @@ -1237,13 +1180,12 @@ assert.match = function (exp, re, msg) { * assert.notMatch('foobar', /^foo/, 'regexp does not match'); * * @name notMatch - * @param {Mixed} value + * @param {unknown} value * @param {RegExp} regexp * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notMatch = function (exp, re, msg) { new Assertion(exp, msg, assert.notMatch, true).to.not.match(re); }; @@ -1262,9 +1204,8 @@ assert.notMatch = function (exp, re, msg) { * @param {String} property * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.property = function (obj, prop, msg) { new Assertion(obj, msg, assert.property, true).to.have.property(prop); }; @@ -1282,9 +1223,8 @@ assert.property = function (obj, prop, msg) { * @param {String} property * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notProperty = function (obj, prop, msg) { new Assertion(obj, msg, assert.notProperty, true) .to.not.have.property(prop); @@ -1302,12 +1242,11 @@ assert.notProperty = function (obj, prop, msg) { * @name propertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.propertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.propertyVal, true) .to.have.property(prop, val); @@ -1326,12 +1265,11 @@ assert.propertyVal = function (obj, prop, val, msg) { * @name notPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.notPropertyVal, true) .to.not.have.property(prop, val); @@ -1348,12 +1286,11 @@ assert.notPropertyVal = function (obj, prop, val, msg) { * @name deepPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.deepPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.deepPropertyVal, true) .to.have.deep.property(prop, val); @@ -1372,12 +1309,11 @@ assert.deepPropertyVal = function (obj, prop, val, msg) { * @name notDeepPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notDeepPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.notDeepPropertyVal, true) .to.not.have.deep.property(prop, val); @@ -1395,9 +1331,8 @@ assert.notDeepPropertyVal = function (obj, prop, val, msg) { * @param {Object} object * @param {String} property * @param {String} message - * @api public + * @public */ - assert.ownProperty = function (obj, prop, msg) { new Assertion(obj, msg, assert.ownProperty, true) .to.have.own.property(prop); @@ -1416,9 +1351,8 @@ assert.ownProperty = function (obj, prop, msg) { * @param {Object} object * @param {String} property * @param {String} message - * @api public + * @public */ - assert.notOwnProperty = function (obj, prop, msg) { new Assertion(obj, msg, assert.notOwnProperty, true) .to.not.have.own.property(prop); @@ -1436,11 +1370,10 @@ assert.notOwnProperty = function (obj, prop, msg) { * @name ownPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message - * @api public + * @public */ - assert.ownPropertyVal = function (obj, prop, value, msg) { new Assertion(obj, msg, assert.ownPropertyVal, true) .to.have.own.property(prop, value); @@ -1459,11 +1392,10 @@ assert.ownPropertyVal = function (obj, prop, value, msg) { * @name notOwnPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message - * @api public + * @public */ - assert.notOwnPropertyVal = function (obj, prop, value, msg) { new Assertion(obj, msg, assert.notOwnPropertyVal, true) .to.not.have.own.property(prop, value); @@ -1481,11 +1413,10 @@ assert.notOwnPropertyVal = function (obj, prop, value, msg) { * @name deepOwnPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message - * @api public + * @public */ - assert.deepOwnPropertyVal = function (obj, prop, value, msg) { new Assertion(obj, msg, assert.deepOwnPropertyVal, true) .to.have.deep.own.property(prop, value); @@ -1506,11 +1437,10 @@ assert.deepOwnPropertyVal = function (obj, prop, value, msg) { * @name notDeepOwnPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message - * @api public + * @public */ - assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) { new Assertion(obj, msg, assert.notDeepOwnPropertyVal, true) .to.not.have.deep.own.property(prop, value); @@ -1530,9 +1460,8 @@ assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) { * @param {String} property * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.nestedProperty = function (obj, prop, msg) { new Assertion(obj, msg, assert.nestedProperty, true) .to.have.nested.property(prop); @@ -1552,9 +1481,8 @@ assert.nestedProperty = function (obj, prop, msg) { * @param {String} property * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notNestedProperty = function (obj, prop, msg) { new Assertion(obj, msg, assert.notNestedProperty, true) .to.not.have.nested.property(prop); @@ -1572,12 +1500,11 @@ assert.notNestedProperty = function (obj, prop, msg) { * @name nestedPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.nestedPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.nestedPropertyVal, true) .to.have.nested.property(prop, val); @@ -1596,12 +1523,11 @@ assert.nestedPropertyVal = function (obj, prop, val, msg) { * @name notNestedPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notNestedPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.notNestedPropertyVal, true) .to.not.have.nested.property(prop, val); @@ -1619,12 +1545,11 @@ assert.notNestedPropertyVal = function (obj, prop, val, msg) { * @name deepNestedPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.deepNestedPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.deepNestedPropertyVal, true) .to.have.deep.nested.property(prop, val); @@ -1644,12 +1569,11 @@ assert.deepNestedPropertyVal = function (obj, prop, val, msg) { * @name notDeepNestedPropertyVal * @param {Object} object * @param {String} property - * @param {Mixed} value + * @param {unknown} value * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notDeepNestedPropertyVal = function (obj, prop, val, msg) { new Assertion(obj, msg, assert.notDeepNestedPropertyVal, true) .to.not.have.deep.nested.property(prop, val); @@ -1666,13 +1590,12 @@ assert.notDeepNestedPropertyVal = function (obj, prop, val, msg) { * assert.lengthOf(new Map([['a',1],['b',2],['c',3]]), 3, 'map has size of 3'); * * @name lengthOf - * @param {Mixed} object + * @param {unknown} object * @param {Number} length * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.lengthOf = function (exp, len, msg) { new Assertion(exp, msg, assert.lengthOf, true).to.have.lengthOf(len); }; @@ -1690,13 +1613,12 @@ assert.lengthOf = function (exp, len, msg) { * assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']); * * @name hasAnyKeys - * @param {Mixed} object + * @param {unknown} object * @param {Array|Object} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.hasAnyKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.hasAnyKeys, true).to.have.any.keys(keys); } @@ -1711,16 +1633,15 @@ assert.hasAnyKeys = function (obj, keys, msg) { * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']); * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337]); * assert.hasAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']); - * assert.hasAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']); + * assert.hasAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']); * * @name hasAllKeys - * @param {Mixed} object + * @param {unknown} object * @param {String[]} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.hasAllKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys); } @@ -1738,17 +1659,16 @@ assert.hasAllKeys = function (obj, keys, msg) { * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337}); * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}]); * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']); - * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}]); - * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']); + * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}]); + * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']); * * @name containsAllKeys - * @param {Mixed} object + * @param {unknown} object * @param {String[]} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.containsAllKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.containsAllKeys, true) .to.contain.all.keys(keys); @@ -1764,16 +1684,15 @@ assert.containsAllKeys = function (obj, keys, msg) { * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']); * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'}); * assert.doesNotHaveAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']); - * assert.doesNotHaveAnyKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']); + * assert.doesNotHaveAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{one: 'two'}, 'example']); * * @name doesNotHaveAnyKeys - * @param {Mixed} object + * @param {unknown} object * @param {String[]} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.doesNotHaveAnyKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true) .to.not.have.any.keys(keys); @@ -1789,16 +1708,15 @@ assert.doesNotHaveAnyKeys = function (obj, keys, msg) { * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']); * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'}); * assert.doesNotHaveAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']); - * assert.doesNotHaveAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']); + * assert.doesNotHaveAllKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{one: 'two'}, 'example']); * * @name doesNotHaveAllKeys - * @param {Mixed} object + * @param {unknown} object * @param {String[]} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.doesNotHaveAllKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.doesNotHaveAllKeys, true) .to.not.have.all.keys(keys); @@ -1821,13 +1739,12 @@ assert.doesNotHaveAllKeys = function (obj, keys, msg) { * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]); * * @name hasAnyDeepKeys - * @param {Mixed} object + * @param {unknown} object * @param {Array|Object} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.hasAnyDeepKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.hasAnyDeepKeys, true) .to.have.any.deep.keys(keys); @@ -1848,13 +1765,12 @@ assert.hasAnyDeepKeys = function (obj, keys, msg) { * assert.hasAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]); * * @name hasAllDeepKeys - * @param {Mixed} object + * @param {unknown} object * @param {Array|Object} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.hasAllDeepKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.hasAllDeepKeys, true) .to.have.all.deep.keys(keys); @@ -1875,13 +1791,12 @@ assert.hasAllDeepKeys = function (obj, keys, msg) { * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]); * * @name containsAllDeepKeys - * @param {Mixed} object + * @param {unknown} object * @param {Array|Object} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.containsAllDeepKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.containsAllDeepKeys, true) .to.contain.all.deep.keys(keys); @@ -1902,13 +1817,12 @@ assert.containsAllDeepKeys = function (obj, keys, msg) { * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{twenty: 'twenty'}, {fifty: 'fifty'}]); * * @name doesNotHaveAnyDeepKeys - * @param {Mixed} object + * @param {unknown} object * @param {Array|Object} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.doesNotHaveAnyDeepKeys, true) .to.not.have.any.deep.keys(keys); @@ -1929,13 +1843,12 @@ assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) { * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {fifty: 'fifty'}]); * * @name doesNotHaveAllDeepKeys - * @param {Mixed} object + * @param {unknown} object * @param {Array|Object} keys * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.doesNotHaveAllDeepKeys = function (obj, keys, msg) { new Assertion(obj, msg, assert.doesNotHaveAllDeepKeys, true) .to.not.have.all.deep.keys(keys); @@ -1969,9 +1882,8 @@ assert.doesNotHaveAllDeepKeys = function (obj, keys, msg) { * @param {String} message * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types * @namespace Assert - * @api public + * @public */ - assert.throws = function (fn, errorLike, errMsgMatcher, msg) { if ('string' === typeof errorLike || errorLike instanceof RegExp) { errMsgMatcher = errorLike; @@ -2009,9 +1921,8 @@ assert.throws = function (fn, errorLike, errMsgMatcher, msg) { * @param {String} message * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types * @namespace Assert - * @api public + * @public */ - assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, msg) { if ('string' === typeof errorLike || errorLike instanceof RegExp) { errMsgMatcher = errorLike; @@ -2031,14 +1942,13 @@ assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, msg) { * assert.operator(1, '>', 2, 'this will fail'); * * @name operator - * @param {Mixed} val1 + * @param {unknown} val1 * @param {String} operator - * @param {Mixed} val2 + * @param {unknown} val2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.operator = function (val, operator, val2, msg) { var ok; switch(operator) { @@ -2094,9 +2004,8 @@ assert.operator = function (val, operator, val2, msg) { * @param {Number} delta * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.closeTo = function (act, exp, delta, msg) { new Assertion(act, msg, assert.closeTo, true).to.be.closeTo(exp, delta); }; @@ -2114,9 +2023,8 @@ assert.closeTo = function (act, exp, delta, msg) { * @param {Number} delta * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.approximately = function (act, exp, delta, msg) { new Assertion(act, msg, assert.approximately, true) .to.be.approximately(exp, delta); @@ -2135,9 +2043,8 @@ assert.approximately = function (act, exp, delta, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.sameMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.sameMembers, true) .to.have.same.members(set2); @@ -2156,9 +2063,8 @@ assert.sameMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notSameMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.notSameMembers, true) .to.not.have.same.members(set2); @@ -2177,9 +2083,8 @@ assert.notSameMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.sameDeepMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.sameDeepMembers, true) .to.have.same.deep.members(set2); @@ -2198,9 +2103,8 @@ assert.sameDeepMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notSameDeepMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.notSameDeepMembers, true) .to.not.have.same.deep.members(set2); @@ -2219,9 +2123,8 @@ assert.notSameDeepMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.sameOrderedMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.sameOrderedMembers, true) .to.have.same.ordered.members(set2); @@ -2240,9 +2143,8 @@ assert.sameOrderedMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notSameOrderedMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.notSameOrderedMembers, true) .to.not.have.same.ordered.members(set2); @@ -2261,9 +2163,8 @@ assert.notSameOrderedMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.sameDeepOrderedMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.sameDeepOrderedMembers, true) .to.have.same.deep.ordered.members(set2); @@ -2283,9 +2184,8 @@ assert.sameDeepOrderedMembers = function (set1, set2, msg) { * @param {Array} set2 * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notSameDeepOrderedMembers = function (set1, set2, msg) { new Assertion(set1, msg, assert.notSameDeepOrderedMembers, true) .to.not.have.same.deep.ordered.members(set2); @@ -2304,9 +2204,8 @@ assert.notSameDeepOrderedMembers = function (set1, set2, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.includeMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.includeMembers, true) .to.include.members(subset); @@ -2325,9 +2224,8 @@ assert.includeMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notIncludeMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.notIncludeMembers, true) .to.not.include.members(subset); @@ -2346,9 +2244,8 @@ assert.notIncludeMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.includeDeepMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.includeDeepMembers, true) .to.include.deep.members(subset); @@ -2367,9 +2264,8 @@ assert.includeDeepMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notIncludeDeepMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.notIncludeDeepMembers, true) .to.not.include.deep.members(subset); @@ -2389,9 +2285,8 @@ assert.notIncludeDeepMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.includeOrderedMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.includeOrderedMembers, true) .to.include.ordered.members(subset); @@ -2412,9 +2307,8 @@ assert.includeOrderedMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notIncludeOrderedMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.notIncludeOrderedMembers, true) .to.not.include.ordered.members(subset); @@ -2434,9 +2328,8 @@ assert.notIncludeOrderedMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.includeDeepOrderedMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.includeDeepOrderedMembers, true) .to.include.deep.ordered.members(subset); @@ -2458,9 +2351,8 @@ assert.includeDeepOrderedMembers = function (superset, subset, msg) { * @param {Array} subset * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) { new Assertion(superset, msg, assert.notIncludeDeepOrderedMembers, true) .to.not.include.deep.ordered.members(subset); @@ -2478,13 +2370,39 @@ assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) { * @param {Array<*>} list * @param {String} message * @namespace Assert - * @api public + * @public */ - assert.oneOf = function (inList, list, msg) { new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list); } +/** + * ### isIterable(obj, [message]) + * + * Asserts that the target is an iterable, which means that it has a iterator + * with the exception of `String.` + * + * assert.isIterable([1, 2]); + * + * @param {unknown} obj + * @param {string} [msg] + * @namespace Assert + * @api public + */ +assert.isIterable = function(obj, msg) { + if (obj == undefined || !obj[Symbol.iterator]) { + msg = msg ? + `${msg} expected ${inspect(obj)} to be an iterable` : + `expected ${inspect(obj)} to be an iterable`; + + throw new AssertionError( + msg, + undefined, + assert.isIterable + ); + } +} + /** * ### .changes(function, object, property, [message]) * @@ -2500,9 +2418,8 @@ assert.oneOf = function (inList, list, msg) { * @param {String} property name _optional_ * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.changes = function (fn, obj, prop, msg) { if (arguments.length === 3 && typeof obj === 'function') { msg = prop; @@ -2528,9 +2445,8 @@ assert.changes = function (fn, obj, prop, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.changesBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2560,9 +2476,8 @@ assert.changesBy = function (fn, obj, prop, delta, msg) { * @param {String} property name _optional_ * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.doesNotChange = function (fn, obj, prop, msg) { if (arguments.length === 3 && typeof obj === 'function') { msg = prop; @@ -2589,9 +2504,8 @@ assert.doesNotChange = function (fn, obj, prop, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.changesButNotBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2621,9 +2535,8 @@ assert.changesButNotBy = function (fn, obj, prop, delta, msg) { * @param {String} property name _optional_ * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.increases = function (fn, obj, prop, msg) { if (arguments.length === 3 && typeof obj === 'function') { msg = prop; @@ -2650,9 +2563,8 @@ assert.increases = function (fn, obj, prop, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.increasesBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2682,9 +2594,8 @@ assert.increasesBy = function (fn, obj, prop, delta, msg) { * @param {String} property name _optional_ * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.doesNotIncrease = function (fn, obj, prop, msg) { if (arguments.length === 3 && typeof obj === 'function') { msg = prop; @@ -2711,9 +2622,8 @@ assert.doesNotIncrease = function (fn, obj, prop, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.increasesButNotBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2743,9 +2653,8 @@ assert.increasesButNotBy = function (fn, obj, prop, delta, msg) { * @param {String} property name _optional_ * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.decreases = function (fn, obj, prop, msg) { if (arguments.length === 3 && typeof obj === 'function') { msg = prop; @@ -2772,9 +2681,8 @@ assert.decreases = function (fn, obj, prop, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.decreasesBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2804,9 +2712,8 @@ assert.decreasesBy = function (fn, obj, prop, delta, msg) { * @param {String} property name _optional_ * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.doesNotDecrease = function (fn, obj, prop, msg) { if (arguments.length === 3 && typeof obj === 'function') { msg = prop; @@ -2833,9 +2740,8 @@ assert.doesNotDecrease = function (fn, obj, prop, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2866,9 +2772,8 @@ assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) { * @param {Number} change amount (delta) * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { if (arguments.length === 4 && typeof obj === 'function') { var tmpMsg = delta; @@ -2883,7 +2788,7 @@ assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { .to.decrease(obj, prop).but.not.by(delta); } -/*! +/** * ### .ifError(object) * * Asserts if value is not a false value, and throws if it is a true value. @@ -2896,9 +2801,8 @@ assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) { * @name ifError * @param {Object} object * @namespace Assert - * @api public + * @public */ - assert.ifError = function (val) { if (val) { throw(val); @@ -2917,9 +2821,8 @@ assert.ifError = function (val) { * @param {Object} object * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isExtensible = function (obj, msg) { new Assertion(obj, msg, assert.isExtensible, true).to.be.extensible; }; @@ -2942,9 +2845,8 @@ assert.isExtensible = function (obj, msg) { * @param {Object} object * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isNotExtensible = function (obj, msg) { new Assertion(obj, msg, assert.isNotExtensible, true).to.not.be.extensible; }; @@ -2966,9 +2868,8 @@ assert.isNotExtensible = function (obj, msg) { * @param {Object} object * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isSealed = function (obj, msg) { new Assertion(obj, msg, assert.isSealed, true).to.be.sealed; }; @@ -2985,9 +2886,8 @@ assert.isSealed = function (obj, msg) { * @param {Object} object * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isNotSealed = function (obj, msg) { new Assertion(obj, msg, assert.isNotSealed, true).to.not.be.sealed; }; @@ -3006,9 +2906,8 @@ assert.isNotSealed = function (obj, msg) { * @param {Object} object * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isFrozen = function (obj, msg) { new Assertion(obj, msg, assert.isFrozen, true).to.be.frozen; }; @@ -3025,9 +2924,8 @@ assert.isFrozen = function (obj, msg) { * @param {Object} object * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isNotFrozen = function (obj, msg) { new Assertion(obj, msg, assert.isNotFrozen, true).to.not.be.frozen; }; @@ -3051,9 +2949,8 @@ assert.isNotFrozen = function (obj, msg) { * @param {Object|Array|String|Map|Set} target * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isEmpty = function(val, msg) { new Assertion(val, msg, assert.isEmpty, true).to.be.empty; }; @@ -3077,17 +2974,15 @@ assert.isEmpty = function(val, msg) { * @param {Object|Array|String|Map|Set} target * @param {String} message _optional_ * @namespace Assert - * @api public + * @public */ - assert.isNotEmpty = function(val, msg) { new Assertion(val, msg, assert.isNotEmpty, true).to.not.be.empty; }; -/*! +/** * Aliases. */ - (function alias(name, as){ assert[as] = assert[name]; return alias; diff --git a/lib/chai/interface/expect.js b/lib/chai/interface/expect.js index 70a9416c..286044a1 100644 --- a/lib/chai/interface/expect.js +++ b/lib/chai/interface/expect.js @@ -13,6 +13,7 @@ function expect(val, message) { } export {expect}; + /** * ### .fail([message]) * ### .fail(actual, expected, [message], [operator]) @@ -27,14 +28,13 @@ export {expect}; * expect.fail(1, 2, undefined, ">"); * * @name fail - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @param {String} operator - * @namespace BDD - * @api public + * @namespace expect + * @public */ - expect.fail = function (actual, expected, message, operator) { if (arguments.length < 2) { message = actual; diff --git a/lib/chai/interface/should.js b/lib/chai/interface/should.js index 8269a58b..3a2c235d 100644 --- a/lib/chai/interface/should.js +++ b/lib/chai/interface/should.js @@ -57,14 +57,13 @@ function loadShould () { * * * @name fail - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @param {String} operator * @namespace BDD - * @api public + * @public */ - should.fail = function (actual, expected, message, operator) { if (arguments.length < 2) { message = actual; @@ -87,13 +86,12 @@ function loadShould () { * should.equal(3, '3', '== coerces values to strings'); * * @name equal - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Should - * @api public + * @public */ - should.equal = function (val1, val2, msg) { new Assertion(val1, msg).to.equal(val2); }; @@ -119,9 +117,8 @@ function loadShould () { * @param {String} message * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types * @namespace Should - * @api public + * @public */ - should.Throw = function (fn, errt, errs, msg) { new Assertion(fn, msg).to.Throw(errt, errs); }; @@ -137,9 +134,8 @@ function loadShould () { * * @name exist * @namespace Should - * @api public + * @public */ - should.exist = function (val, msg) { new Assertion(val, msg).to.exist; } @@ -155,13 +151,12 @@ function loadShould () { * should.not.equal(3, 4, 'these numbers are not equal'); * * @name not.equal - * @param {Mixed} actual - * @param {Mixed} expected + * @param {unknown} actual + * @param {unknown} expected * @param {String} message * @namespace Should - * @api public + * @public */ - should.not.equal = function (val1, val2, msg) { new Assertion(val1, msg).to.not.equal(val2); }; @@ -183,9 +178,8 @@ function loadShould () { * @param {String} message * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types * @namespace Should - * @api public + * @public */ - should.not.Throw = function (fn, errt, errs, msg) { new Assertion(fn, msg).to.not.Throw(errt, errs); }; @@ -201,9 +195,8 @@ function loadShould () { * * @name not.exist * @namespace Should - * @api public + * @public */ - should.not.exist = function (val, msg) { new Assertion(val, msg).to.not.exist; } diff --git a/lib/chai/utils/addChainableMethod.js b/lib/chai/utils/addChainableMethod.js index aaf8baaa..2205b5ea 100644 --- a/lib/chai/utils/addChainableMethod.js +++ b/lib/chai/utils/addChainableMethod.js @@ -4,17 +4,13 @@ * MIT Licensed */ -/*! - * Module dependencies - */ - 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'; -/*! +/** * Module variables */ diff --git a/lib/chai/utils/compareByInspect.js b/lib/chai/utils/compareByInspect.js index ff9f9817..829de728 100644 --- a/lib/chai/utils/compareByInspect.js +++ b/lib/chai/utils/compareByInspect.js @@ -4,10 +4,6 @@ * MIT Licensed */ -/*! - * Module dependencies - */ - import {inspect} from './inspect.js'; /** diff --git a/lib/chai/utils/getMessage.js b/lib/chai/utils/getMessage.js index 97c4826e..83e59974 100644 --- a/lib/chai/utils/getMessage.js +++ b/lib/chai/utils/getMessage.js @@ -4,10 +4,6 @@ * MIT Licensed */ -/*! - * Module dependencies - */ - import {flag} from './flag.js'; import {getActual} from './getActual.js'; import {objDisplay} from './objDisplay.js'; diff --git a/lib/chai/utils/getOwnEnumerableProperties.js b/lib/chai/utils/getOwnEnumerableProperties.js index a54b1100..ac69b502 100644 --- a/lib/chai/utils/getOwnEnumerableProperties.js +++ b/lib/chai/utils/getOwnEnumerableProperties.js @@ -4,10 +4,6 @@ * MIT Licensed */ -/*! - * Module dependencies - */ - import {getOwnEnumerablePropertySymbols} from './getOwnEnumerablePropertySymbols.js'; /** diff --git a/lib/chai/utils/index.js b/lib/chai/utils/index.js index 4b9eba8b..5f52828c 100644 --- a/lib/chai/utils/index.js +++ b/lib/chai/utils/index.js @@ -4,171 +4,88 @@ * MIT Licensed */ -/*! - * Dependencies that are used for multiple exports are required here only once - */ - +// Dependencies that are used for multiple exports are required here only once import * as checkError from 'check-error'; -/*! - * test utility - */ - +// test utility export {test} from './test.js'; -/*! - * type utility - */ - +// type utility export {type} from './type-detect.js'; -/*! - * expectTypes utility - */ +// expectTypes utility export {expectTypes} from './expectTypes.js'; -/*! - * message utility - */ - +// message utility export {getMessage} from './getMessage.js'; -/*! - * actual utility - */ - +// actual utility export {getActual} from './getActual.js'; -/*! - * Inspect util - */ - +// Inspect util export {inspect} from './inspect.js'; -/*! - * Object Display util - */ - +// Object Display util export {objDisplay} from './objDisplay.js'; -/*! - * Flag utility - */ - +// Flag utility export {flag} from './flag.js'; -/*! - * Flag transferring utility - */ - +// Flag transferring utility export {transferFlags} from './transferFlags.js'; -/*! - * Deep equal utility - */ - +// Deep equal utility export {default as eql} from 'deep-eql'; -/*! - * Deep path info - */ - +// Deep path info export {getPathInfo, hasProperty} from 'pathval'; -/*! - * Function name - */ - +// Function name export function getName(fn) { return fn.name } -/*! - * add Property - */ - +// add Property export {addProperty} from './addProperty.js'; -/*! - * add Method - */ - +// add Method export {addMethod} from './addMethod.js'; -/*! - * overwrite Property - */ - +// overwrite Property export {overwriteProperty} from './overwriteProperty.js'; -/*! - * overwrite Method - */ - +// overwrite Method export {overwriteMethod} from './overwriteMethod.js'; -/*! - * Add a chainable method - */ - +// Add a chainable method export {addChainableMethod} from './addChainableMethod.js'; -/*! - * Overwrite chainable method - */ - +// Overwrite chainable method export {overwriteChainableMethod} from './overwriteChainableMethod.js'; -/*! - * Compare by inspect method - */ - +// Compare by inspect method export {compareByInspect} from './compareByInspect.js'; -/*! - * Get own enumerable property symbols method - */ - +// Get own enumerable property symbols method export {getOwnEnumerablePropertySymbols} from './getOwnEnumerablePropertySymbols.js'; -/*! - * Get own enumerable properties method - */ - +// Get own enumerable properties method export {getOwnEnumerableProperties} from './getOwnEnumerableProperties.js'; -/*! - * Checks error against a given set of criteria - */ - +// Checks error against a given set of criteria export {checkError}; -/*! - * Proxify util - */ - +// Proxify util export {proxify} from './proxify.js'; -/*! - * addLengthGuard util - */ - +// addLengthGuard util export {addLengthGuard} from './addLengthGuard.js'; -/*! - * isProxyEnabled helper - */ - +// isProxyEnabled helper export {isProxyEnabled} from './isProxyEnabled.js'; -/*! - * isNaN method - */ - +// isNaN method export {isNaN} from './isNaN.js'; -/*! - * getOperator method - */ - +// getOperator method export {getOperator} from './getOperator.js'; diff --git a/lib/chai/utils/objDisplay.js b/lib/chai/utils/objDisplay.js index 5a8383c0..c04f12df 100644 --- a/lib/chai/utils/objDisplay.js +++ b/lib/chai/utils/objDisplay.js @@ -4,10 +4,6 @@ * MIT Licensed */ -/*! - * Module dependencies - */ - import {inspect} from './inspect.js'; import {config} from '../config.js'; diff --git a/lib/chai/utils/test.js b/lib/chai/utils/test.js index 19a47dbe..5a400bdb 100644 --- a/lib/chai/utils/test.js +++ b/lib/chai/utils/test.js @@ -4,10 +4,6 @@ * MIT Licensed */ -/*! - * Module dependencies - */ - import {flag} from './flag.js'; /** diff --git a/test/assert.js b/test/assert.js index 22373a35..c469dda1 100644 --- a/test/assert.js +++ b/test/assert.js @@ -125,10 +125,8 @@ describe('assert', function () { var foo; assert.equal(foo, undefined); - if (typeof Symbol === 'function') { - var sym = Symbol(); - assert.equal(sym, sym); - } + var sym = Symbol(); + assert.equal(sym, sym); err(function () { assert.equal(1, 2, 'blah'); @@ -145,6 +143,7 @@ describe('assert', function () { assert.typeOf(async function() {}, 'asyncfunction'); assert.typeOf(function*() {}, 'generatorfunction'); assert.typeOf(async function*() {}, 'asyncgeneratorfunction'); + assert.typeOf(Symbol(), 'symbol'); err(function () { assert.typeOf(5, 'function', 'blah'); @@ -154,10 +153,6 @@ describe('assert', function () { assert.typeOf(function() {}, 'asyncfunction', 'blah'); }, "blah: expected [Function] to be an asyncfunction"); - if (typeof Symbol === 'function') { - assert.typeOf(Symbol(), 'symbol'); - } - err(function () { assert.typeOf(5, 'string', 'blah'); }, "blah: expected 5 to be a string"); @@ -227,21 +222,19 @@ describe('assert', function () { assert.instanceOf(t, Thing); }, 'The instanceof assertion needs a constructor but Function was given.', true); - if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') { - err(function(){ - assert.instanceOf(new Foo(), Symbol()); - }, "The instanceof assertion needs a constructor but Symbol was given."); - - err(function() { - var FakeConstructor = {}; - var fakeInstanceB = 4; - FakeConstructor[Symbol.hasInstance] = function (val) { - return val === 3; - }; - - assert.instanceOf(fakeInstanceB, FakeConstructor); - }, 'expected 4 to be an instance of an unnamed constructor') - } + err(function(){ + assert.instanceOf(new Foo(), Symbol()); + }, "The instanceof assertion needs a constructor but Symbol was given."); + + err(function() { + var FakeConstructor = {}; + var fakeInstanceB = 4; + FakeConstructor[Symbol.hasInstance] = function (val) { + return val === 3; + }; + + assert.instanceOf(fakeInstanceB, FakeConstructor); + }, 'expected 4 to be an instance of an unnamed constructor') err(function () { assert.instanceOf(5, Foo, 'blah'); @@ -282,21 +275,19 @@ describe('assert', function () { assert.notInstanceOf(new Foo(), undefined); }, "The instanceof assertion needs a constructor but undefined was given."); - if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') { - err(function(){ - assert.notInstanceOf(new Foo(), Symbol()); - }, "The instanceof assertion needs a constructor but Symbol was given."); - - err(function() { - var FakeConstructor = {}; - var fakeInstanceB = 4; - FakeConstructor[Symbol.hasInstance] = function (val) { - return val === 4; - }; - - assert.notInstanceOf(fakeInstanceB, FakeConstructor); - }, 'expected 4 to not be an instance of an unnamed constructor'); - } + err(function(){ + assert.notInstanceOf(new Foo(), Symbol()); + }, "The instanceof assertion needs a constructor but Symbol was given."); + + err(function() { + var FakeConstructor = {}; + var fakeInstanceB = 4; + FakeConstructor[Symbol.hasInstance] = function (val) { + return val === 4; + }; + + assert.notInstanceOf(fakeInstanceB, FakeConstructor); + }, 'expected 4 to not be an instance of an unnamed constructor'); err(function () { assert.notInstanceOf(new Foo(), Foo, 'blah'); @@ -333,11 +324,9 @@ describe('assert', function () { it('notEqual', function() { assert.notEqual(3, 4); - if (typeof Symbol === 'function') { - var sym1 = Symbol() - , sym2 = Symbol(); - assert.notEqual(sym1, sym2); - } + var sym1 = Symbol() + , sym2 = Symbol(); + assert.notEqual(sym1, sym2); err(function () { assert.notEqual(5, 5, 'blah'); @@ -347,10 +336,8 @@ describe('assert', function () { it('strictEqual', function() { assert.strictEqual('foo', 'foo'); - if (typeof Symbol === 'function') { - var sym = Symbol(); - assert.strictEqual(sym, sym); - } + var sym = Symbol(); + assert.strictEqual(sym, sym); err(function () { assert.strictEqual('5', 5, 'blah'); @@ -360,11 +347,9 @@ describe('assert', function () { it('notStrictEqual', function() { assert.notStrictEqual(5, '5'); - if (typeof Symbol === 'function') { - var sym1 = Symbol() - , sym2 = Symbol(); - assert.notStrictEqual(sym1, sym2); - } + var sym1 = Symbol() + , sym2 = Symbol(); + assert.notStrictEqual(sym1, sym2); err(function () { assert.notStrictEqual(5, 5, 'blah'); @@ -592,7 +577,7 @@ describe('assert', function () { it('isArray', function() { assert.isArray([]); - assert.isArray(new Array); + assert.isArray(new Array()); err(function () { assert.isArray({}, 'blah'); @@ -607,7 +592,7 @@ describe('assert', function () { }, "blah: expected [] not to be an array"); err(function () { - assert.isNotArray(new Array); + assert.isNotArray(new Array()); }, "expected [] not to be an array"); }); @@ -701,13 +686,10 @@ describe('assert', function () { // .include should work with Error objects and objects with a custom // `@@toStringTag`. assert.include(new Error('foo'), {message: 'foo'}); - if (typeof Symbol !== 'undefined' - && typeof Symbol.toStringTag !== 'undefined') { - var customObj = {a: 1}; - customObj[Symbol.toStringTag] = 'foo'; + var customObj = {a: 1}; + customObj[Symbol.toStringTag] = 'foo'; - assert.include(customObj, {a: 1}); - } + assert.include(customObj, {a: 1}); var obj1 = {a: 1} , obj2 = {b: 2}; @@ -715,51 +697,39 @@ describe('assert', function () { assert.include({foo: obj1, bar: obj2}, {foo: obj1}); assert.include({foo: obj1, bar: obj2}, {foo: obj1, bar: obj2}); - if (typeof Map === 'function') { - var map = new Map(); - var val = [{a: 1}]; - map.set('a', val); - map.set('b', 2); - map.set('c', -0); - map.set('d', NaN); - - assert.include(map, val); - assert.include(map, 2); - assert.include(map, 0); - assert.include(map, NaN); - } + var map = new Map(); + var val = [{a: 1}]; + map.set('a', val); + map.set('b', 2); + map.set('c', -0); + map.set('d', NaN); - if (typeof Set === 'function') { - var set = new Set(); - var val = [{a: 1}]; - set.add(val); - set.add(2); - set.add(-0); - set.add(NaN); - - assert.include(set, val); - assert.include(set, 2); - if (set.has(0)) { - // This test is skipped in IE11 because (contrary to spec) IE11 uses - // SameValue instead of SameValueZero equality for sets. - assert.include(set, 0); - } - assert.include(set, NaN); - } + assert.include(map, val); + assert.include(map, 2); + assert.include(map, 0); + assert.include(map, NaN); - if (typeof WeakSet === 'function') { - var ws = new WeakSet(); - var val = [{a: 1}]; - ws.add(val); + var val = [{a: 1}]; + var set = new Set(); + set.add(val); + set.add(2); + set.add(-0); + set.add(NaN); - assert.include(ws, val); - } + assert.include(set, val); + assert.include(set, 2); + assert.include(set, 0); + assert.include(set, NaN); - if (typeof Symbol === 'function') { - var sym1 = Symbol() - , sym2 = Symbol(); - assert.include([sym1, sym2], sym1); - } + var ws = new WeakSet(); + var val = [{a: 1}]; + ws.add(val); + + assert.include(ws, val); + + var sym1 = Symbol() + , sym2 = Symbol(); + assert.include([sym1, sym2], sym1); err(function () { assert.include('foobar', 'baz', 'blah'); @@ -812,44 +782,36 @@ describe('assert', function () { assert.notInclude({foo: obj1, bar: obj2}, {foo: {a: 1}}); assert.notInclude({foo: obj1, bar: obj2}, {foo: obj1, bar: {b: 2}}); - if (typeof Map === 'function') { - var map = new Map(); - var val = [{a: 1}]; - map.set('a', val); - map.set('b', 2); + var map = new Map(); + var val = [{a: 1}]; + map.set('a', val); + map.set('b', 2); - assert.notInclude(map, [{a: 1}]); - assert.notInclude(map, 3); - } + assert.notInclude(map, [{a: 1}]); + assert.notInclude(map, 3); - if (typeof Set === 'function') { - var set = new Set(); - var val = [{a: 1}]; - set.add(val); - set.add(2); + var set = new Set(); + var val = [{a: 1}]; + set.add(val); + set.add(2); - assert.include(set, val); - assert.include(set, 2); + assert.include(set, val); + assert.include(set, 2); - assert.notInclude(set, [{a: 1}]); - assert.notInclude(set, 3); - } + assert.notInclude(set, [{a: 1}]); + assert.notInclude(set, 3); - if (typeof WeakSet === 'function') { - var ws = new WeakSet(); - var val = [{a: 1}]; - ws.add(val); + var ws = new WeakSet(); + var val = [{a: 1}]; + ws.add(val); - assert.notInclude(ws, [{a: 1}]); - assert.notInclude(ws, {}); - } + assert.notInclude(ws, [{a: 1}]); + assert.notInclude(ws, {}); - if (typeof Symbol === 'function') { - var sym1 = Symbol() - , sym2 = Symbol() - , sym3 = Symbol(); - assert.notInclude([sym1, sym2], sym3); - } + var sym1 = Symbol() + , sym2 = Symbol() + , sym3 = Symbol(); + assert.notInclude([sym1, sym2], sym3); err(function () { var obj1 = {a: 1} @@ -909,25 +871,19 @@ describe('assert', function () { assert.notDeepInclude({foo: obj1, bar: obj2}, {baz: {a: 1}}); assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 9}}); - if (typeof Map === 'function') { - var map = new Map(); - map.set(1, [{a: 1}]); + var map = new Map(); + map.set(1, [{a: 1}]); - assert.deepInclude(map, [{a: 1}]); - } + assert.deepInclude(map, [{a: 1}]); - if (typeof Set === 'function') { - var set = new Set(); - set.add([{a: 1}]); + var set = new Set(); + set.add([{a: 1}]); - assert.deepInclude(set, [{a: 1}]); - } + assert.deepInclude(set, [{a: 1}]); - if (typeof WeakSet === 'function') { - err(function() { - assert.deepInclude(new WeakSet(), {}, 'foo'); - }, 'foo: unable to use .deep.include with WeakSet'); - } + err(function() { + assert.deepInclude(new WeakSet(), {}, 'foo'); + }, 'foo: unable to use .deep.include with WeakSet'); err(function () { assert.deepInclude([obj1, obj2], {a: 9}, 'blah'); @@ -1099,264 +1055,252 @@ describe('assert', function () { assert.hasAllKeys(obj, [enumProp1, enumProp2]); assert.doesNotHaveAllKeys(obj, [enumProp1, enumProp2, nonEnumProp]); - if (typeof Symbol === 'function') { - var sym1 = Symbol('sym1') - , sym2 = Symbol('sym2') - , sym3 = Symbol('sym3') - , str = 'str' - , obj = {}; + var sym1 = Symbol('sym1') + , sym2 = Symbol('sym2') + , sym3 = Symbol('sym3') + , str = 'str' + , obj = {}; - obj[sym1] = 'sym1'; - obj[sym2] = 'sym2'; - obj[str] = 'str'; + obj[sym1] = 'sym1'; + obj[sym2] = 'sym2'; + obj[str] = 'str'; - Object.defineProperty(obj, sym3, { - enumerable: false, - value: 'sym3' - }); + Object.defineProperty(obj, sym3, { + enumerable: false, + value: 'sym3' + }); - assert.hasAllKeys(obj, [sym1, sym2, str]); - assert.doesNotHaveAllKeys(obj, [sym1, sym2, sym3, str]); - } + assert.hasAllKeys(obj, [sym1, sym2, str]); + assert.doesNotHaveAllKeys(obj, [sym1, sym2, sym3, str]); - if (typeof Map !== 'undefined') { - // Not using Map constructor args because not supported in IE 11. - var aKey = {thisIs: 'anExampleObject'} - , anotherKey = {doingThisBecauseOf: 'referential equality'} - , testMap = new Map(); + var aKey = {thisIs: 'anExampleObject'} + , anotherKey = {doingThisBecauseOf: 'referential equality'} + , testMap = new Map(); - testMap.set(aKey, 'aValue'); - testMap.set(anotherKey, 'anotherValue'); + testMap.set(aKey, 'aValue'); + testMap.set(anotherKey, 'anotherValue'); - assert.hasAnyKeys(testMap, [ aKey ]); - assert.hasAnyKeys(testMap, [ 'thisDoesNotExist', 'thisToo', aKey ]); - assert.hasAllKeys(testMap, [ aKey, anotherKey ]); + assert.hasAnyKeys(testMap, [ aKey ]); + assert.hasAnyKeys(testMap, [ 'thisDoesNotExist', 'thisToo', aKey ]); + assert.hasAllKeys(testMap, [ aKey, anotherKey ]); - assert.containsAllKeys(testMap, [ aKey ]); - assert.doesNotHaveAllKeys(testMap, [ aKey, {iDoNot: 'exist'} ]); + assert.containsAllKeys(testMap, [ aKey ]); + assert.doesNotHaveAllKeys(testMap, [ aKey, {iDoNot: 'exist'} ]); - assert.doesNotHaveAnyKeys(testMap, [ {iDoNot: 'exist'} ]); - assert.doesNotHaveAnyKeys(testMap, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); - assert.doesNotHaveAllKeys(testMap, [ 'thisDoesNotExist', 'thisToo', anotherKey ]); + assert.doesNotHaveAnyKeys(testMap, [ {iDoNot: 'exist'} ]); + assert.doesNotHaveAnyKeys(testMap, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); + assert.doesNotHaveAllKeys(testMap, [ 'thisDoesNotExist', 'thisToo', anotherKey ]); - assert.doesNotHaveAnyKeys(testMap, [ {iDoNot: 'exist'}, 'thisDoesNotExist' ]); - assert.doesNotHaveAnyKeys(testMap, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); - assert.doesNotHaveAllKeys(testMap, [ aKey, {iDoNot: 'exist'} ]); + assert.doesNotHaveAnyKeys(testMap, [ {iDoNot: 'exist'}, 'thisDoesNotExist' ]); + assert.doesNotHaveAnyKeys(testMap, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); + assert.doesNotHaveAllKeys(testMap, [ aKey, {iDoNot: 'exist'} ]); - // Ensure the assertions above use strict equality - assert.doesNotHaveAnyKeys(testMap, {thisIs: 'anExampleObject'}); - assert.doesNotHaveAllKeys(testMap, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); + // Ensure the assertions above use strict equality + assert.doesNotHaveAnyKeys(testMap, {thisIs: 'anExampleObject'}); + assert.doesNotHaveAllKeys(testMap, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); - err(function(){ - assert.hasAnyKeys(testMap, [ {thisIs: 'anExampleObject'} ]); - }); + err(function(){ + assert.hasAnyKeys(testMap, [ {thisIs: 'anExampleObject'} ]); + }); - err(function(){ - assert.hasAllKeys(testMap, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); - }); + err(function(){ + assert.hasAllKeys(testMap, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); + }); - err(function(){ - assert.containsAllKeys(testMap, [ {thisIs: 'anExampleObject'} ]); - }); + err(function(){ + assert.containsAllKeys(testMap, [ {thisIs: 'anExampleObject'} ]); + }); - // Tests for the deep variations of the keys assertion - assert.hasAnyDeepKeys(testMap, {thisIs: 'anExampleObject'}); - assert.hasAnyDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {three: 'three'}]); - assert.hasAnyDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + // Tests for the deep variations of the keys assertion + assert.hasAnyDeepKeys(testMap, {thisIs: 'anExampleObject'}); + assert.hasAnyDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {three: 'three'}]); + assert.hasAnyDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - assert.hasAllDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + assert.hasAllDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - assert.containsAllDeepKeys(testMap, {thisIs: 'anExampleObject'}); - assert.containsAllDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + assert.containsAllDeepKeys(testMap, {thisIs: 'anExampleObject'}); + assert.containsAllDeepKeys(testMap, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - assert.doesNotHaveAnyDeepKeys(testMap, {thisDoesNot: 'exist'}); - assert.doesNotHaveAnyDeepKeys(testMap, [{twenty: 'twenty'}, {fifty: 'fifty'}]); + assert.doesNotHaveAnyDeepKeys(testMap, {thisDoesNot: 'exist'}); + assert.doesNotHaveAnyDeepKeys(testMap, [{twenty: 'twenty'}, {fifty: 'fifty'}]); - assert.doesNotHaveAllDeepKeys(testMap, {thisDoesNot: 'exist'}); - assert.doesNotHaveAllDeepKeys(testMap, [{twenty: 'twenty'}, {thisIs: 'anExampleObject'}]); + assert.doesNotHaveAllDeepKeys(testMap, {thisDoesNot: 'exist'}); + assert.doesNotHaveAllDeepKeys(testMap, [{twenty: 'twenty'}, {thisIs: 'anExampleObject'}]); - var weirdMapKey1 = Object.create(null) - , weirdMapKey2 = {toString: NaN} - , weirdMapKey3 = [] - , weirdMap = new Map(); + var weirdMapKey1 = Object.create(null) + , weirdMapKey2 = {toString: NaN} + , weirdMapKey3 = [] + , weirdMap = new Map(); - weirdMap.set(weirdMapKey1, 'val1'); - weirdMap.set(weirdMapKey2, 'val2'); + weirdMap.set(weirdMapKey1, 'val1'); + weirdMap.set(weirdMapKey2, 'val2'); - assert.hasAllKeys(weirdMap, [weirdMapKey1, weirdMapKey2]); - assert.doesNotHaveAllKeys(weirdMap, [weirdMapKey1, weirdMapKey3]); + assert.hasAllKeys(weirdMap, [weirdMapKey1, weirdMapKey2]); + assert.doesNotHaveAllKeys(weirdMap, [weirdMapKey1, weirdMapKey3]); - if (typeof Symbol === 'function') { - var symMapKey1 = Symbol() - , symMapKey2 = Symbol() - , symMapKey3 = Symbol() - , symMap = new Map(); + var symMapKey1 = Symbol() + , symMapKey2 = Symbol() + , symMapKey3 = Symbol() + , symMap = new Map(); - symMap.set(symMapKey1, 'val1'); - symMap.set(symMapKey2, 'val2'); + symMap.set(symMapKey1, 'val1'); + symMap.set(symMapKey2, 'val2'); - assert.hasAllKeys(symMap, [symMapKey1, symMapKey2]); - assert.hasAnyKeys(symMap, [symMapKey1, symMapKey3]); - assert.containsAllKeys(symMap, [symMapKey2, symMapKey1]); + assert.hasAllKeys(symMap, [symMapKey1, symMapKey2]); + assert.hasAnyKeys(symMap, [symMapKey1, symMapKey3]); + assert.containsAllKeys(symMap, [symMapKey2, symMapKey1]); - assert.doesNotHaveAllKeys(symMap, [symMapKey1, symMapKey3]); - assert.doesNotHaveAnyKeys(symMap, [symMapKey3]); - } + assert.doesNotHaveAllKeys(symMap, [symMapKey1, symMapKey3]); + assert.doesNotHaveAnyKeys(symMap, [symMapKey3]); - var errMap = new Map(); + var errMap = new Map(); - errMap.set({1: 20}, 'number'); + errMap.set({1: 20}, 'number'); - err(function(){ - assert.hasAllKeys(errMap, [], 'blah'); - }, "blah: keys required"); + err(function(){ + assert.hasAllKeys(errMap, [], 'blah'); + }, "blah: keys required"); - err(function(){ - assert.containsAllKeys(errMap, [], 'blah'); - }, "blah: keys required"); + err(function(){ + assert.containsAllKeys(errMap, [], 'blah'); + }, "blah: keys required"); - err(function(){ - assert.doesNotHaveAllKeys(errMap, [], 'blah'); - }, "blah: keys required"); + err(function(){ + assert.doesNotHaveAllKeys(errMap, [], 'blah'); + }, "blah: keys required"); - err(function(){ - assert.hasAnyKeys(errMap, [], 'blah'); - }, "blah: keys required"); + err(function(){ + assert.hasAnyKeys(errMap, [], 'blah'); + }, "blah: keys required"); - err(function(){ - assert.doesNotHaveAnyKeys(errMap, [], 'blah'); - }, "blah: keys required"); - - // Uncomment this after solving https://github.com/chaijs/chai/issues/662 - // This should fail because of referential equality (this is a strict comparison) - // err(function(){ - // assert.containsAllKeys(new Map([[{foo: 1}, 'bar']]), { foo: 1 }); - // }, 'expected [ [ { foo: 1 }, 'bar' ] ] to contain key { foo: 1 }'); - - // err(function(){ - // assert.containsAllDeepKeys(new Map([[{foo: 1}, 'bar']]), { iDoNotExist: 0 }) - // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); - } + err(function(){ + assert.doesNotHaveAnyKeys(errMap, [], 'blah'); + }, "blah: keys required"); - if (typeof Set !== 'undefined') { - // Not using Set constructor args because not supported in IE 11. - var aKey = {thisIs: 'anExampleObject'} - , anotherKey = {doingThisBecauseOf: 'referential equality'} - , testSet = new Set(); + // Uncomment this after solving https://github.com/chaijs/chai/issues/662 + // This should fail because of referential equality (this is a strict comparison) + // err(function(){ + // assert.containsAllKeys(new Map([[{foo: 1}, 'bar']]), { foo: 1 }); + // }, 'expected [ [ { foo: 1 }, 'bar' ] ] to contain key { foo: 1 }'); - testSet.add(aKey); - testSet.add(anotherKey); + // err(function(){ + // assert.containsAllDeepKeys(new Map([[{foo: 1}, 'bar']]), { iDoNotExist: 0 }) + // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); - assert.hasAnyKeys(testSet, [ aKey ]); - assert.hasAnyKeys(testSet, [ 20, 1, aKey ]); - assert.hasAllKeys(testSet, [ aKey, anotherKey ]); + var aKey = {thisIs: 'anExampleObject'} + , anotherKey = {doingThisBecauseOf: 'referential equality'} + , testSet = new Set(); - assert.containsAllKeys(testSet, [ aKey ]); - assert.doesNotHaveAllKeys(testSet, [ aKey, {iDoNot: 'exist'} ]); + testSet.add(aKey); + testSet.add(anotherKey); - assert.doesNotHaveAnyKeys(testSet, [ {iDoNot: 'exist'} ]); - assert.doesNotHaveAnyKeys(testSet, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); - assert.doesNotHaveAllKeys(testSet, [ 'thisDoesNotExist', 'thisToo', anotherKey ]); + assert.hasAnyKeys(testSet, [ aKey ]); + assert.hasAnyKeys(testSet, [ 20, 1, aKey ]); + assert.hasAllKeys(testSet, [ aKey, anotherKey ]); - assert.doesNotHaveAnyKeys(testSet, [ {iDoNot: 'exist'}, 'thisDoesNotExist' ]); - assert.doesNotHaveAnyKeys(testSet, [ 20, 1, {iDoNot: 'exist'} ]); - assert.doesNotHaveAllKeys(testSet, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); + assert.containsAllKeys(testSet, [ aKey ]); + assert.doesNotHaveAllKeys(testSet, [ aKey, {iDoNot: 'exist'} ]); - // Ensure the assertions above use strict equality - assert.doesNotHaveAnyKeys(testSet, {thisIs: 'anExampleObject'}); - assert.doesNotHaveAllKeys(testSet, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); + assert.doesNotHaveAnyKeys(testSet, [ {iDoNot: 'exist'} ]); + assert.doesNotHaveAnyKeys(testSet, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); + assert.doesNotHaveAllKeys(testSet, [ 'thisDoesNotExist', 'thisToo', anotherKey ]); - err(function(){ - assert.hasAnyKeys(testSet, [ {thisIs: 'anExampleObject'} ]); - }); + assert.doesNotHaveAnyKeys(testSet, [ {iDoNot: 'exist'}, 'thisDoesNotExist' ]); + assert.doesNotHaveAnyKeys(testSet, [ 20, 1, {iDoNot: 'exist'} ]); + assert.doesNotHaveAllKeys(testSet, [ 'thisDoesNotExist', 'thisToo', {iDoNot: 'exist'} ]); - err(function(){ - assert.hasAllKeys(testSet, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); - }); + // Ensure the assertions above use strict equality + assert.doesNotHaveAnyKeys(testSet, {thisIs: 'anExampleObject'}); + assert.doesNotHaveAllKeys(testSet, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); - err(function(){ - assert.containsAllKeys(testSet, [ {thisIs: 'anExampleObject'} ]); - }); + err(function(){ + assert.hasAnyKeys(testSet, [ {thisIs: 'anExampleObject'} ]); + }); - // Tests for the deep variations of the keys assertion - assert.hasAnyDeepKeys(testSet, {thisIs: 'anExampleObject'}); - assert.hasAnyDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {three: 'three'}]); - assert.hasAnyDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + err(function(){ + assert.hasAllKeys(testSet, [ {thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'} ]); + }); - assert.hasAllDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + err(function(){ + assert.containsAllKeys(testSet, [ {thisIs: 'anExampleObject'} ]); + }); - assert.containsAllDeepKeys(testSet, {thisIs: 'anExampleObject'}); - assert.containsAllDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + // Tests for the deep variations of the keys assertion + assert.hasAnyDeepKeys(testSet, {thisIs: 'anExampleObject'}); + assert.hasAnyDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {three: 'three'}]); + assert.hasAnyDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - assert.doesNotHaveAnyDeepKeys(testSet, {twenty: 'twenty'}); - assert.doesNotHaveAnyDeepKeys(testSet, [{twenty: 'twenty'}, {fifty: 'fifty'}]); + assert.hasAllDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - assert.doesNotHaveAllDeepKeys(testSet, {twenty: 'twenty'}); - assert.doesNotHaveAllDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {fifty: 'fifty'}]); + assert.containsAllDeepKeys(testSet, {thisIs: 'anExampleObject'}); + assert.containsAllDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - var weirdSetKey1 = Object.create(null) - , weirdSetKey2 = {toString: NaN} - , weirdSetKey3 = [] - , weirdSet = new Set(); + assert.doesNotHaveAnyDeepKeys(testSet, {twenty: 'twenty'}); + assert.doesNotHaveAnyDeepKeys(testSet, [{twenty: 'twenty'}, {fifty: 'fifty'}]); - weirdSet.add(weirdSetKey1); - weirdSet.add(weirdSetKey2); + assert.doesNotHaveAllDeepKeys(testSet, {twenty: 'twenty'}); + assert.doesNotHaveAllDeepKeys(testSet, [{thisIs: 'anExampleObject'}, {fifty: 'fifty'}]); - assert.hasAllKeys(weirdSet, [weirdSetKey1, weirdSetKey2]); - assert.doesNotHaveAllKeys(weirdSet, [weirdSetKey1, weirdSetKey3]); + var weirdSetKey1 = Object.create(null) + , weirdSetKey2 = {toString: NaN} + , weirdSetKey3 = [] + , weirdSet = new Set(); - if (typeof Symbol === 'function') { - var symSetKey1 = Symbol() - , symSetKey2 = Symbol() - , symSetKey3 = Symbol() - , symSet = new Set(); + weirdSet.add(weirdSetKey1); + weirdSet.add(weirdSetKey2); - symSet.add(symSetKey1); - symSet.add(symSetKey2); + assert.hasAllKeys(weirdSet, [weirdSetKey1, weirdSetKey2]); + assert.doesNotHaveAllKeys(weirdSet, [weirdSetKey1, weirdSetKey3]); - assert.hasAllKeys(symSet, [symSetKey1, symSetKey2]); - assert.hasAnyKeys(symSet, [symSetKey1, symSetKey3]); - assert.containsAllKeys(symSet, [symSetKey2, symSetKey1]); + var symSetKey1 = Symbol() + , symSetKey2 = Symbol() + , symSetKey3 = Symbol() + , symSet = new Set(); - assert.doesNotHaveAllKeys(symSet, [symSetKey1, symSetKey3]); - assert.doesNotHaveAnyKeys(symSet, [symSetKey3]); - } + symSet.add(symSetKey1); + symSet.add(symSetKey2); - var errSet = new Set(); + assert.hasAllKeys(symSet, [symSetKey1, symSetKey2]); + assert.hasAnyKeys(symSet, [symSetKey1, symSetKey3]); + assert.containsAllKeys(symSet, [symSetKey2, symSetKey1]); - errSet.add({1: 20}); - errSet.add('number'); + assert.doesNotHaveAllKeys(symSet, [symSetKey1, symSetKey3]); + assert.doesNotHaveAnyKeys(symSet, [symSetKey3]); - err(function(){ - assert.hasAllKeys(errSet, [], 'blah'); - }, "blah: keys required"); + var errSet = new Set(); - err(function(){ - assert.containsAllKeys(errSet, [], 'blah'); - }, "blah: keys required"); + errSet.add({1: 20}); + errSet.add('number'); - err(function(){ - assert.doesNotHaveAllKeys(errSet, [], 'blah'); - }, "blah: keys required"); + err(function(){ + assert.hasAllKeys(errSet, [], 'blah'); + }, "blah: keys required"); - err(function(){ - assert.hasAnyKeys(errSet, [], 'blah'); - }, "blah: keys required"); + err(function(){ + assert.containsAllKeys(errSet, [], 'blah'); + }, "blah: keys required"); - err(function(){ - assert.doesNotHaveAnyKeys(errSet, [], 'blah'); - }, "blah: keys required"); - - // Uncomment this after solving https://github.com/chaijs/chai/issues/662 - // This should fail because of referential equality (this is a strict comparison) - // err(function(){ - // assert.containsAllKeys(new Set([{foo: 1}]), { foo: 1 }); - // }, 'expected [ [ { foo: 1 }, 'bar' ] ] to contain key { foo: 1 }'); - - // err(function(){ - // assert.containsAllDeepKeys(new Set([{foo: 1}]), { iDoNotExist: 0 }) - // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); - } + err(function(){ + assert.doesNotHaveAllKeys(errSet, [], 'blah'); + }, "blah: keys required"); + + err(function(){ + assert.hasAnyKeys(errSet, [], 'blah'); + }, "blah: keys required"); + + err(function(){ + assert.doesNotHaveAnyKeys(errSet, [], 'blah'); + }, "blah: keys required"); + + // Uncomment this after solving https://github.com/chaijs/chai/issues/662 + // This should fail because of referential equality (this is a strict comparison) + // err(function(){ + // assert.containsAllKeys(new Set([{foo: 1}]), { foo: 1 }); + // }, 'expected [ [ { foo: 1 }, 'bar' ] ] to contain key { foo: 1 }'); + + // err(function(){ + // assert.containsAllDeepKeys(new Set([{foo: 1}]), { iDoNotExist: 0 }) + // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); err(function(){ assert.hasAllKeys({ foo: 1 }, [], 'blah'); @@ -1468,33 +1412,29 @@ describe('assert', function () { assert.lengthOf(1, 5); }, "expected 1 to have property \'length\'"); - if (typeof Map === 'function') { - assert.lengthOf(new Map, 0); + assert.lengthOf(new Map(), 0); - var map = new Map; - map.set('a', 1); - map.set('b', 2); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); - assert.lengthOf(map, 2); + assert.lengthOf(map, 2); - err(function(){ - assert.lengthOf(map, 3, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2 } to have a size of 3 but got 2"); - } + err(function(){ + assert.lengthOf(map, 3, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2 } to have a size of 3 but got 2"); - if (typeof Set === 'function') { - assert.lengthOf(new Set, 0); + assert.lengthOf(new Set(), 0); - var set = new Set; - set.add(1); - set.add(2); + var set = new Set(); + set.add(1); + set.add(2); - assert.lengthOf(set, 2); + assert.lengthOf(set, 2); - err(function(){ - assert.lengthOf(set, 3, 'blah'); - }, "blah: expected Set{ 1, 2 } to have a size of 3 but got 2"); - } + err(function(){ + assert.lengthOf(set, 3, 'blah'); + }, "blah: expected Set{ 1, 2 } to have a size of 3 but got 2"); }); it('match', function () { @@ -1969,6 +1909,8 @@ describe('assert', function () { assert.sameMembers([4, 2], [4, 2]); assert.sameMembers([4, 2, 2], [4, 2, 2]); + assert.sameMembers(new Set([1,2,3]), new Set([3,2,1])); + err(function() { assert.sameMembers([], [1, 2], 'blah'); }, 'blah: expected [] to have the same members as [ 1, 2 ]'); @@ -1979,11 +1921,11 @@ describe('assert', function () { err(function () { assert.sameMembers({}, [], 'blah'); - }, 'blah: expected {} to be an array'); + }, 'blah: expected {} to be an iterable'); err(function () { assert.sameMembers([], {}, 'blah'); - }, 'blah: expected {} to be an array'); + }, 'blah: expected {} to be an iterable'); }); it('notSameMembers', function() { @@ -2375,6 +2317,33 @@ describe('assert', function () { }, 'blah: the argument to most must be a number'); }); + it('iterable', function() { + assert.isIterable([1, 2, 3]); + assert.isIterable(new Map([[1, 'one'], [2, 'two'], [3, 'three']])); + assert.isIterable(new Set([1, 2, 3])); + assert.isIterable('hello'); + + err(function() { + assert.isIterable(42); + }, 'expected 42 to be an iterable'); + + err(function() { + assert.isIterable(undefined); + }, 'expected undefined to be an iterable'); + + err(function() { + assert.isIterable(null); + }, 'expected null to be an iterable'); + + err(function() { + assert.isIterable(true); + }, 'expected true to be an iterable'); + + err(function() { + assert.isIterable({ key: 'value' }); + }, 'expected { key: \'value\' } to be an iterable'); + }); + it('change', function() { var obj = { value: 10, str: 'foo' }, heroes = ['spiderman', 'superman'], @@ -2556,18 +2525,16 @@ describe('assert', function () { assert[isExtensible](undefined); }, 'expected undefined to be extensible'); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - isExtensible: function() { - throw new TypeError(); - } - }); - - err(function() { - // isExtensible should not suppress errors, thrown in proxy traps - assert[isExtensible](proxy); - }, { name: 'TypeError' }, true); - } + var proxy = new Proxy({}, { + isExtensible: function() { + throw new TypeError(); + } + }); + + err(function() { + // isExtensible should not suppress errors, thrown in proxy traps + assert[isExtensible](proxy); + }, { name: 'TypeError' }, true); }); }); @@ -2588,23 +2555,18 @@ describe('assert', function () { assert[isNotExtensible]('foo'); assert[isNotExtensible](false); assert[isNotExtensible](undefined); + assert[isNotExtensible](Symbol()); - if (typeof Symbol === 'function') { - assert[isNotExtensible](Symbol()); - } + var proxy = new Proxy({}, { + isExtensible: function() { + throw new TypeError(); + } + }); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - isExtensible: function() { - throw new TypeError(); - } - }); - - err(function() { - // isNotExtensible should not suppress errors, thrown in proxy traps - assert[isNotExtensible](proxy); - }, { name: 'TypeError' }, true); - } + err(function() { + // isNotExtensible should not suppress errors, thrown in proxy traps + assert[isNotExtensible](proxy); + }, { name: 'TypeError' }, true); }); }); @@ -2625,26 +2587,21 @@ describe('assert', function () { assert[isSealed]('foo'); assert[isSealed](false); assert[isSealed](undefined); + assert[isSealed](Symbol()); - if (typeof Symbol === 'function') { - assert[isSealed](Symbol()); - } - - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - ownKeys: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + ownKeys: function() { + throw new TypeError(); + } + }); - // Object.isSealed will call ownKeys trap only if object is not extensible - Object.preventExtensions(proxy); + // Object.isSealed will call ownKeys trap only if object is not extensible + Object.preventExtensions(proxy); - err(function() { - // isSealed should not suppress errors, thrown in proxy traps - assert[isSealed](proxy); - }, { name: 'TypeError' }, true); - } + err(function() { + // isSealed should not suppress errors, thrown in proxy traps + assert[isSealed](proxy); + }, { name: 'TypeError' }, true); }); }); @@ -2680,21 +2637,19 @@ describe('assert', function () { assert[isNotSealed](undefined); }, 'expected undefined to not be sealed'); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - ownKeys: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + ownKeys: function() { + throw new TypeError(); + } + }); - // Object.isSealed will call ownKeys trap only if object is not extensible - Object.preventExtensions(proxy); + // Object.isSealed will call ownKeys trap only if object is not extensible + Object.preventExtensions(proxy); - err(function() { - // isNotSealed should not suppress errors, thrown in proxy traps - assert[isNotSealed](proxy); - }, { name: 'TypeError' }, true); - } + err(function() { + // isNotSealed should not suppress errors, thrown in proxy traps + assert[isNotSealed](proxy); + }, { name: 'TypeError' }, true); }); }); @@ -2715,26 +2670,21 @@ describe('assert', function () { assert[isFrozen]('foo'); assert[isFrozen](false); assert[isFrozen](undefined); + assert[isFrozen](Symbol()); - if (typeof Symbol === 'function') { - assert[isFrozen](Symbol()); - } - - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - ownKeys: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + ownKeys: function() { + throw new TypeError(); + } + }); - // Object.isFrozen will call ownKeys trap only if object is not extensible - Object.preventExtensions(proxy); + // Object.isFrozen will call ownKeys trap only if object is not extensible + Object.preventExtensions(proxy); - err(function() { - // isFrozen should not suppress errors, thrown in proxy traps - assert[isFrozen](proxy); - }, { name: 'TypeError' }, true); - } + err(function() { + // isFrozen should not suppress errors, thrown in proxy traps + assert[isFrozen](proxy); + }, { name: 'TypeError' }, true); }); }); @@ -2770,21 +2720,19 @@ describe('assert', function () { assert[isNotFrozen](undefined); }, 'expected undefined to not be frozen'); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - ownKeys: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + ownKeys: function() { + throw new TypeError(); + } + }); - // Object.isFrozen will call ownKeys trap only if object is not extensible - Object.preventExtensions(proxy); + // Object.isFrozen will call ownKeys trap only if object is not extensible + Object.preventExtensions(proxy); - err(function() { - // isNotFrozen should not suppress errors, thrown in proxy traps - assert[isNotFrozen](proxy); - }, { name: 'TypeError' }, true); - } + err(function() { + // isNotFrozen should not suppress errors, thrown in proxy traps + assert[isNotFrozen](proxy); + }, { name: 'TypeError' }, true); }); }); @@ -2795,36 +2743,27 @@ describe('assert', function () { assert[isEmpty](''); assert[isEmpty]([]); - assert[isEmpty](new FakeArgs); + assert[isEmpty](new FakeArgs()); assert[isEmpty]({}); - if (typeof WeakMap === 'function') { - err(function(){ - assert[isEmpty](new WeakMap, 'blah'); - }, "blah: .empty was passed a weak collection"); - } - - if (typeof WeakSet === 'function') { - err(function(){ - assert[isEmpty](new WeakSet, 'blah'); - }, "blah: .empty was passed a weak collection"); - } + err(function(){ + assert[isEmpty](new WeakMap(), 'blah'); + }, "blah: .empty was passed a weak collection"); - if (typeof Map === 'function') { - assert[isEmpty](new Map); + err(function(){ + assert[isEmpty](new WeakSet(), 'blah'); + }, "blah: .empty was passed a weak collection"); - var map = new Map; - map.key = 'val'; - assert[isEmpty](map); - } + assert[isEmpty](new Map()); - if (typeof Set === 'function') { - assert[isEmpty](new Set); + var map = new Map(); + map.key = 'val'; + assert[isEmpty](map); + assert[isEmpty](new Set()); - var set = new Set; - set.key = 'val'; - assert[isEmpty](set); - } + var set = new Set(); + set.key = 'val'; + assert[isEmpty](set); err(function(){ assert[isEmpty]('foo', 'blah'); @@ -2870,15 +2809,13 @@ describe('assert', function () { assert[isEmpty](false); }, ".empty was passed non-string primitive false"); - if (typeof Symbol !== 'undefined') { - err(function(){ - assert[isEmpty](Symbol()); - }, ".empty was passed non-string primitive Symbol()"); + err(function(){ + assert[isEmpty](Symbol()); + }, ".empty was passed non-string primitive Symbol()"); - err(function(){ - assert[isEmpty](Symbol.iterator); - }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); - } + err(function(){ + assert[isEmpty](Symbol.iterator); + }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); err(function(){ assert[isEmpty](function() {}, 'blah'); @@ -2902,39 +2839,29 @@ describe('assert', function () { assert[isNotEmpty]({arguments: 0}); assert[isNotEmpty]({foo: 'bar'}); - if (typeof WeakMap === 'function') { - err(function(){ - assert[isNotEmpty](new WeakMap, 'blah'); - }, "blah: .empty was passed a weak collection"); - } + err(function(){ + assert[isNotEmpty](new WeakMap(), 'blah'); + }, "blah: .empty was passed a weak collection"); - if (typeof WeakSet === 'function') { - err(function(){ - assert[isNotEmpty](new WeakSet, 'blah'); - }, "blah: .empty was passed a weak collection"); - } + err(function(){ + assert[isNotEmpty](new WeakSet(), 'blah'); + }, "blah: .empty was passed a weak collection"); - if (typeof Map === 'function') { - // Not using Map constructor args because not supported in IE 11. - var map = new Map; - map.set('a', 1); - assert[isNotEmpty](map); + var map = new Map(); + map.set('a', 1); + assert[isNotEmpty](map); - err(function(){ - assert[isNotEmpty](new Map); - }, "expected Map{} not to be empty"); - } + err(function(){ + assert[isNotEmpty](new Map()); + }, "expected Map{} not to be empty"); - if (typeof Set === 'function') { - // Not using Set constructor args because not supported in IE 11. - var set = new Set; - set.add(1); - assert[isNotEmpty](set); + var set = new Set(); + set.add(1); + assert[isNotEmpty](set); - err(function(){ - assert[isNotEmpty](new Set); - }, "expected Set{} not to be empty"); - } + err(function(){ + assert[isNotEmpty](new Set()); + }, "expected Set{} not to be empty"); err(function(){ assert[isNotEmpty]('', 'blah'); @@ -2945,7 +2872,7 @@ describe('assert', function () { }, "expected [] not to be empty"); err(function(){ - assert[isNotEmpty](new FakeArgs); + assert[isNotEmpty](new FakeArgs()); }, "expected FakeArgs{} not to be empty"); err(function(){ @@ -2980,15 +2907,13 @@ describe('assert', function () { assert[isNotEmpty](false); }, ".empty was passed non-string primitive false"); - if (typeof Symbol !== 'undefined') { - err(function(){ - assert[isNotEmpty](Symbol()); - }, ".empty was passed non-string primitive Symbol()"); + err(function(){ + assert[isNotEmpty](Symbol()); + }, ".empty was passed non-string primitive Symbol()"); - err(function(){ - assert[isNotEmpty](Symbol.iterator); - }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); - } + err(function(){ + assert[isNotEmpty](Symbol.iterator); + }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); err(function(){ assert[isNotEmpty](function() {}, 'blah'); diff --git a/test/configuration.js b/test/configuration.js index 09e1b498..b5ac839d 100644 --- a/test/configuration.js +++ b/test/configuration.js @@ -105,10 +105,7 @@ describe('configuration', function () { it('should include Chai frames in stack trace', function () { expect(caughtErr.stack).to.contain('propertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.contain('proxyGetter'); - } + expect(caughtErr.stack).to.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -131,10 +128,7 @@ describe('configuration', function () { it('should include Chai frames in stack trace', function () { expect(caughtErr.stack).to.contain('overwritingPropertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.contain('proxyGetter'); - } + expect(caughtErr.stack).to.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -247,10 +241,7 @@ describe('configuration', function () { it('should not include Chai frames in stack trace', function () { expect(caughtErr.stack).to.not.contain('propertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.not.contain('proxyGetter'); - } + expect(caughtErr.stack).to.not.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -273,10 +264,7 @@ describe('configuration', function () { it('should not include Chai frames in stack trace', function () { expect(caughtErr.stack).to.not.contain('overwritingPropertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.not.contain('proxyGetter'); - } + expect(caughtErr.stack).to.not.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -411,10 +399,7 @@ describe('configuration', function () { it('should include Chai frames in stack trace', function () { expect(caughtErr.stack).to.contain('propertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.contain('proxyGetter'); - } + expect(caughtErr.stack).to.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -437,10 +422,7 @@ describe('configuration', function () { it('should include Chai frames in stack trace', function () { expect(caughtErr.stack).to.contain('overwritingPropertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.contain('proxyGetter'); - } + expect(caughtErr.stack).to.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -553,10 +535,7 @@ describe('configuration', function () { it('should not include Chai frames in stack trace', function () { expect(caughtErr.stack).to.not.contain('propertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.not.contain('proxyGetter'); - } + expect(caughtErr.stack).to.not.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -579,10 +558,7 @@ describe('configuration', function () { it('should not include Chai frames in stack trace', function () { expect(caughtErr.stack).to.not.contain('overwritingPropertyGetter'); - - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(caughtErr.stack).to.not.contain('proxyGetter'); - } + expect(caughtErr.stack).to.not.contain('proxyGetter'); }); it('should include user frames in stack trace', function () { @@ -767,11 +743,7 @@ describe('configuration', function () { describe('when true', function() { it('should use proxy unless user\'s environment doesn\'t support', function() { - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(readNoExistentProperty).to.throw('Invalid Chai property: tue'); - } else { - expect(readNoExistentProperty).to.not.throw('Invalid Chai property: tue'); - } + expect(readNoExistentProperty).to.throw('Invalid Chai property: tue'); }); }); @@ -806,13 +778,8 @@ describe('configuration', function () { it('should throw for properties which are not on the `proxyExcludedKeys` Array in an environment with proxy support', function() { chai.config.proxyExcludedKeys = []; - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - expect(readNoExistentProperty('then')).to.throw('Invalid Chai property: then'); - expect(readNoExistentProperty('inspect')).to.throw('Invalid Chai property: inspect'); - } else { - expect(readNoExistentProperty('then')).to.not.throw(); - expect(readNoExistentProperty('inspect')).to.not.throw(); - } + expect(readNoExistentProperty('then')).to.throw('Invalid Chai property: then'); + expect(readNoExistentProperty('inspect')).to.throw('Invalid Chai property: inspect'); }); }); diff --git a/test/expect.js b/test/expect.js index d5247655..ad702cf7 100644 --- a/test/expect.js +++ b/test/expect.js @@ -52,8 +52,6 @@ describe('expect', function () { }); describe('proxify', function () { - if (typeof Proxy === 'undefined' || typeof Reflect === 'undefined') return; - it('throws when invalid property follows expect', function () { err(function () { expect(42).pizza; @@ -371,10 +369,7 @@ describe('expect', function () { expect([]).to.be.a('array'); expect(function() {}).to.be.a('function'); expect(null).to.be.a('null'); - - if (typeof Symbol === 'function') { - expect(Symbol()).to.be.a('symbol'); - } + expect(Symbol()).to.be.a('symbol'); err(function(){ expect(5).to.not.be.a('number', 'blah'); @@ -519,31 +514,29 @@ describe('expect', function () { expect(t).to.an.instanceof(Thing); }, 'The instanceof assertion needs a constructor but Function was given.', true) - if (typeof Symbol !== 'undefined' && typeof Symbol.hasInstance !== 'undefined') { - err(function(){ - expect(new Foo()).to.an.instanceof(Symbol()); - }, "The instanceof assertion needs a constructor but Symbol was given."); - - err(function() { - var FakeConstructor = {}; - var fakeInstanceB = 4; - FakeConstructor[Symbol.hasInstance] = function (val) { - return val === 3; - }; - - expect(fakeInstanceB).to.be.an.instanceof(FakeConstructor); - }, 'expected 4 to be an instance of an unnamed constructor') - - err(function() { - var FakeConstructor = {}; - var fakeInstanceB = 4; - FakeConstructor[Symbol.hasInstance] = function (val) { - return val === 4; - }; - - expect(fakeInstanceB).to.not.be.an.instanceof(FakeConstructor); - }, 'expected 4 to not be an instance of an unnamed constructor') - } + err(function(){ + expect(new Foo()).to.an.instanceof(Symbol()); + }, "The instanceof assertion needs a constructor but Symbol was given."); + + err(function() { + var FakeConstructor = {}; + var fakeInstanceB = 4; + FakeConstructor[Symbol.hasInstance] = function (val) { + return val === 3; + }; + + expect(fakeInstanceB).to.be.an.instanceof(FakeConstructor); + }, 'expected 4 to be an instance of an unnamed constructor') + + err(function() { + var FakeConstructor = {}; + var fakeInstanceB = 4; + FakeConstructor[Symbol.hasInstance] = function (val) { + return val === 4; + }; + + expect(fakeInstanceB).to.not.be.an.instanceof(FakeConstructor); + }, 'expected 4 to not be an instance of an unnamed constructor') err(function(){ expect(3).to.an.instanceof(Foo, 'blah'); @@ -644,47 +637,43 @@ describe('expect', function () { expect(1).to.have.lengthOf.within(5, 7, 'blah'); }, "blah: expected 1 to have property 'length'"); - if (typeof Map === 'function') { - expect(new Map).to.have.length.within(0, 0); - expect(new Map).to.have.lengthOf.within(0, 0); + expect(new Map()).to.have.length.within(0, 0); + expect(new Map()).to.have.lengthOf.within(0, 0); - var map = new Map; - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); + map.set('c', 3); - expect(map).to.have.length.within(2, 4); - expect(map).to.have.lengthOf.within(2, 4); + expect(map).to.have.length.within(2, 4); + expect(map).to.have.lengthOf.within(2, 4); - err(function () { - expect(map).to.have.length.within(5, 7, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size within 5..7"); + err(function () { + expect(map).to.have.length.within(5, 7, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size within 5..7"); - err(function () { - expect(map).to.have.lengthOf.within(5, 7, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size within 5..7"); - } + err(function () { + expect(map).to.have.lengthOf.within(5, 7, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size within 5..7"); - if (typeof Set === 'function') { - expect(new Set).to.have.length.within(0, 0); - expect(new Set).to.have.lengthOf.within(0, 0); + expect(new Set()).to.have.length.within(0, 0); + expect(new Set()).to.have.lengthOf.within(0, 0); - var set = new Set; - set.add(1); - set.add(2); - set.add(3); + var set = new Set(); + set.add(1); + set.add(2); + set.add(3); - expect(set).to.have.length.within(2, 4); - expect(set).to.have.lengthOf.within(2, 4); + expect(set).to.have.length.within(2, 4); + expect(set).to.have.lengthOf.within(2, 4); - err(function () { - expect(set).to.have.length.within(5, 7, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size within 5..7"); + err(function () { + expect(set).to.have.length.within(5, 7, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size within 5..7"); - err(function () { - expect(set).to.have.lengthOf.within(5, 7, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size within 5..7"); - } + err(function () { + expect(set).to.have.lengthOf.within(5, 7, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size within 5..7"); }); it('within(start, finish) (dates)', function(){ @@ -819,47 +808,43 @@ describe('expect', function () { expect(1).to.have.lengthOf.above(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - if (typeof Map === 'function') { - expect(new Map).to.have.length.above(-1); - expect(new Map).to.have.lengthOf.above(-1); + expect(new Map()).to.have.length.above(-1); + expect(new Map()).to.have.lengthOf.above(-1); - var map = new Map; - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); + map.set('c', 3); - expect(map).to.have.length.above(2); - expect(map).to.have.lengthOf.above(2); + expect(map).to.have.length.above(2); + expect(map).to.have.lengthOf.above(2); - err(function () { - expect(map).to.have.length.above(5, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size above 5 but got 3"); + err(function () { + expect(map).to.have.length.above(5, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size above 5 but got 3"); - err(function () { - expect(map).to.have.lengthOf.above(5, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size above 5 but got 3"); - } + err(function () { + expect(map).to.have.lengthOf.above(5, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size above 5 but got 3"); - if (typeof Set === 'function') { - expect(new Set).to.have.length.above(-1); - expect(new Set).to.have.lengthOf.above(-1); + expect(new Set()).to.have.length.above(-1); + expect(new Set()).to.have.lengthOf.above(-1); - var set = new Set; - set.add(1); - set.add(2); - set.add(3); + var set = new Set(); + set.add(1); + set.add(2); + set.add(3); - expect(set).to.have.length.above(2); - expect(set).to.have.lengthOf.above(2); + expect(set).to.have.length.above(2); + expect(set).to.have.lengthOf.above(2); - err(function () { - expect(set).to.have.length.above(5, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size above 5 but got 3"); + err(function () { + expect(set).to.have.length.above(5, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size above 5 but got 3"); - err(function () { - expect(set).to.have.lengthOf.above(5, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size above 5 but got 3"); - } + err(function () { + expect(set).to.have.lengthOf.above(5, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size above 5 but got 3"); }); it('above(n) (dates)', function(){ @@ -986,47 +971,43 @@ describe('expect', function () { expect(1).to.have.lengthOf.at.least(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - if (typeof Map === 'function') { - expect(new Map).to.have.length.of.at.least(0); - expect(new Map).to.have.lengthOf.at.least(0); + expect(new Map()).to.have.length.of.at.least(0); + expect(new Map()).to.have.lengthOf.at.least(0); - var map = new Map; - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); + map.set('c', 3); - expect(map).to.have.length.of.at.least(3); - expect(map).to.have.lengthOf.at.least(3); + expect(map).to.have.length.of.at.least(3); + expect(map).to.have.lengthOf.at.least(3); - err(function () { - expect(map).to.have.length.of.at.least(4, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at least 4 but got 3"); + err(function () { + expect(map).to.have.length.of.at.least(4, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at least 4 but got 3"); - err(function () { - expect(map).to.have.lengthOf.at.least(4, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at least 4 but got 3"); - } + err(function () { + expect(map).to.have.lengthOf.at.least(4, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at least 4 but got 3"); - if (typeof Set === 'function') { - expect(new Set).to.have.length.of.at.least(0); - expect(new Set).to.have.lengthOf.at.least(0); + expect(new Set()).to.have.length.of.at.least(0); + expect(new Set()).to.have.lengthOf.at.least(0); - var set = new Set; - set.add(1); - set.add(2); - set.add(3); + var set = new Set(); + set.add(1); + set.add(2); + set.add(3); - expect(set).to.have.length.of.at.least(3); - expect(set).to.have.lengthOf.at.least(3); + expect(set).to.have.length.of.at.least(3); + expect(set).to.have.lengthOf.at.least(3); - err(function () { - expect(set).to.have.length.of.at.least(4, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size at least 4 but got 3"); + err(function () { + expect(set).to.have.length.of.at.least(4, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size at least 4 but got 3"); - err(function () { - expect(set).to.have.lengthOf.at.least(4, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size at least 4 but got 3"); - } + err(function () { + expect(set).to.have.lengthOf.at.least(4, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size at least 4 but got 3"); }); it('below(n)', function(){ @@ -1107,47 +1088,43 @@ describe('expect', function () { expect(1).to.have.lengthOf.below(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - if (typeof Map === 'function') { - expect(new Map).to.have.length.below(1); - expect(new Map).to.have.lengthOf.below(1); + expect(new Map()).to.have.length.below(1); + expect(new Map()).to.have.lengthOf.below(1); - var map = new Map; - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); + map.set('c', 3); - expect(map).to.have.length.below(4); - expect(map).to.have.lengthOf.below(4); + expect(map).to.have.length.below(4); + expect(map).to.have.lengthOf.below(4); - err(function () { - expect(map).to.have.length.below(2, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size below 2 but got 3"); + err(function () { + expect(map).to.have.length.below(2, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size below 2 but got 3"); - err(function () { - expect(map).to.have.lengthOf.below(2, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size below 2 but got 3"); - } + err(function () { + expect(map).to.have.lengthOf.below(2, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size below 2 but got 3"); - if (typeof Set === 'function') { - expect(new Set).to.have.length.below(1); - expect(new Set).to.have.lengthOf.below(1); + expect(new Set()).to.have.length.below(1); + expect(new Set()).to.have.lengthOf.below(1); - var set = new Set; - set.add(1); - set.add(2); - set.add(3); + var set = new Set(); + set.add(1); + set.add(2); + set.add(3); - expect(set).to.have.length.below(4); - expect(set).to.have.lengthOf.below(4); + expect(set).to.have.length.below(4); + expect(set).to.have.lengthOf.below(4); - err(function () { - expect(set).to.have.length.below(2, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size below 2 but got 3"); + err(function () { + expect(set).to.have.length.below(2, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size below 2 but got 3"); - err(function () { - expect(set).to.have.lengthOf.below(2, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size below 2 but got 3"); - } + err(function () { + expect(set).to.have.lengthOf.below(2, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size below 2 but got 3"); }); it('below(n) (dates)', function(){ @@ -1278,47 +1255,43 @@ describe('expect', function () { expect(1).to.have.lengthOf.at.most(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - if (typeof Map === 'function') { - expect(new Map).to.have.length.of.at.most(0); - expect(new Map).to.have.lengthOf.at.most(0); + expect(new Map()).to.have.length.of.at.most(0); + expect(new Map()).to.have.lengthOf.at.most(0); - var map = new Map; - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); + map.set('c', 3); - expect(map).to.have.length.of.at.most(3); - expect(map).to.have.lengthOf.at.most(3); + expect(map).to.have.length.of.at.most(3); + expect(map).to.have.lengthOf.at.most(3); - err(function () { - expect(map).to.have.length.of.at.most(2, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at most 2 but got 3"); + err(function () { + expect(map).to.have.length.of.at.most(2, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at most 2 but got 3"); - err(function () { - expect(map).to.have.lengthOf.at.most(2, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at most 2 but got 3"); - } + err(function () { + expect(map).to.have.lengthOf.at.most(2, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at most 2 but got 3"); - if (typeof Set === 'function') { - expect(new Set).to.have.length.of.at.most(0); - expect(new Set).to.have.lengthOf.at.most(0); + expect(new Set()).to.have.length.of.at.most(0); + expect(new Set()).to.have.lengthOf.at.most(0); - var set = new Set; - set.add(1); - set.add(2); - set.add(3); + var set = new Set(); + set.add(1); + set.add(2); + set.add(3); - expect(set).to.have.length.of.at.most(3); - expect(set).to.have.lengthOf.at.most(3); + expect(set).to.have.length.of.at.most(3); + expect(set).to.have.lengthOf.at.most(3); - err(function () { - expect(set).to.have.length.of.at.most(2, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size at most 2 but got 3"); + err(function () { + expect(set).to.have.length.of.at.most(2, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size at most 2 but got 3"); - err(function () { - expect(set).to.have.lengthOf.at.most(2, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to have a size at most 2 but got 3"); - } + err(function () { + expect(set).to.have.lengthOf.at.most(2, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to have a size at most 2 but got 3"); }); it('most(n) (dates)', function(){ @@ -1424,47 +1397,43 @@ describe('expect', function () { expect('asd').to.not.have.lengthOf(3, 'blah'); }, "blah: expected 'asd' to not have a length of 3"); - if (typeof Map === 'function') { - expect(new Map).to.have.length(0); - expect(new Map).to.have.lengthOf(0); + expect(new Map()).to.have.length(0); + expect(new Map()).to.have.lengthOf(0); - var map = new Map; - map.set('a', 1); - map.set('b', 2); - map.set('c', 3); + var map = new Map(); + map.set('a', 1); + map.set('b', 2); + map.set('c', 3); - expect(map).to.have.length(3); - expect(map).to.have.lengthOf(3); + expect(map).to.have.length(3); + expect(map).to.have.lengthOf(3); - err(function(){ - expect(map).to.not.have.length(3, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to not have a size of 3"); + err(function(){ + expect(map).to.not.have.length(3, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to not have a size of 3"); - err(function(){ - expect(map).to.not.have.lengthOf(3, 'blah'); - }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to not have a size of 3"); - } + err(function(){ + expect(map).to.not.have.lengthOf(3, 'blah'); + }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to not have a size of 3"); - if (typeof Set === 'function') { - expect(new Set).to.have.length(0); - expect(new Set).to.have.lengthOf(0); + expect(new Set()).to.have.length(0); + expect(new Set()).to.have.lengthOf(0); - var set = new Set; - set.add(1); - set.add(2); - set.add(3); + var set = new Set(); + set.add(1); + set.add(2); + set.add(3); - expect(set).to.have.length(3); - expect(set).to.have.lengthOf(3); + expect(set).to.have.length(3); + expect(set).to.have.lengthOf(3); - err(function(){ - expect(set).to.not.have.length(3, 'blah'); - }, "blah: expected Set{ 1, 2, 3 } to not have a size of 3"); + err(function(){ + expect(set).to.not.have.length(3, 'blah'); + }, "blah: expected Set{ 1, 2, 3 } to not have a size of 3"); - err(function(){ - expect(set).to.not.have.lengthOf(3, 'blah');; - }, "blah: expected Set{ 1, 2, 3 } to not have a size of 3"); - } + err(function(){ + expect(set).to.not.have.lengthOf(3, 'blah');; + }, "blah: expected Set{ 1, 2, 3 } to not have a size of 3"); }); it('eql(val)', function(){ @@ -1473,34 +1442,30 @@ describe('expect', function () { expect(1).to.eql(1); expect('4').to.not.eql(4); - if (typeof Symbol === 'function') { - var sym = Symbol(); - expect(sym).to.eql(sym); - } + var sym = Symbol(); + expect(sym).to.eql(sym); err(function(){ expect(4).to.eql(3, 'blah'); }, 'blah: expected 4 to deeply equal 3'); }); - if ('undefined' !== typeof Buffer) { - it('Buffer eql()', function () { - expect(Buffer.from([ 1 ])).to.eql(Buffer.from([ 1 ])); + it('Buffer eql()', function () { + if (typeof Buffer === 'undefined') return; - err(function () { - expect(Buffer.from([ 0 ])).to.eql(Buffer.from([ 1 ])); - }, 'expected Buffer[ 0 ] to deeply equal Buffer[ 1 ]'); - }); - } + expect(Buffer.from([ 1 ])).to.eql(Buffer.from([ 1 ])); + + err(function () { + expect(Buffer.from([ 0 ])).to.eql(Buffer.from([ 1 ])); + }, 'expected Buffer[ 0 ] to deeply equal Buffer[ 1 ]'); + }); it('equal(val)', function(){ expect('test').to.equal('test'); expect(1).to.equal(1); - if (typeof Symbol === 'function') { - var sym = Symbol(); - expect(sym).to.equal(sym); - } + var sym = Symbol(); + expect(sym).to.equal(sym); err(function(){ expect(4).to.equal(3, 'blah'); @@ -1585,64 +1550,56 @@ describe('expect', function () { expect('foo').not.to.be.empty; expect([]).to.be.empty; expect(['foo']).not.to.be.empty; - expect(new FakeArgs).to.be.empty; + expect(new FakeArgs()).to.be.empty; expect({arguments: 0}).not.to.be.empty; expect({}).to.be.empty; expect({foo: 'bar'}).not.to.be.empty; - if (typeof WeakMap === 'function') { - err(function(){ - expect(new WeakMap, 'blah').not.to.be.empty; - }, "blah: .empty was passed a weak collection"); - } + err(function(){ + expect(new WeakMap(), 'blah').not.to.be.empty; + }, "blah: .empty was passed a weak collection"); - if (typeof WeakSet === 'function') { - err(function(){ - expect(new WeakSet, 'blah').not.to.be.empty; - }, "blah: .empty was passed a weak collection"); - } + err(function(){ + expect(new WeakSet(), 'blah').not.to.be.empty; + }, "blah: .empty was passed a weak collection"); - if (typeof Map === 'function') { - expect(new Map).to.be.empty; + expect(new Map()).to.be.empty; - // Not using Map constructor args because not supported in IE 11. - var map = new Map; - map.set('a', 1); - expect(map).not.to.be.empty; + // Not using Map constructor args because not supported in IE 11. + var map = new Map(); + map.set('a', 1); + expect(map).not.to.be.empty; - err(function(){ - expect(new Map).not.to.be.empty; - }, "expected Map{} not to be empty"); + err(function(){ + expect(new Map()).not.to.be.empty; + }, "expected Map{} not to be empty"); - map = new Map; - map.key = 'val'; - expect(map).to.be.empty; + map = new Map(); + map.key = 'val'; + expect(map).to.be.empty; - err(function(){ - expect(map).not.to.be.empty; - }, "expected Map{} not to be empty"); - } + err(function(){ + expect(map).not.to.be.empty; + }, "expected Map{} not to be empty"); - if (typeof Set === 'function') { - expect(new Set).to.be.empty; + expect(new Set()).to.be.empty; - // Not using Set constructor args because not supported in IE 11. - var set = new Set; - set.add(1); - expect(set).not.to.be.empty; + // Not using Set constructor args because not supported in IE 11. + var set = new Set(); + set.add(1); + expect(set).not.to.be.empty; - err(function(){ - expect(new Set).not.to.be.empty; - }, "expected Set{} not to be empty"); + err(function(){ + expect(new Set()).not.to.be.empty; + }, "expected Set{} not to be empty"); - set = new Set; - set.key = 'val'; - expect(set).to.be.empty; + set = new Set(); + set.key = 'val'; + expect(set).to.be.empty; - err(function(){ - expect(set).not.to.be.empty; - }, "expected Set{} not to be empty"); - } + err(function(){ + expect(set).not.to.be.empty; + }, "expected Set{} not to be empty"); err(function(){ expect('', 'blah').not.to.be.empty; @@ -1661,7 +1618,7 @@ describe('expect', function () { }, "expected [ \'foo\' ] to be empty"); err(function(){ - expect(new FakeArgs).not.to.be.empty; + expect(new FakeArgs()).not.to.be.empty; }, "expected FakeArgs{} not to be empty"); err(function(){ @@ -1716,15 +1673,13 @@ describe('expect', function () { expect(false).to.be.empty; }, ".empty was passed non-string primitive false"); - if (typeof Symbol !== 'undefined') { - err(function(){ - expect(Symbol()).to.be.empty; - }, ".empty was passed non-string primitive Symbol()"); + err(function(){ + expect(Symbol()).to.be.empty; + }, ".empty was passed non-string primitive Symbol()"); - err(function(){ - expect(Symbol.iterator).to.be.empty; - }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); - } + err(function(){ + expect(Symbol.iterator).to.be.empty; + }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); err(function(){ expect(function() {}, 'blah').to.be.empty; @@ -2275,13 +2230,10 @@ describe('expect', function () { // .include should work with Error objects and objects with a custom // `@@toStringTag`. expect(new Error('foo')).to.include({message: 'foo'}); - if (typeof Symbol !== 'undefined' - && typeof Symbol.toStringTag !== 'undefined') { - var customObj = {a: 1}; - customObj[Symbol.toStringTag] = 'foo'; + var customObj = {a: 1}; + customObj[Symbol.toStringTag] = 'foo'; - expect(customObj).to.include({a: 1}); - } + expect(customObj).to.include({a: 1}); var obj1 = {a: 1} , obj2 = {b: 2}; @@ -2292,59 +2244,51 @@ describe('expect', function () { expect({foo: obj1, bar: obj2}).to.not.include({foo: {a: 1}}); expect({foo: obj1, bar: obj2}).to.not.include({foo: obj1, bar: {b: 2}}); - if (typeof Map === 'function') { - var map = new Map(); - var val = [{a: 1}]; - map.set('a', val); - map.set('b', 2); - map.set('c', -0); - map.set('d', NaN); - - expect(map).to.include(val); - expect(map).to.not.include([{a: 1}]); - expect(map).to.include(2); - expect(map).to.not.include(3); - expect(map).to.include(0); - expect(map).to.include(NaN); + var map = new Map(); + var val = [{a: 1}]; + map.set('a', val); + map.set('b', 2); + map.set('c', -0); + map.set('d', NaN); + + expect(map).to.include(val); + expect(map).to.not.include([{a: 1}]); + expect(map).to.include(2); + expect(map).to.not.include(3); + expect(map).to.include(0); + expect(map).to.include(NaN); + + var set = new Set(); + var val = [{a: 1}]; + set.add(val); + set.add(2); + set.add(-0); + set.add(NaN); + + expect(set).to.include(val); + expect(set).to.not.include([{a: 1}]); + expect(set).to.include(2); + expect(set).to.not.include(3); + if (set.has(0)) { + // This test is skipped in IE11 because (contrary to spec) IE11 uses + // SameValue instead of SameValueZero equality for sets. + expect(set).to.include(0); } + expect(set).to.include(NaN); - if (typeof Set === 'function') { - var set = new Set(); - var val = [{a: 1}]; - set.add(val); - set.add(2); - set.add(-0); - set.add(NaN); - - expect(set).to.include(val); - expect(set).to.not.include([{a: 1}]); - expect(set).to.include(2); - expect(set).to.not.include(3); - if (set.has(0)) { - // This test is skipped in IE11 because (contrary to spec) IE11 uses - // SameValue instead of SameValueZero equality for sets. - expect(set).to.include(0); - } - expect(set).to.include(NaN); - } - - if (typeof WeakSet === 'function') { - var ws = new WeakSet(); - var val = [{a: 1}]; - ws.add(val); + var ws = new WeakSet(); + var val = [{a: 1}]; + ws.add(val); - expect(ws).to.include(val); - expect(ws).to.not.include([{a: 1}]); - expect(ws).to.not.include({}); - } + expect(ws).to.include(val); + expect(ws).to.not.include([{a: 1}]); + expect(ws).to.not.include({}); - if (typeof Symbol === 'function') { - var sym1 = Symbol() - , sym2 = Symbol() - , sym3 = Symbol(); - expect([sym1, sym2]).to.include(sym1); - expect([sym1, sym2]).to.not.include(sym3); - } + var sym1 = Symbol() + , sym2 = Symbol() + , sym3 = Symbol(); + expect([sym1, sym2]).to.include(sym1); + expect([sym1, sym2]).to.not.include(sym3); err(function(){ expect(['foo']).to.include('bar', 'blah'); @@ -2467,25 +2411,19 @@ describe('expect', function () { expect({foo: obj1, bar: obj2}).to.not.deep.include({baz: {a: 1}}); expect({foo: obj1, bar: obj2}).to.not.deep.include({foo: {a: 1}, bar: {b: 9}}); - if (typeof Map === 'function') { - var map = new Map(); - map.set(1, [{a: 1}]); + var map = new Map(); + map.set(1, [{a: 1}]); - expect(map).to.deep.include([{a: 1}]); - } + expect(map).to.deep.include([{a: 1}]); - if (typeof Set === 'function') { - var set = new Set(); - set.add([{a: 1}]); + var set = new Set(); + set.add([{a: 1}]); - expect(set).to.deep.include([{a: 1}]); - } + expect(set).to.deep.include([{a: 1}]); - if (typeof WeakSet === 'function') { - err(function() { - expect(new WeakSet()).to.deep.include({}, 'foo'); - }, 'foo: unable to use .deep.include with WeakSet'); - } + err(function() { + expect(new WeakSet()).to.deep.include({}, 'foo'); + }, 'foo: unable to use .deep.include with WeakSet'); err(function () { expect([obj1, obj2]).to.deep.include({a: 9}, 'blah'); @@ -2686,286 +2624,276 @@ describe('expect', function () { expect(obj).to.have.all.keys([enumProp1, enumProp2]); expect(obj).to.not.have.all.keys([enumProp1, enumProp2, nonEnumProp]); - if (typeof Symbol === 'function') { - var sym1 = Symbol('sym1') - , sym2 = Symbol('sym2') - , sym3 = Symbol('sym3') - , str = 'str' - , obj = {}; + var sym1 = Symbol('sym1') + , sym2 = Symbol('sym2') + , sym3 = Symbol('sym3') + , str = 'str' + , obj = {}; - obj[sym1] = 'sym1'; - obj[sym2] = 'sym2'; - obj[str] = 'str'; + obj[sym1] = 'sym1'; + obj[sym2] = 'sym2'; + obj[str] = 'str'; - Object.defineProperty(obj, sym3, { - enumerable: false, - value: 'sym3' - }); + Object.defineProperty(obj, sym3, { + enumerable: false, + value: 'sym3' + }); - expect(obj).to.have.all.keys([sym1, sym2, str]); - expect(obj).to.not.have.all.keys([sym1, sym2, sym3, str]); - } + expect(obj).to.have.all.keys([sym1, sym2, str]); + expect(obj).to.not.have.all.keys([sym1, sym2, sym3, str]); - if (typeof Map !== 'undefined') { - // Not using Map constructor args because not supported in IE 11. - var aKey = {thisIs: 'anExampleObject'} - , anotherKey = {doingThisBecauseOf: 'referential equality'} - , testMap = new Map(); + // Not using Map constructor args because not supported in IE 11. + var aKey = {thisIs: 'anExampleObject'} + , anotherKey = {doingThisBecauseOf: 'referential equality'} + , testMap = new Map(); - testMap.set(aKey, 'aValue'); - testMap.set(anotherKey, 'anotherValue'); + testMap.set(aKey, 'aValue'); + testMap.set(anotherKey, 'anotherValue'); - expect(testMap).to.have.any.keys(aKey); - expect(testMap).to.have.any.keys('thisDoesNotExist', 'thisToo', aKey); - expect(testMap).to.have.all.keys(aKey, anotherKey); + expect(testMap).to.have.any.keys(aKey); + expect(testMap).to.have.any.keys('thisDoesNotExist', 'thisToo', aKey); + expect(testMap).to.have.all.keys(aKey, anotherKey); - expect(testMap).to.contain.all.keys(aKey); - expect(testMap).to.not.contain.all.keys(aKey, 'thisDoesNotExist'); + expect(testMap).to.contain.all.keys(aKey); + expect(testMap).to.not.contain.all.keys(aKey, 'thisDoesNotExist'); - expect(testMap).to.not.have.any.keys({iDoNot: 'exist'}); - expect(testMap).to.not.have.any.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); - expect(testMap).to.not.have.all.keys('thisDoesNotExist', 'thisToo', anotherKey); + expect(testMap).to.not.have.any.keys({iDoNot: 'exist'}); + expect(testMap).to.not.have.any.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); + expect(testMap).to.not.have.all.keys('thisDoesNotExist', 'thisToo', anotherKey); - expect(testMap).to.have.any.keys([aKey]); - expect(testMap).to.have.any.keys([20, 1, aKey]); - expect(testMap).to.have.all.keys([aKey, anotherKey]); + expect(testMap).to.have.any.keys([aKey]); + expect(testMap).to.have.any.keys([20, 1, aKey]); + expect(testMap).to.have.all.keys([aKey, anotherKey]); - expect(testMap).to.not.have.any.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); - expect(testMap).to.not.have.any.keys([20, 1, {13: 37}]); - expect(testMap).to.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); + expect(testMap).to.not.have.any.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); + expect(testMap).to.not.have.any.keys([20, 1, {13: 37}]); + expect(testMap).to.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); - // Ensure the assertions above use strict equality - err(function() { - expect(testMap).to.have.any.keys({thisIs: 'anExampleObject'}); - }); + // Ensure the assertions above use strict equality + err(function() { + expect(testMap).to.have.any.keys({thisIs: 'anExampleObject'}); + }); - err(function() { - expect(testMap).to.have.all.keys({thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}); - }); + err(function() { + expect(testMap).to.have.all.keys({thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}); + }); - err(function() { - expect(testMap).to.contain.all.keys({thisIs: 'anExampleObject'}); - }); + err(function() { + expect(testMap).to.contain.all.keys({thisIs: 'anExampleObject'}); + }); - err(function() { - expect(testMap).to.have.any.keys([{thisIs: 'anExampleObject'}]); - }); + err(function() { + expect(testMap).to.have.any.keys([{thisIs: 'anExampleObject'}]); + }); - err(function() { - expect(testMap).to.have.all.keys([{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - }); + err(function() { + expect(testMap).to.have.all.keys([{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + }); - // Using the same assertions as above but with `.deep` flag instead of using referential equality - expect(testMap).to.have.any.deep.keys({thisIs: 'anExampleObject'}); - expect(testMap).to.have.any.deep.keys('thisDoesNotExist', 'thisToo', {thisIs: 'anExampleObject'}); + // Using the same assertions as above but with `.deep` flag instead of using referential equality + expect(testMap).to.have.any.deep.keys({thisIs: 'anExampleObject'}); + expect(testMap).to.have.any.deep.keys('thisDoesNotExist', 'thisToo', {thisIs: 'anExampleObject'}); - expect(testMap).to.contain.all.deep.keys({thisIs: 'anExampleObject'}); - expect(testMap).to.not.contain.all.deep.keys({thisIs: 'anExampleObject'}, 'thisDoesNotExist'); + expect(testMap).to.contain.all.deep.keys({thisIs: 'anExampleObject'}); + expect(testMap).to.not.contain.all.deep.keys({thisIs: 'anExampleObject'}, 'thisDoesNotExist'); - expect(testMap).to.not.have.any.deep.keys({iDoNot: 'exist'}); - expect(testMap).to.not.have.any.deep.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); - expect(testMap).to.not.have.all.deep.keys('thisDoesNotExist', 'thisToo', {doingThisBecauseOf: 'referential equality'}); + expect(testMap).to.not.have.any.deep.keys({iDoNot: 'exist'}); + expect(testMap).to.not.have.any.deep.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); + expect(testMap).to.not.have.all.deep.keys('thisDoesNotExist', 'thisToo', {doingThisBecauseOf: 'referential equality'}); - expect(testMap).to.have.any.deep.keys([{thisIs: 'anExampleObject'}]); - expect(testMap).to.have.any.deep.keys([20, 1, {thisIs: 'anExampleObject'}]); + expect(testMap).to.have.any.deep.keys([{thisIs: 'anExampleObject'}]); + expect(testMap).to.have.any.deep.keys([20, 1, {thisIs: 'anExampleObject'}]); - expect(testMap).to.have.all.deep.keys({thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}); + expect(testMap).to.have.all.deep.keys({thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}); - expect(testMap).to.not.have.any.deep.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); - expect(testMap).to.not.have.any.deep.keys([20, 1, {13: 37}]); - expect(testMap).to.not.have.all.deep.keys([{thisIs: 'anExampleObject'}, {'iDoNot': 'exist'}]); + expect(testMap).to.not.have.any.deep.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); + expect(testMap).to.not.have.any.deep.keys([20, 1, {13: 37}]); + expect(testMap).to.not.have.all.deep.keys([{thisIs: 'anExampleObject'}, {'iDoNot': 'exist'}]); - var weirdMapKey1 = Object.create(null) - , weirdMapKey2 = {toString: NaN} - , weirdMapKey3 = [] - , weirdMap = new Map(); + var weirdMapKey1 = Object.create(null) + , weirdMapKey2 = {toString: NaN} + , weirdMapKey3 = [] + , weirdMap = new Map(); - weirdMap.set(weirdMapKey1, 'val1'); - weirdMap.set(weirdMapKey2, 'val2'); + weirdMap.set(weirdMapKey1, 'val1'); + weirdMap.set(weirdMapKey2, 'val2'); - expect(weirdMap).to.have.all.keys([weirdMapKey1, weirdMapKey2]); - expect(weirdMap).to.not.have.all.keys([weirdMapKey1, weirdMapKey3]); + expect(weirdMap).to.have.all.keys([weirdMapKey1, weirdMapKey2]); + expect(weirdMap).to.not.have.all.keys([weirdMapKey1, weirdMapKey3]); - if (typeof Symbol === 'function') { - var symMapKey1 = Symbol() - , symMapKey2 = Symbol() - , symMapKey3 = Symbol() - , symMap = new Map(); + var symMapKey1 = Symbol() + , symMapKey2 = Symbol() + , symMapKey3 = Symbol() + , symMap = new Map(); - symMap.set(symMapKey1, 'val1'); - symMap.set(symMapKey2, 'val2'); + symMap.set(symMapKey1, 'val1'); + symMap.set(symMapKey2, 'val2'); - expect(symMap).to.have.all.keys(symMapKey1, symMapKey2); - expect(symMap).to.have.any.keys(symMapKey1, symMapKey3); - expect(symMap).to.contain.all.keys(symMapKey2, symMapKey1); - expect(symMap).to.contain.any.keys(symMapKey3, symMapKey1); + expect(symMap).to.have.all.keys(symMapKey1, symMapKey2); + expect(symMap).to.have.any.keys(symMapKey1, symMapKey3); + expect(symMap).to.contain.all.keys(symMapKey2, symMapKey1); + expect(symMap).to.contain.any.keys(symMapKey3, symMapKey1); - expect(symMap).to.not.have.all.keys(symMapKey1, symMapKey3); - expect(symMap).to.not.have.any.keys(symMapKey3); - expect(symMap).to.not.contain.all.keys(symMapKey3, symMapKey1); - expect(symMap).to.not.contain.any.keys(symMapKey3); - } + expect(symMap).to.not.have.all.keys(symMapKey1, symMapKey3); + expect(symMap).to.not.have.any.keys(symMapKey3); + expect(symMap).to.not.contain.all.keys(symMapKey3, symMapKey1); + expect(symMap).to.not.contain.any.keys(symMapKey3); - var errMap = new Map(); + var errMap = new Map(); - errMap.set({ foo: 1 }); + errMap.set({ foo: 1 }); - err(function(){ - expect(errMap, 'blah').to.have.keys(); - }, "blah: keys required"); + err(function(){ + expect(errMap, 'blah').to.have.keys(); + }, "blah: keys required"); - err(function(){ - expect(errMap).to.have.keys([]); - }, "keys required"); + err(function(){ + expect(errMap).to.have.keys([]); + }, "keys required"); - err(function(){ - expect(errMap).to.contain.keys(); - }, "keys required"); + err(function(){ + expect(errMap).to.contain.keys(); + }, "keys required"); - err(function(){ - expect(errMap).to.contain.keys([]); - }, "keys required"); - - // Uncomment this after solving https://github.com/chaijs/chai/issues/662 - // This should fail because of referential equality (this is a strict comparison) - // err(function(){ - // expect(new Map([[{foo: 1}, 'bar']])).to.contain.keys({ foo: 1 }); - // }, 'expected [ [ { foo: 1 }, 'bar' ] ] to contain key { foo: 1 }'); - - // err(function(){ - // expect(new Map([[{foo: 1}, 'bar']])).to.contain.deep.keys({ iDoNotExist: 0 }) - // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); - } + err(function(){ + expect(errMap).to.contain.keys([]); + }, "keys required"); - if (typeof Set !== 'undefined') { - // Not using Set constructor args because not supported in IE 11. - var aKey = {thisIs: 'anExampleObject'} - , anotherKey = {doingThisBecauseOf: 'referential equality'} - , testSet = new Set(); + // Uncomment this after solving https://github.com/chaijs/chai/issues/662 + // This should fail because of referential equality (this is a strict comparison) + // err(function(){ + // expect(new Map([[{foo: 1}, 'bar']])).to.contain.keys({ foo: 1 }); + // }, 'expected [ [ { foo: 1 }, 'bar' ] ] to contain key { foo: 1 }'); - testSet.add(aKey); - testSet.add(anotherKey); + // err(function(){ + // expect(new Map([[{foo: 1}, 'bar']])).to.contain.deep.keys({ iDoNotExist: 0 }) + // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); - expect(testSet).to.have.any.keys(aKey); - expect(testSet).to.have.any.keys('thisDoesNotExist', 'thisToo', aKey); - expect(testSet).to.have.all.keys(aKey, anotherKey); + // Not using Set constructor args because not supported in IE 11. + var aKey = {thisIs: 'anExampleObject'} + , anotherKey = {doingThisBecauseOf: 'referential equality'} + , testSet = new Set(); - expect(testSet).to.contain.all.keys(aKey); - expect(testSet).to.not.contain.all.keys(aKey, 'thisDoesNotExist'); + testSet.add(aKey); + testSet.add(anotherKey); - expect(testSet).to.not.have.any.keys({iDoNot: 'exist'}); - expect(testSet).to.not.have.any.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); - expect(testSet).to.not.have.all.keys('thisDoesNotExist', 'thisToo', anotherKey); + expect(testSet).to.have.any.keys(aKey); + expect(testSet).to.have.any.keys('thisDoesNotExist', 'thisToo', aKey); + expect(testSet).to.have.all.keys(aKey, anotherKey); - expect(testSet).to.have.any.keys([aKey]); - expect(testSet).to.have.any.keys([20, 1, aKey]); - expect(testSet).to.have.all.keys([aKey, anotherKey]); + expect(testSet).to.contain.all.keys(aKey); + expect(testSet).to.not.contain.all.keys(aKey, 'thisDoesNotExist'); - expect(testSet).to.not.have.any.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); - expect(testSet).to.not.have.any.keys([20, 1, {13: 37}]); - expect(testSet).to.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); + expect(testSet).to.not.have.any.keys({iDoNot: 'exist'}); + expect(testSet).to.not.have.any.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); + expect(testSet).to.not.have.all.keys('thisDoesNotExist', 'thisToo', anotherKey); - // Ensure the assertions above use strict equality - err(function() { - expect(testSet).to.have.any.keys({thisIs: 'anExampleObject'}); - }); + expect(testSet).to.have.any.keys([aKey]); + expect(testSet).to.have.any.keys([20, 1, aKey]); + expect(testSet).to.have.all.keys([aKey, anotherKey]); - err(function() { - expect(testSet).to.have.all.keys({thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}); - }); + expect(testSet).to.not.have.any.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); + expect(testSet).to.not.have.any.keys([20, 1, {13: 37}]); + expect(testSet).to.not.have.all.keys([aKey, {'iDoNot': 'exist'}]); - err(function() { - expect(testSet).to.contain.all.keys({thisIs: 'anExampleObject'}); - }); + // Ensure the assertions above use strict equality + err(function() { + expect(testSet).to.have.any.keys({thisIs: 'anExampleObject'}); + }); - err(function() { - expect(testSet).to.have.any.keys([{thisIs: 'anExampleObject'}]); - }); + err(function() { + expect(testSet).to.have.all.keys({thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}); + }); - err(function() { - expect(testSet).to.have.all.keys([{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - }); + err(function() { + expect(testSet).to.contain.all.keys({thisIs: 'anExampleObject'}); + }); - // Using the same assertions as above but with `.deep` flag instead of using referential equality - expect(testSet).to.have.any.deep.keys({thisIs: 'anExampleObject'}); - expect(testSet).to.have.any.deep.keys('thisDoesNotExist', 'thisToo', {thisIs: 'anExampleObject'}); + err(function() { + expect(testSet).to.have.any.keys([{thisIs: 'anExampleObject'}]); + }); - expect(testSet).to.contain.all.deep.keys({thisIs: 'anExampleObject'}); - expect(testSet).to.not.contain.all.deep.keys({thisIs: 'anExampleObject'}, 'thisDoesNotExist'); + err(function() { + expect(testSet).to.have.all.keys([{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + }); - expect(testSet).to.not.have.any.deep.keys({iDoNot: 'exist'}); - expect(testSet).to.not.have.any.deep.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); - expect(testSet).to.not.have.all.deep.keys('thisDoesNotExist', 'thisToo', {doingThisBecauseOf: 'referential equality'}); + // Using the same assertions as above but with `.deep` flag instead of using referential equality + expect(testSet).to.have.any.deep.keys({thisIs: 'anExampleObject'}); + expect(testSet).to.have.any.deep.keys('thisDoesNotExist', 'thisToo', {thisIs: 'anExampleObject'}); - expect(testSet).to.have.any.deep.keys([{thisIs: 'anExampleObject'}]); - expect(testSet).to.have.any.deep.keys([20, 1, {thisIs: 'anExampleObject'}]); + expect(testSet).to.contain.all.deep.keys({thisIs: 'anExampleObject'}); + expect(testSet).to.not.contain.all.deep.keys({thisIs: 'anExampleObject'}, 'thisDoesNotExist'); - expect(testSet).to.have.all.deep.keys([{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); + expect(testSet).to.not.have.any.deep.keys({iDoNot: 'exist'}); + expect(testSet).to.not.have.any.deep.keys('thisIsNotAkey', {iDoNot: 'exist'}, {33: 20}); + expect(testSet).to.not.have.all.deep.keys('thisDoesNotExist', 'thisToo', {doingThisBecauseOf: 'referential equality'}); - expect(testSet).to.not.have.any.deep.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); - expect(testSet).to.not.have.any.deep.keys([20, 1, {13: 37}]); - expect(testSet).to.not.have.all.deep.keys([{thisIs: 'anExampleObject'}, {'iDoNot': 'exist'}]); + expect(testSet).to.have.any.deep.keys([{thisIs: 'anExampleObject'}]); + expect(testSet).to.have.any.deep.keys([20, 1, {thisIs: 'anExampleObject'}]); - var weirdSetKey1 = Object.create(null) - , weirdSetKey2 = {toString: NaN} - , weirdSetKey3 = [] - , weirdSet = new Set(); + expect(testSet).to.have.all.deep.keys([{thisIs: 'anExampleObject'}, {doingThisBecauseOf: 'referential equality'}]); - weirdSet.add(weirdSetKey1); - weirdSet.add(weirdSetKey2); + expect(testSet).to.not.have.any.deep.keys([{13: 37}, 'thisDoesNotExist', 'thisToo']); + expect(testSet).to.not.have.any.deep.keys([20, 1, {13: 37}]); + expect(testSet).to.not.have.all.deep.keys([{thisIs: 'anExampleObject'}, {'iDoNot': 'exist'}]); - expect(weirdSet).to.have.all.keys([weirdSetKey1, weirdSetKey2]); - expect(weirdSet).to.not.have.all.keys([weirdSetKey1, weirdSetKey3]); + var weirdSetKey1 = Object.create(null) + , weirdSetKey2 = {toString: NaN} + , weirdSetKey3 = [] + , weirdSet = new Set(); - if (typeof Symbol === 'function') { - var symSetKey1 = Symbol() - , symSetKey2 = Symbol() - , symSetKey3 = Symbol() - , symSet = new Set(); + weirdSet.add(weirdSetKey1); + weirdSet.add(weirdSetKey2); - symSet.add(symSetKey1); - symSet.add(symSetKey2); + expect(weirdSet).to.have.all.keys([weirdSetKey1, weirdSetKey2]); + expect(weirdSet).to.not.have.all.keys([weirdSetKey1, weirdSetKey3]); - expect(symSet).to.have.all.keys(symSetKey1, symSetKey2); - expect(symSet).to.have.any.keys(symSetKey1, symSetKey3); - expect(symSet).to.contain.all.keys(symSetKey2, symSetKey1); - expect(symSet).to.contain.any.keys(symSetKey3, symSetKey1); + var symSetKey1 = Symbol() + , symSetKey2 = Symbol() + , symSetKey3 = Symbol() + , symSet = new Set(); - expect(symSet).to.not.have.all.keys(symSetKey1, symSetKey3); - expect(symSet).to.not.have.any.keys(symSetKey3); - expect(symSet).to.not.contain.all.keys(symSetKey3, symSetKey1); - expect(symSet).to.not.contain.any.keys(symSetKey3); - } + symSet.add(symSetKey1); + symSet.add(symSetKey2); - var errSet = new Set(); - errSet.add({ foo: 1}); + expect(symSet).to.have.all.keys(symSetKey1, symSetKey2); + expect(symSet).to.have.any.keys(symSetKey1, symSetKey3); + expect(symSet).to.contain.all.keys(symSetKey2, symSetKey1); + expect(symSet).to.contain.any.keys(symSetKey3, symSetKey1); - err(function(){ - expect(errSet, 'blah').to.have.keys(); - }, "blah: keys required"); + expect(symSet).to.not.have.all.keys(symSetKey1, symSetKey3); + expect(symSet).to.not.have.any.keys(symSetKey3); + expect(symSet).to.not.contain.all.keys(symSetKey3, symSetKey1); + expect(symSet).to.not.contain.any.keys(symSetKey3); - err(function(){ - expect(errSet).to.have.keys([]); - }, "keys required"); + var errSet = new Set(); + errSet.add({ foo: 1}); - err(function(){ - expect(errSet).to.contain.keys(); - }, "keys required"); + err(function(){ + expect(errSet, 'blah').to.have.keys(); + }, "blah: keys required"); - err(function(){ - expect(errSet).to.contain.keys([]); - }, "keys required"); - - // Uncomment this after solving https://github.com/chaijs/chai/issues/662 - // This should fail because of referential equality (this is a strict comparison) - // err(function(){ - // expect(new Set([{foo: 1}])).to.contain.keys({ foo: 1 }); - // }, 'expected [ { foo: 1 } ] to deeply contain key { foo: 1 }'); - - // err(function(){ - // expect(new Set([{foo: 1}])).to.contain.deep.keys({ iDoNotExist: 0 }); - // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); - } + err(function(){ + expect(errSet).to.have.keys([]); + }, "keys required"); + + err(function(){ + expect(errSet).to.contain.keys(); + }, "keys required"); + + err(function(){ + expect(errSet).to.contain.keys([]); + }, "keys required"); + + // Uncomment this after solving https://github.com/chaijs/chai/issues/662 + // This should fail because of referential equality (this is a strict comparison) + // err(function(){ + // expect(new Set([{foo: 1}])).to.contain.keys({ foo: 1 }); + // }, 'expected [ { foo: 1 } ] to deeply contain key { foo: 1 }'); + + // err(function(){ + // expect(new Set([{foo: 1}])).to.contain.deep.keys({ iDoNotExist: 0 }); + // }, 'expected [ { foo: 1 } ] to deeply contain key { iDoNotExist: 0 }'); err(function(){ expect({ foo: 1 }, 'blah').to.have.keys(); @@ -3469,9 +3397,11 @@ describe('expect', function () { }); it('same.members', function() { - expect([5, 4]).to.have.same.members([4, 5]); expect([5, 4]).to.have.same.members([5, 4]); + expect([5, 4]).to.have.same.members([4, 5]); expect([5, 4, 4]).to.have.same.members([5, 4, 4]); + expect(new Set([5, 4])).to.have.same.members([4, 5]); + expect([5, 4]).to.not.have.same.members([]); expect([5, 4]).to.not.have.same.members([6, 3]); expect([5, 4]).to.not.have.same.members([5, 4, 2]); @@ -3479,6 +3409,7 @@ describe('expect', function () { expect([5, 4, 4]).to.not.have.same.members([5, 4]); expect([5, 4, 4]).to.not.have.same.members([5, 4, 3]); expect([5, 4, 3]).to.not.have.same.members([5, 4, 4]); + expect(new Set([5, 4])).to.not.have.same.members([4]); }); it('members', function() { @@ -3508,19 +3439,19 @@ describe('expect', function () { err(function () { expect({}).members([], 'blah'); - }, 'blah: expected {} to be an array'); + }, 'blah: expected {} to be an iterable'); err(function () { expect({}, 'blah').members([]); - }, 'blah: expected {} to be an array'); + }, 'blah: expected {} to be an iterable'); err(function () { expect([]).members({}, 'blah'); - }, 'blah: expected {} to be an array'); + }, 'blah: expected {} to be an iterable'); err(function () { expect([], 'blah').members({}); - }, 'blah: expected {} to be an array'); + }, 'blah: expected {} to be an iterable'); }); it('deep.members', function() { @@ -3641,6 +3572,33 @@ describe('expect', function () { }, 'expected [ { a: 1 }, { b: 2 }, { c: 3 } ] to not be an ordered superset of [ { a: 1 }, { b: 2 } ]'); }); + it('iterable', function() { + expect([1, 2, 3]).to.be.iterable; + expect(new Map([[1, 'one'], [2, 'two'], [3, 'three']])).to.be.iterable; + expect(new Set([1, 2, 3])).to.be.iterable; + expect('hello').to.be.iterable; + + err(function() { + expect(42).to.be.iterable; + }, 'expected 42 to be an iterable'); + + err(function() { + expect(undefined).to.be.iterable; + }, 'expected undefined to be an iterable'); + + err(function() { + expect(null).to.be.iterable; + }, 'expected null to be an iterable'); + + err(function() { + expect(true).to.be.iterable; + }, 'expected true to be an iterable'); + + err(function() { + expect({ key: 'value' }).to.be.iterable; + }, 'expected { key: \'value\' } to be an iterable'); + }) + it('change', function() { var obj = { value: 10, str: 'foo' }, heroes = ['spiderman', 'superman'], @@ -3873,9 +3831,7 @@ describe('expect', function () { expect(false).to.not.be.extensible; expect(undefined).to.not.be.extensible; - if (typeof Symbol === 'function') { - expect(Symbol()).to.not.be.extensible; - } + expect(Symbol()).to.not.be.extensible; err(function() { expect(42).to.be.extensible; @@ -3897,18 +3853,16 @@ describe('expect', function () { expect(undefined).to.be.extensible; }, 'expected undefined to be extensible'); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - isExtensible: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + isExtensible: function() { + throw new TypeError(); + } + }); - err(function() { - // .extensible should not suppress errors, thrown in proxy traps - expect(proxy).to.be.extensible; - }, { name: 'TypeError' }, true); - } + err(function() { + // .extensible should not suppress errors, thrown in proxy traps + expect(proxy).to.be.extensible; + }, { name: 'TypeError' }, true); }); it('sealed', function() { @@ -3932,10 +3886,7 @@ describe('expect', function () { expect('foo').to.be.sealed; expect(false).to.be.sealed; expect(undefined).to.be.sealed; - - if (typeof Symbol === 'function') { - expect(Symbol()).to.be.sealed; - } + expect(Symbol()).to.be.sealed; err(function() { expect(42).to.not.be.sealed; @@ -3957,21 +3908,19 @@ describe('expect', function () { expect(undefined).to.not.be.sealed; }, 'expected undefined to not be sealed'); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - ownKeys: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + ownKeys: function() { + throw new TypeError(); + } + }); - // Object.isSealed will call ownKeys trap only if object is not extensible - Object.preventExtensions(proxy); + // Object.isSealed will call ownKeys trap only if object is not extensible + Object.preventExtensions(proxy); - err(function() { - // .sealed should not suppress errors, thrown in proxy traps - expect(proxy).to.be.sealed; - }, { name: 'TypeError' }, true); - } + err(function() { + // .sealed should not suppress errors, thrown in proxy traps + expect(proxy).to.be.sealed; + }, { name: 'TypeError' }, true); }); it('frozen', function() { @@ -3995,10 +3944,7 @@ describe('expect', function () { expect('foo').to.be.frozen; expect(false).to.be.frozen; expect(undefined).to.be.frozen; - - if (typeof Symbol === 'function') { - expect(Symbol()).to.be.frozen; - } + expect(Symbol()).to.be.frozen; err(function() { expect(42).to.not.be.frozen; @@ -4020,20 +3966,18 @@ describe('expect', function () { expect(undefined).to.not.be.frozen; }, 'expected undefined to not be frozen'); - if (typeof Proxy === 'function') { - var proxy = new Proxy({}, { - ownKeys: function() { - throw new TypeError(); - } - }); + var proxy = new Proxy({}, { + ownKeys: function() { + throw new TypeError(); + } + }); - // Object.isFrozen will call ownKeys trap only if object is not extensible - Object.preventExtensions(proxy); + // Object.isFrozen will call ownKeys trap only if object is not extensible + Object.preventExtensions(proxy); - err(function() { - // .frozen should not suppress errors, thrown in proxy traps - expect(proxy).to.be.frozen; - }, { name: 'TypeError' }, true); - } + err(function() { + // .frozen should not suppress errors, thrown in proxy traps + expect(proxy).to.be.frozen; + }, { name: 'TypeError' }, true); }); }); diff --git a/test/globalErr.js b/test/globalErr.js index a93f7738..d51b3fe8 100644 --- a/test/globalErr.js +++ b/test/globalErr.js @@ -186,12 +186,12 @@ describe('globalErr', function () { , undefined ]; - if (typeof Symbol === 'function') vals.push(Symbol()); - if (typeof Map === 'function') vals.push(new Map()); - if (typeof WeakMap === 'function') vals.push(new WeakMap()); - if (typeof Set === 'function') vals.push(new Set()); - if (typeof WeakSet === 'function') vals.push(new WeakSet()); - if (typeof Promise === 'function') vals.push(new Promise(noop)); + vals.push(Symbol()); + vals.push(new Map()); + vals.push(new Set()); + vals.push(new WeakMap()); + vals.push(new WeakSet()); + vals.push(new Promise(noop)); vals.forEach(function (val) { err(function () { err(val) }, 'Invalid fn') @@ -207,12 +207,12 @@ describe('globalErr', function () { , null ]; - if (typeof Symbol === 'function') vals.push(Symbol()); - if (typeof Map === 'function') vals.push(new Map()); - if (typeof WeakMap === 'function') vals.push(new WeakMap()); - if (typeof Set === 'function') vals.push(new Set()); - if (typeof WeakSet === 'function') vals.push(new WeakSet()); - if (typeof Promise === 'function') vals.push(new Promise(noop)); + vals.push(Symbol()); + vals.push(new Map()); + vals.push(new WeakMap()); + vals.push(new Set()); + vals.push(new WeakSet()); + vals.push(new Promise(noop)); vals.forEach(function (val) { err(function () { diff --git a/test/should.js b/test/should.js index adb94d94..baa7891f 100644 --- a/test/should.js +++ b/test/should.js @@ -585,10 +585,10 @@ describe('should', function() { (1).should.have.lengthOf.within(5,7, 'blah'); }, "blah: expected 1 to have property 'length'"); - (new Map).should.have.length.within(0, 0); - (new Map).should.have.lengthOf.within(0, 0); + (new Map()).should.have.length.within(0, 0); + (new Map()).should.have.lengthOf.within(0, 0); - var map = new Map; + var map = new Map(); map.set('a', 1); map.set('b', 2); map.set('c', 3); @@ -604,10 +604,10 @@ describe('should', function() { map.should.have.lengthOf.within(5, 7, 'blah'); }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size within 5..7"); - (new Set).should.have.length.within(0, 0); - (new Set).should.have.lengthOf.within(0, 0); + (new Set()).should.have.length.within(0, 0); + (new Set()).should.have.lengthOf.within(0, 0); - var set = new Set; + var set = new Set(); set.add(1); set.add(2); set.add(3); @@ -728,10 +728,10 @@ describe('should', function() { (1).should.have.lengthOf.above(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - (new Map).should.have.length.above(-1); - (new Map).should.have.lengthOf.above(-1); + (new Map()).should.have.length.above(-1); + (new Map()).should.have.lengthOf.above(-1); - var map = new Map; + var map = new Map(); map.set('a', 1); map.set('b', 2); map.set('c', 3); @@ -747,10 +747,10 @@ describe('should', function() { map.should.have.lengthOf.above(5, 'blah'); }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size above 5 but got 3"); - (new Set).should.have.length.above(-1); - (new Set).should.have.lengthOf.above(-1); + (new Set()).should.have.length.above(-1); + (new Set()).should.have.lengthOf.above(-1); - var set = new Set; + var set = new Set(); set.add(1); set.add(2); set.add(3); @@ -846,10 +846,10 @@ describe('should', function() { (1).should.not.be.at.least(null, 'blah'); }, "blah: the argument to least must be a number"); - (new Map).should.have.length.of.at.least(0); - (new Map).should.have.lengthOf.at.least(0); + (new Map()).should.have.length.of.at.least(0); + (new Map()).should.have.lengthOf.at.least(0); - var map = new Map; + var map = new Map(); map.set('a', 1); map.set('b', 2); map.set('c', 3); @@ -865,10 +865,10 @@ describe('should', function() { map.should.have.lengthOf.at.least(4, 'blah'); }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at least 4 but got 3"); - (new Set).should.have.length.of.at.least(0); - (new Set).should.have.lengthOf.at.least(0); + (new Set()).should.have.length.of.at.least(0); + (new Set()).should.have.lengthOf.at.least(0); - var set = new Set; + var set = new Set(); set.add(1); set.add(2); set.add(3); @@ -931,10 +931,10 @@ describe('should', function() { (1).should.have.lengthOf.below(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - (new Map).should.have.length.below(1); - (new Map).should.have.lengthOf.below(1); + (new Map()).should.have.length.below(1); + (new Map()).should.have.lengthOf.below(1); - var map = new Map; + var map = new Map(); map.set('a', 1); map.set('b', 2); map.set('c', 3); @@ -950,10 +950,10 @@ describe('should', function() { map.should.have.lengthOf.below(2, 'blah'); }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size below 2 but got 3"); - (new Set).should.have.length.below(1); - (new Set).should.have.lengthOf.below(1); + (new Set()).should.have.length.below(1); + (new Set()).should.have.lengthOf.below(1); - var set = new Set; + var set = new Set(); set.add(1); set.add(2); set.add(3); @@ -1057,10 +1057,10 @@ describe('should', function() { (1).should.have.lengthOf.at.most(0, 'blah'); }, "blah: expected 1 to have property 'length'"); - (new Map).should.have.length.of.at.most(0); - (new Map).should.have.lengthOf.at.most(0); + (new Map()).should.have.length.of.at.most(0); + (new Map()).should.have.lengthOf.at.most(0); - var map = new Map; + var map = new Map(); map.set('a', 1); map.set('b', 2); map.set('c', 3); @@ -1076,10 +1076,10 @@ describe('should', function() { map.should.have.lengthOf.at.most(2, 'blah'); }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to have a size at most 2 but got 3"); - (new Set).should.have.length.of.at.most(0); - (new Set).should.have.lengthOf.at.most(0); + (new Set()).should.have.length.of.at.most(0); + (new Set()).should.have.lengthOf.at.most(0); - var set = new Set; + var set = new Set(); set.add(1); set.add(2); set.add(3); @@ -1186,10 +1186,10 @@ describe('should', function() { 'asd'.should.not.have.lengthOf(3, 'blah'); }, "blah: expected 'asd' to not have a length of 3"); - (new Map).should.have.length(0); - (new Map).should.have.lengthOf(0); + (new Map()).should.have.length(0); + (new Map()).should.have.lengthOf(0); - var map = new Map; + var map = new Map(); map.set('a', 1); map.set('b', 2); map.set('c', 3); @@ -1205,10 +1205,10 @@ describe('should', function() { map.should.not.have.lengthOf(3, 'blah'); }, "blah: expected Map{ 'a' => 1, 'b' => 2, 'c' => 3 } to not have a size of 3"); - (new Set).should.have.length(0); - (new Set).should.have.lengthOf(0); + (new Set()).should.have.length(0); + (new Set()).should.have.lengthOf(0); - var set = new Set; + var set = new Set(); set.add(1); set.add(2); set.add(3); @@ -1291,31 +1291,31 @@ describe('should', function() { 'foo'.should.not.be.empty; ([]).should.be.empty; (['foo']).should.not.be.empty; - (new FakeArgs).should.be.empty; + (new FakeArgs()).should.be.empty; ({arguments: 0}).should.not.be.empty; ({}).should.be.empty; ({foo: 'bar'}).should.not.be.empty; err(function(){ - (new WeakMap).should.not.be.empty; + (new WeakMap()).should.not.be.empty; }, ".empty was passed a weak collection"); err(function(){ - (new WeakSet).should.not.be.empty; + (new WeakSet()).should.not.be.empty; }, ".empty was passed a weak collection"); - (new Map).should.be.empty; + (new Map()).should.be.empty; // Not using Map constructor args because not supported in IE 11. - var map = new Map; + var map = new Map(); map.set('a', 1); map.should.not.be.empty; err(function(){ - (new Map).should.not.be.empty; + (new Map()).should.not.be.empty; }, "expected Map{} not to be empty"); - map = new Map; + map = new Map(); map.key = 'val'; map.should.be.empty; @@ -1323,18 +1323,18 @@ describe('should', function() { map.should.not.be.empty; }, "expected Map{} not to be empty"); - (new Set).should.be.empty; + (new Set()).should.be.empty; // Not using Set constructor args because not supported in IE 11. - var set = new Set; + var set = new Set(); set.add(1); set.should.not.be.empty; err(function(){ - (new Set).should.not.be.empty; + (new Set()).should.not.be.empty; }, "expected Set{} not to be empty"); - set = new Set; + set = new Set(); set.key = 'val'; set.should.be.empty; @@ -1359,7 +1359,7 @@ describe('should', function() { }, "expected [ \'foo\' ] to be empty"); err(function(){ - (new FakeArgs).should.not.be.empty; + (new FakeArgs()).should.not.be.empty; }, "expected FakeArgs{} not to be empty"); err(function(){ @@ -1390,15 +1390,13 @@ describe('should', function() { false.should.be.empty; }, ".empty was passed non-string primitive false"); - if (typeof Symbol !== 'undefined') { - err(function(){ - Symbol().should.be.empty; - }, ".empty was passed non-string primitive Symbol()"); + err(function(){ + Symbol().should.be.empty; + }, ".empty was passed non-string primitive Symbol()"); - err(function(){ - Symbol.iterator.should.be.empty; - }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); - } + err(function(){ + Symbol.iterator.should.be.empty; + }, ".empty was passed non-string primitive Symbol(Symbol.iterator)"); err(function(){ (function() {}).should.be.empty; @@ -1812,13 +1810,10 @@ describe('should', function() { // .include should work with Error objects and objects with a custom // `@@toStringTag`. (new Error('foo')).should.include({message: 'foo'}); - if (typeof Symbol !== 'undefined' - && typeof Symbol.toStringTag !== 'undefined') { - var customObj = {a: 1}; - customObj[Symbol.toStringTag] = 'foo'; + var customObj = {a: 1}; + customObj[Symbol.toStringTag] = 'foo'; - customObj.should.include({a: 1}); - } + customObj.should.include({a: 1}); ({a: 1}).should.include({'toString': Object.prototype.toString}); @@ -2820,11 +2815,11 @@ describe('should', function() { err(function() { 'foo'.should.include.members([12], 'blah'); - }, "blah: expected 'foo' to be an array"); + }, "blah: expected 'foo' to be a superset of [ 12 ]"); err(function() { [1, 2, 3].should.include.members('o', 'blah'); - }, "blah: expected 'o' to be an array"); + }, "blah: expected [ 1, 2, 3 ] to be a superset of 'o'"); }); it('memberEquals', function() { @@ -2832,12 +2827,15 @@ describe('should', function() { [5, 4].should.have.same.members([5, 4]); [5, 4, 4].should.have.same.members([5, 4, 4]); [].should.have.same.members([]); + (new Set([])).should.have.same.members(new Set([])); + (new Set([1,2,3])).should.have.same.members(new Set([3,2,1])); [5, 4].should.not.have.same.members([5, 4, 4]); [5, 4, 4].should.not.have.same.members([5, 4]); [5, 4, 4].should.not.have.same.members([5, 4, 3]); [5, 4, 3].should.not.have.same.members([5, 4, 4]); [{a: 1}].should.not.have.same.members([{a: 1}]); + (new Set([1,2,3])).should.not.have.same.members(new Set([2,1])); err(function() { [1, 2, 3].should.have.same.members([], 'blah'); @@ -2845,7 +2843,7 @@ describe('should', function() { err(function() { [1, 2, 3].should.have.same.members(4, 'blah'); - }, 'blah: expected 4 to be an array'); + }, 'blah: expected 4 to be an iterable'); }); it('deep.members', function() { @@ -2942,6 +2940,25 @@ describe('should', function() { }, 'expected [ { a: 1 }, { b: 2 }, { c: 3 } ] to not be an ordered superset of [ { a: 1 }, { b: 2 } ]'); }); + it ('iterable', function() { + ([1, 2, 3]).should.be.iterable; + (new Map([[1, 'one'], [2, 'two'], [3, 'three']])).should.be.iterable; + (new Set([1, 2, 3])).should.be.iterable; + ('hello').should.be.iterable; + + err(function() { + (42).should.be.iterable; + }, 'expected 42 to be an iterable'); + + err(function() { + (true).should.be.iterable; + }, 'expected true to be an iterable'); + + err(function() { + ({ key: 'value' }).should.be.iterable; + }, 'expected { key: \'value\' } to be an iterable'); + }) + it('change', function() { var obj = { value: 10, str: 'foo' }, heroes = ['spiderman', 'superman'], diff --git a/test/utilities.js b/test/utilities.js index 5a00da46..3e956352 100644 --- a/test/utilities.js +++ b/test/utilities.js @@ -750,8 +750,6 @@ describe('utilities', function () { }); it('inspect Symbol', function () { - if (typeof Symbol !== 'function') return; - chai.use(function (_chai, _) { expect(_.inspect(Symbol())).to.equal('Symbol()'); expect(_.inspect(Symbol('cat'))).to.equal('Symbol(cat)'); @@ -759,8 +757,6 @@ describe('utilities', function () { }); it('inspect BigInt', function () { - if (typeof BigInt !== 'function') return; - chai.use(function (_chai, _) { expect(_.inspect(BigInt(0))).to.equal('0n'); expect(_.inspect(BigInt(1234))).to.equal('1234n'); @@ -1089,11 +1085,9 @@ describe('utilities', function () { expect(cbi({'cat': [['dog', 1]]}, {'cat': [['dog', 2]]})).to.equal(-1); expect(cbi({'cat': [['dog', 2]]}, {'cat': [['dog', 1]]})).to.equal(1); - if (typeof Symbol === 'function') { - // "Symbol(c" is less than "Symbol(d" - expect(cbi(Symbol('cat'), Symbol('dog'))).to.equal(-1); - expect(cbi(Symbol('dog'), Symbol('cat'))).to.equal(1); - } + // "Symbol(c" is less than "Symbol(d" + expect(cbi(Symbol('cat'), Symbol('dog'))).to.equal(-1); + expect(cbi(Symbol('dog'), Symbol('cat'))).to.equal(1); }); }); @@ -1116,8 +1110,6 @@ describe('utilities', function () { }); it('returns enumerable symbols only', function () { - if (typeof Symbol !== 'function') return; - var cat = Symbol('cat') , dog = Symbol('dog') , frog = Symbol('frog') @@ -1165,8 +1157,6 @@ describe('utilities', function () { }); it('returns enumerable property names and symbols', function () { - if (typeof Symbol !== 'function') return; - var cat = Symbol('cat') , dog = Symbol('dog') , frog = Symbol('frog') @@ -1193,8 +1183,6 @@ describe('utilities', function () { }); describe('proxified object', function () { - if (typeof Proxy === 'undefined' || typeof Reflect === 'undefined') return; - var proxify; beforeEach(function () { @@ -1324,27 +1312,15 @@ describe('utilities', function () { chai.config.useProxy = origUseProxy; }); - if (typeof Proxy !== 'undefined' && typeof Reflect !== 'undefined') { - it("returns true if Proxy and Reflect are defined, and useProxy is true", function () { - expect(isProxyEnabled()).to.be.true; - }); - - it("returns false if Proxy and Reflect are defined, and useProxy is false", function () { - chai.config.useProxy = false; - - expect(isProxyEnabled()).to.be.false; - }); - } else { - it("returns false if Proxy and/or Reflect are undefined, and useProxy is true", function () { - expect(isProxyEnabled()).to.be.false; - }); + it("returns true if Proxy and Reflect are defined, and useProxy is true", function () { + expect(isProxyEnabled()).to.be.true; + }); - it("returns false if Proxy and/or Reflect are undefined, and useProxy is false", function () { - chai.config.useProxy = false; + it("returns false if Proxy and Reflect are defined, and useProxy is false", function () { + chai.config.useProxy = false; - expect(isProxyEnabled()).to.be.false; - }); - } + expect(isProxyEnabled()).to.be.false; + }); }); describe('getOperator', function() {