chai 4.1.0 → 4.1.1
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.
- package/chai.js +75 -70
- package/lib/chai/core/assertions.js +70 -65
- package/lib/chai/interface/assert.js +4 -4
- package/lib/chai.js +1 -1
- package/package.json +1 -1
package/chai.js
CHANGED
|
@@ -14,7 +14,7 @@ var used = [];
|
|
|
14
14
|
* Chai version
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
exports.version = '4.1.
|
|
17
|
+
exports.version = '4.1.1';
|
|
18
18
|
|
|
19
19
|
/*!
|
|
20
20
|
* Assertion Error
|
|
@@ -830,53 +830,18 @@ module.exports = function (chai, _) {
|
|
|
830
830
|
|
|
831
831
|
function include (val, msg) {
|
|
832
832
|
if (msg) flag(this, 'message', msg);
|
|
833
|
-
|
|
834
|
-
_.expectTypes(this, [
|
|
835
|
-
'array', 'object', 'string',
|
|
836
|
-
'map', 'set', 'weakset',
|
|
837
|
-
]);
|
|
838
|
-
|
|
833
|
+
|
|
839
834
|
var obj = flag(this, 'object')
|
|
840
|
-
, objType = _.type(obj).toLowerCase()
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
, firstErr = null
|
|
847
|
-
, numErrs = 0;
|
|
848
|
-
|
|
849
|
-
props.forEach(function (prop) {
|
|
850
|
-
var propAssertion = new Assertion(obj);
|
|
851
|
-
_.transferFlags(this, propAssertion, true);
|
|
852
|
-
flag(propAssertion, 'lockSsfi', true);
|
|
853
|
-
|
|
854
|
-
if (!negate || props.length === 1) {
|
|
855
|
-
propAssertion.property(prop, val[prop]);
|
|
856
|
-
return;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
try {
|
|
860
|
-
propAssertion.property(prop, val[prop]);
|
|
861
|
-
} catch (err) {
|
|
862
|
-
if (!_.checkError.compatibleConstructor(err, AssertionError)) throw err;
|
|
863
|
-
if (firstErr === null) firstErr = err;
|
|
864
|
-
numErrs++;
|
|
865
|
-
}
|
|
866
|
-
}, this);
|
|
867
|
-
|
|
868
|
-
// When validating .not.include with multiple properties, we only want
|
|
869
|
-
// to throw an assertion error if all of the properties are included,
|
|
870
|
-
// in which case we throw the first property assertion error that we
|
|
871
|
-
// encountered.
|
|
872
|
-
if (negate && props.length > 1 && numErrs === props.length) throw firstErr;
|
|
835
|
+
, objType = _.type(obj).toLowerCase()
|
|
836
|
+
, flagMsg = flag(this, 'message')
|
|
837
|
+
, negate = flag(this, 'negate')
|
|
838
|
+
, ssfi = flag(this, 'ssfi')
|
|
839
|
+
, isDeep = flag(this, 'deep')
|
|
840
|
+
, descriptor = isDeep ? 'deep ' : '';
|
|
873
841
|
|
|
874
|
-
|
|
875
|
-
}
|
|
842
|
+
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
876
843
|
|
|
877
|
-
var
|
|
878
|
-
, descriptor = isDeep ? 'deep ' : ''
|
|
879
|
-
, included = false;
|
|
844
|
+
var included = false;
|
|
880
845
|
|
|
881
846
|
switch (objType) {
|
|
882
847
|
case 'string':
|
|
@@ -885,10 +850,6 @@ module.exports = function (chai, _) {
|
|
|
885
850
|
|
|
886
851
|
case 'weakset':
|
|
887
852
|
if (isDeep) {
|
|
888
|
-
var flagMsg = flag(this, 'message')
|
|
889
|
-
, ssfi = flag(this, 'ssfi');
|
|
890
|
-
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
891
|
-
|
|
892
853
|
throw new AssertionError(
|
|
893
854
|
flagMsg + 'unable to use .deep.include with WeakSet',
|
|
894
855
|
undefined,
|
|
@@ -925,6 +886,53 @@ module.exports = function (chai, _) {
|
|
|
925
886
|
included = obj.indexOf(val) !== -1;
|
|
926
887
|
}
|
|
927
888
|
break;
|
|
889
|
+
|
|
890
|
+
default:
|
|
891
|
+
// This block is for asserting a subset of properties in an object.
|
|
892
|
+
// `_.expectTypes` isn't used here because `.include` should work with
|
|
893
|
+
// objects with a custom `@@toStringTag`.
|
|
894
|
+
if (val !== Object(val)) {
|
|
895
|
+
throw new AssertionError(
|
|
896
|
+
flagMsg + 'object tested must be an array, a map, an object,'
|
|
897
|
+
+ ' a set, a string, or a weakset, but ' + objType + ' given',
|
|
898
|
+
undefined,
|
|
899
|
+
ssfi
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
var props = Object.keys(val)
|
|
904
|
+
, firstErr = null
|
|
905
|
+
, numErrs = 0;
|
|
906
|
+
|
|
907
|
+
props.forEach(function (prop) {
|
|
908
|
+
var propAssertion = new Assertion(obj);
|
|
909
|
+
_.transferFlags(this, propAssertion, true);
|
|
910
|
+
flag(propAssertion, 'lockSsfi', true);
|
|
911
|
+
|
|
912
|
+
if (!negate || props.length === 1) {
|
|
913
|
+
propAssertion.property(prop, val[prop]);
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
try {
|
|
918
|
+
propAssertion.property(prop, val[prop]);
|
|
919
|
+
} catch (err) {
|
|
920
|
+
if (!_.checkError.compatibleConstructor(err, AssertionError)) {
|
|
921
|
+
throw err;
|
|
922
|
+
}
|
|
923
|
+
if (firstErr === null) firstErr = err;
|
|
924
|
+
numErrs++;
|
|
925
|
+
}
|
|
926
|
+
}, this);
|
|
927
|
+
|
|
928
|
+
// When validating .not.include with multiple properties, we only want
|
|
929
|
+
// to throw an assertion error if all of the properties are included,
|
|
930
|
+
// in which case we throw the first property assertion error that we
|
|
931
|
+
// encountered.
|
|
932
|
+
if (negate && props.length > 1 && numErrs === props.length) {
|
|
933
|
+
throw firstErr;
|
|
934
|
+
}
|
|
935
|
+
return;
|
|
928
936
|
}
|
|
929
937
|
|
|
930
938
|
// Assert inclusion in collection or substring in a string.
|
|
@@ -1962,28 +1970,25 @@ module.exports = function (chai, _) {
|
|
|
1962
1970
|
var target = flag(this, 'object')
|
|
1963
1971
|
var ssfi = flag(this, 'ssfi');
|
|
1964
1972
|
var flagMsg = flag(this, 'message');
|
|
1965
|
-
var validInstanceOfTarget = constructor === Object(constructor) && (
|
|
1966
|
-
typeof constructor === 'function' ||
|
|
1967
|
-
(typeof Symbol !== 'undefined' &&
|
|
1968
|
-
typeof Symbol.hasInstance !== 'undefined' &&
|
|
1969
|
-
Symbol.hasInstance in constructor)
|
|
1970
|
-
);
|
|
1971
1973
|
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
flagMsg
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1974
|
+
try {
|
|
1975
|
+
var isInstanceOf = target instanceof constructor;
|
|
1976
|
+
} catch (err) {
|
|
1977
|
+
if (err instanceof TypeError) {
|
|
1978
|
+
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
1979
|
+
throw new AssertionError(
|
|
1980
|
+
flagMsg + 'The instanceof assertion needs a constructor but '
|
|
1981
|
+
+ _.type(constructor) + ' was given.',
|
|
1982
|
+
undefined,
|
|
1983
|
+
ssfi
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
throw err;
|
|
1980
1987
|
}
|
|
1981
1988
|
|
|
1982
|
-
var isInstanceOf = target instanceof constructor
|
|
1983
|
-
|
|
1984
1989
|
var name = _.getName(constructor);
|
|
1985
1990
|
if (name === null) {
|
|
1986
|
-
|
|
1991
|
+
name = 'an unnamed constructor';
|
|
1987
1992
|
}
|
|
1988
1993
|
|
|
1989
1994
|
this.assert(
|
|
@@ -5762,10 +5767,10 @@ module.exports = function (chai, util) {
|
|
|
5762
5767
|
* You can also provide a single object instead of a `keys` array and its keys
|
|
5763
5768
|
* will be used as the expected set of keys.
|
|
5764
5769
|
*
|
|
5765
|
-
* assert.
|
|
5766
|
-
* assert.
|
|
5767
|
-
* assert.
|
|
5768
|
-
* assert.
|
|
5770
|
+
* assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
|
|
5771
|
+
* assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
|
|
5772
|
+
* assert.hasAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
|
|
5773
|
+
* assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
|
|
5769
5774
|
*
|
|
5770
5775
|
* @name hasAnyKeys
|
|
5771
5776
|
* @param {Mixed} object
|
|
@@ -469,53 +469,18 @@ module.exports = function (chai, _) {
|
|
|
469
469
|
|
|
470
470
|
function include (val, msg) {
|
|
471
471
|
if (msg) flag(this, 'message', msg);
|
|
472
|
-
|
|
473
|
-
_.expectTypes(this, [
|
|
474
|
-
'array', 'object', 'string',
|
|
475
|
-
'map', 'set', 'weakset',
|
|
476
|
-
]);
|
|
477
|
-
|
|
472
|
+
|
|
478
473
|
var obj = flag(this, 'object')
|
|
479
|
-
, objType = _.type(obj).toLowerCase()
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
, firstErr = null
|
|
486
|
-
, numErrs = 0;
|
|
487
|
-
|
|
488
|
-
props.forEach(function (prop) {
|
|
489
|
-
var propAssertion = new Assertion(obj);
|
|
490
|
-
_.transferFlags(this, propAssertion, true);
|
|
491
|
-
flag(propAssertion, 'lockSsfi', true);
|
|
492
|
-
|
|
493
|
-
if (!negate || props.length === 1) {
|
|
494
|
-
propAssertion.property(prop, val[prop]);
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
try {
|
|
499
|
-
propAssertion.property(prop, val[prop]);
|
|
500
|
-
} catch (err) {
|
|
501
|
-
if (!_.checkError.compatibleConstructor(err, AssertionError)) throw err;
|
|
502
|
-
if (firstErr === null) firstErr = err;
|
|
503
|
-
numErrs++;
|
|
504
|
-
}
|
|
505
|
-
}, this);
|
|
506
|
-
|
|
507
|
-
// When validating .not.include with multiple properties, we only want
|
|
508
|
-
// to throw an assertion error if all of the properties are included,
|
|
509
|
-
// in which case we throw the first property assertion error that we
|
|
510
|
-
// encountered.
|
|
511
|
-
if (negate && props.length > 1 && numErrs === props.length) throw firstErr;
|
|
474
|
+
, objType = _.type(obj).toLowerCase()
|
|
475
|
+
, flagMsg = flag(this, 'message')
|
|
476
|
+
, negate = flag(this, 'negate')
|
|
477
|
+
, ssfi = flag(this, 'ssfi')
|
|
478
|
+
, isDeep = flag(this, 'deep')
|
|
479
|
+
, descriptor = isDeep ? 'deep ' : '';
|
|
512
480
|
|
|
513
|
-
|
|
514
|
-
}
|
|
481
|
+
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
515
482
|
|
|
516
|
-
var
|
|
517
|
-
, descriptor = isDeep ? 'deep ' : ''
|
|
518
|
-
, included = false;
|
|
483
|
+
var included = false;
|
|
519
484
|
|
|
520
485
|
switch (objType) {
|
|
521
486
|
case 'string':
|
|
@@ -524,10 +489,6 @@ module.exports = function (chai, _) {
|
|
|
524
489
|
|
|
525
490
|
case 'weakset':
|
|
526
491
|
if (isDeep) {
|
|
527
|
-
var flagMsg = flag(this, 'message')
|
|
528
|
-
, ssfi = flag(this, 'ssfi');
|
|
529
|
-
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
530
|
-
|
|
531
492
|
throw new AssertionError(
|
|
532
493
|
flagMsg + 'unable to use .deep.include with WeakSet',
|
|
533
494
|
undefined,
|
|
@@ -564,6 +525,53 @@ module.exports = function (chai, _) {
|
|
|
564
525
|
included = obj.indexOf(val) !== -1;
|
|
565
526
|
}
|
|
566
527
|
break;
|
|
528
|
+
|
|
529
|
+
default:
|
|
530
|
+
// This block is for asserting a subset of properties in an object.
|
|
531
|
+
// `_.expectTypes` isn't used here because `.include` should work with
|
|
532
|
+
// objects with a custom `@@toStringTag`.
|
|
533
|
+
if (val !== Object(val)) {
|
|
534
|
+
throw new AssertionError(
|
|
535
|
+
flagMsg + 'object tested must be an array, a map, an object,'
|
|
536
|
+
+ ' a set, a string, or a weakset, but ' + objType + ' given',
|
|
537
|
+
undefined,
|
|
538
|
+
ssfi
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
var props = Object.keys(val)
|
|
543
|
+
, firstErr = null
|
|
544
|
+
, numErrs = 0;
|
|
545
|
+
|
|
546
|
+
props.forEach(function (prop) {
|
|
547
|
+
var propAssertion = new Assertion(obj);
|
|
548
|
+
_.transferFlags(this, propAssertion, true);
|
|
549
|
+
flag(propAssertion, 'lockSsfi', true);
|
|
550
|
+
|
|
551
|
+
if (!negate || props.length === 1) {
|
|
552
|
+
propAssertion.property(prop, val[prop]);
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
try {
|
|
557
|
+
propAssertion.property(prop, val[prop]);
|
|
558
|
+
} catch (err) {
|
|
559
|
+
if (!_.checkError.compatibleConstructor(err, AssertionError)) {
|
|
560
|
+
throw err;
|
|
561
|
+
}
|
|
562
|
+
if (firstErr === null) firstErr = err;
|
|
563
|
+
numErrs++;
|
|
564
|
+
}
|
|
565
|
+
}, this);
|
|
566
|
+
|
|
567
|
+
// When validating .not.include with multiple properties, we only want
|
|
568
|
+
// to throw an assertion error if all of the properties are included,
|
|
569
|
+
// in which case we throw the first property assertion error that we
|
|
570
|
+
// encountered.
|
|
571
|
+
if (negate && props.length > 1 && numErrs === props.length) {
|
|
572
|
+
throw firstErr;
|
|
573
|
+
}
|
|
574
|
+
return;
|
|
567
575
|
}
|
|
568
576
|
|
|
569
577
|
// Assert inclusion in collection or substring in a string.
|
|
@@ -1601,28 +1609,25 @@ module.exports = function (chai, _) {
|
|
|
1601
1609
|
var target = flag(this, 'object')
|
|
1602
1610
|
var ssfi = flag(this, 'ssfi');
|
|
1603
1611
|
var flagMsg = flag(this, 'message');
|
|
1604
|
-
var validInstanceOfTarget = constructor === Object(constructor) && (
|
|
1605
|
-
typeof constructor === 'function' ||
|
|
1606
|
-
(typeof Symbol !== 'undefined' &&
|
|
1607
|
-
typeof Symbol.hasInstance !== 'undefined' &&
|
|
1608
|
-
Symbol.hasInstance in constructor)
|
|
1609
|
-
);
|
|
1610
1612
|
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
flagMsg
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1613
|
+
try {
|
|
1614
|
+
var isInstanceOf = target instanceof constructor;
|
|
1615
|
+
} catch (err) {
|
|
1616
|
+
if (err instanceof TypeError) {
|
|
1617
|
+
flagMsg = flagMsg ? flagMsg + ': ' : '';
|
|
1618
|
+
throw new AssertionError(
|
|
1619
|
+
flagMsg + 'The instanceof assertion needs a constructor but '
|
|
1620
|
+
+ _.type(constructor) + ' was given.',
|
|
1621
|
+
undefined,
|
|
1622
|
+
ssfi
|
|
1623
|
+
);
|
|
1624
|
+
}
|
|
1625
|
+
throw err;
|
|
1619
1626
|
}
|
|
1620
1627
|
|
|
1621
|
-
var isInstanceOf = target instanceof constructor
|
|
1622
|
-
|
|
1623
1628
|
var name = _.getName(constructor);
|
|
1624
1629
|
if (name === null) {
|
|
1625
|
-
|
|
1630
|
+
name = 'an unnamed constructor';
|
|
1626
1631
|
}
|
|
1627
1632
|
|
|
1628
1633
|
this.assert(
|
|
@@ -1675,10 +1675,10 @@ module.exports = function (chai, util) {
|
|
|
1675
1675
|
* You can also provide a single object instead of a `keys` array and its keys
|
|
1676
1676
|
* will be used as the expected set of keys.
|
|
1677
1677
|
*
|
|
1678
|
-
* assert.
|
|
1679
|
-
* assert.
|
|
1680
|
-
* assert.
|
|
1681
|
-
* assert.
|
|
1678
|
+
* assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
|
|
1679
|
+
* assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
|
|
1680
|
+
* assert.hasAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
|
|
1681
|
+
* assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
|
|
1682
1682
|
*
|
|
1683
1683
|
* @name hasAnyKeys
|
|
1684
1684
|
* @param {Mixed} object
|
package/lib/chai.js
CHANGED