chai 5.0.2 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ import {config} from './config.js';
9
9
  import {AssertionError} from 'assertion-error';
10
10
  import * as util from './utils/index.js';
11
11
 
12
- /*!
12
+ /**
13
13
  * Assertion Constructor
14
14
  *
15
15
  * Creates object for chaining.
@@ -147,14 +147,13 @@ Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual,
147
147
  }
148
148
  };
149
149
 
150
- /*!
150
+ /**
151
151
  * ### ._obj
152
152
  *
153
153
  * Quick reference to stored `actual` value for plugin developers.
154
154
  *
155
155
  * @api private
156
156
  */
157
-
158
157
  Object.defineProperty(Assertion.prototype, '_obj',
159
158
  { get: function () {
160
159
  return util.flag(this, 'object');
@@ -3037,7 +3037,9 @@ Assertion.addMethod('closeTo', closeTo);
3037
3037
  Assertion.addMethod('approximately', closeTo);
3038
3038
 
3039
3039
  // Note: Duplicates are ignored if testing for inclusion instead of sameness.
3040
- function isSubsetOf(subset, superset, cmp, contains, ordered) {
3040
+ function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
3041
+ let superset = Array.from(_superset);
3042
+ let subset = Array.from(_subset);
3041
3043
  if (!contains) {
3042
3044
  if (subset.length !== superset.length) return false;
3043
3045
  superset = superset.slice();
@@ -3133,15 +3135,14 @@ function isSubsetOf(subset, superset, cmp, contains, ordered) {
3133
3135
  * @namespace BDD
3134
3136
  * @api public
3135
3137
  */
3136
-
3137
3138
  Assertion.addMethod('members', function (subset, msg) {
3138
3139
  if (msg) flag(this, 'message', msg);
3139
3140
  var obj = flag(this, 'object')
3140
3141
  , flagMsg = flag(this, 'message')
3141
3142
  , ssfi = flag(this, 'ssfi');
3142
3143
 
3143
- new Assertion(obj, flagMsg, ssfi, true).to.be.an('array');
3144
- new Assertion(subset, flagMsg, ssfi, true).to.be.an('array');
3144
+ new Assertion(obj, flagMsg, ssfi, true).to.be.iterable;
3145
+ new Assertion(subset, flagMsg, ssfi, true).to.be.iterable;
3145
3146
 
3146
3147
  var contains = flag(this, 'contains');
3147
3148
  var ordered = flag(this, 'ordered');
@@ -3170,6 +3171,39 @@ Assertion.addMethod('members', function (subset, msg) {
3170
3171
  );
3171
3172
  });
3172
3173
 
3174
+ /**
3175
+ * ### .iterable
3176
+ *
3177
+ * Asserts that the target is an iterable, which means that it has a iterator.
3178
+ *
3179
+ * expect([1, 2]).to.be.iterable;
3180
+ * expect("foobar").to.be.iterable;
3181
+ *
3182
+ * Add `.not` earlier in the chain to negate `.iterable`.
3183
+ *
3184
+ * expect(1).to.not.be.iterable;
3185
+ * expect(true).to.not.be.iterable;
3186
+ *
3187
+ * A custom error message can be given as the second argument to `expect`.
3188
+ *
3189
+ * expect(1, 'nooo why fail??').to.be.iterable;
3190
+ *
3191
+ * @name iterable
3192
+ * @namespace BDD
3193
+ * @api public
3194
+ */
3195
+ Assertion.addProperty('iterable', function(msg) {
3196
+ if (msg) flag(this, 'message', msg);
3197
+ var obj = flag(this, 'object');
3198
+
3199
+ this.assert(
3200
+ obj != undefined && obj[Symbol.iterator]
3201
+ , 'expected #{this} to be an iterable'
3202
+ , 'expected #{this} to not be an iterable'
3203
+ , obj
3204
+ );
3205
+ });
3206
+
3173
3207
  /**
3174
3208
  * ### .oneOf(list[, msg])
3175
3209
  *