chai 5.0.3 → 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.
- package/chai.js +26 -178
- package/lib/chai/assertion.js +2 -3
- package/lib/chai/core/assertions.js +38 -4
- package/lib/chai/interface/assert.js +250 -355
- package/lib/chai/interface/expect.js +5 -5
- package/lib/chai/interface/should.js +13 -20
- package/lib/chai/utils/addChainableMethod.js +1 -5
- package/lib/chai/utils/compareByInspect.js +0 -4
- package/lib/chai/utils/getMessage.js +0 -4
- package/lib/chai/utils/getOwnEnumerableProperties.js +0 -4
- package/lib/chai/utils/index.js +28 -111
- package/lib/chai/utils/objDisplay.js +0 -4
- package/lib/chai/utils/test.js +0 -4
- package/lib/chai.js +7 -29
- package/package.json +1 -1
package/chai.js
CHANGED
|
@@ -2810,7 +2810,9 @@ function closeTo(expected, delta, msg) {
|
|
|
2810
2810
|
__name(closeTo, "closeTo");
|
|
2811
2811
|
Assertion.addMethod("closeTo", closeTo);
|
|
2812
2812
|
Assertion.addMethod("approximately", closeTo);
|
|
2813
|
-
function isSubsetOf(
|
|
2813
|
+
function isSubsetOf(_subset, _superset, cmp, contains, ordered) {
|
|
2814
|
+
let superset = Array.from(_superset);
|
|
2815
|
+
let subset = Array.from(_subset);
|
|
2814
2816
|
if (!contains) {
|
|
2815
2817
|
if (subset.length !== superset.length)
|
|
2816
2818
|
return false;
|
|
@@ -2841,8 +2843,8 @@ Assertion.addMethod("members", function(subset, msg) {
|
|
|
2841
2843
|
if (msg)
|
|
2842
2844
|
flag2(this, "message", msg);
|
|
2843
2845
|
var obj = flag2(this, "object"), flagMsg = flag2(this, "message"), ssfi = flag2(this, "ssfi");
|
|
2844
|
-
new Assertion(obj, flagMsg, ssfi, true).to.be.
|
|
2845
|
-
new Assertion(subset, flagMsg, ssfi, true).to.be.
|
|
2846
|
+
new Assertion(obj, flagMsg, ssfi, true).to.be.iterable;
|
|
2847
|
+
new Assertion(subset, flagMsg, ssfi, true).to.be.iterable;
|
|
2846
2848
|
var contains = flag2(this, "contains");
|
|
2847
2849
|
var ordered = flag2(this, "ordered");
|
|
2848
2850
|
var subject, failMsg, failNegateMsg;
|
|
@@ -2865,6 +2867,17 @@ Assertion.addMethod("members", function(subset, msg) {
|
|
|
2865
2867
|
true
|
|
2866
2868
|
);
|
|
2867
2869
|
});
|
|
2870
|
+
Assertion.addProperty("iterable", function(msg) {
|
|
2871
|
+
if (msg)
|
|
2872
|
+
flag2(this, "message", msg);
|
|
2873
|
+
var obj = flag2(this, "object");
|
|
2874
|
+
this.assert(
|
|
2875
|
+
obj != void 0 && obj[Symbol.iterator],
|
|
2876
|
+
"expected #{this} to be an iterable",
|
|
2877
|
+
"expected #{this} to not be an iterable",
|
|
2878
|
+
obj
|
|
2879
|
+
);
|
|
2880
|
+
});
|
|
2868
2881
|
function oneOf(list, msg) {
|
|
2869
2882
|
if (msg)
|
|
2870
2883
|
flag2(this, "message", msg);
|
|
@@ -3544,6 +3557,16 @@ assert.notIncludeDeepOrderedMembers = function(superset, subset, msg) {
|
|
|
3544
3557
|
assert.oneOf = function(inList, list, msg) {
|
|
3545
3558
|
new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list);
|
|
3546
3559
|
};
|
|
3560
|
+
assert.isIterable = function(obj, msg) {
|
|
3561
|
+
if (obj == void 0 || !obj[Symbol.iterator]) {
|
|
3562
|
+
msg = msg ? `${msg} expected ${inspect2(obj)} to be an iterable` : `expected ${inspect2(obj)} to be an iterable`;
|
|
3563
|
+
throw new AssertionError(
|
|
3564
|
+
msg,
|
|
3565
|
+
void 0,
|
|
3566
|
+
assert.isIterable
|
|
3567
|
+
);
|
|
3568
|
+
}
|
|
3569
|
+
};
|
|
3547
3570
|
assert.changes = function(fn, obj, prop, msg) {
|
|
3548
3571
|
if (arguments.length === 3 && typeof obj === "function") {
|
|
3549
3572
|
msg = prop;
|
|
@@ -3737,9 +3760,6 @@ export {
|
|
|
3737
3760
|
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
|
|
3738
3761
|
* MIT Licensed
|
|
3739
3762
|
*/
|
|
3740
|
-
/*!
|
|
3741
|
-
* Module dependencies
|
|
3742
|
-
*/
|
|
3743
3763
|
/*!
|
|
3744
3764
|
* Chai - expectTypes utility
|
|
3745
3765
|
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
|
|
@@ -3766,52 +3786,6 @@ export {
|
|
|
3766
3786
|
* Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
|
|
3767
3787
|
* MIT Licensed
|
|
3768
3788
|
*/
|
|
3769
|
-
/*!
|
|
3770
|
-
* Assertion Constructor
|
|
3771
|
-
*
|
|
3772
|
-
* Creates object for chaining.
|
|
3773
|
-
*
|
|
3774
|
-
* `Assertion` objects contain metadata in the form of flags. Three flags can
|
|
3775
|
-
* be assigned during instantiation by passing arguments to this constructor:
|
|
3776
|
-
*
|
|
3777
|
-
* - `object`: This flag contains the target of the assertion. For example, in
|
|
3778
|
-
* the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
|
|
3779
|
-
* contain `numKittens` so that the `equal` assertion can reference it when
|
|
3780
|
-
* needed.
|
|
3781
|
-
*
|
|
3782
|
-
* - `message`: This flag contains an optional custom error message to be
|
|
3783
|
-
* prepended to the error message that's generated by the assertion when it
|
|
3784
|
-
* fails.
|
|
3785
|
-
*
|
|
3786
|
-
* - `ssfi`: This flag stands for "start stack function indicator". It
|
|
3787
|
-
* contains a function reference that serves as the starting point for
|
|
3788
|
-
* removing frames from the stack trace of the error that's created by the
|
|
3789
|
-
* assertion when it fails. The goal is to provide a cleaner stack trace to
|
|
3790
|
-
* end users by removing Chai's internal functions. Note that it only works
|
|
3791
|
-
* in environments that support `Error.captureStackTrace`, and only when
|
|
3792
|
-
* `Chai.config.includeStack` hasn't been set to `false`.
|
|
3793
|
-
*
|
|
3794
|
-
* - `lockSsfi`: This flag controls whether or not the given `ssfi` flag
|
|
3795
|
-
* should retain its current value, even as assertions are chained off of
|
|
3796
|
-
* this object. This is usually set to `true` when creating a new assertion
|
|
3797
|
-
* from within another assertion. It's also temporarily set to `true` before
|
|
3798
|
-
* an overwritten assertion gets called by the overwriting assertion.
|
|
3799
|
-
*
|
|
3800
|
-
* - `eql`: This flag contains the deepEqual function to be used by the assertion.
|
|
3801
|
-
*
|
|
3802
|
-
* @param {Mixed} obj target of the assertion
|
|
3803
|
-
* @param {String} msg (optional) custom error message
|
|
3804
|
-
* @param {Function} ssfi (optional) starting point for removing stack frames
|
|
3805
|
-
* @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
|
|
3806
|
-
* @api private
|
|
3807
|
-
*/
|
|
3808
|
-
/*!
|
|
3809
|
-
* ### ._obj
|
|
3810
|
-
*
|
|
3811
|
-
* Quick reference to stored `actual` value for plugin developers.
|
|
3812
|
-
*
|
|
3813
|
-
* @api private
|
|
3814
|
-
*/
|
|
3815
3789
|
/*!
|
|
3816
3790
|
* Chai - isProxyEnabled helper
|
|
3817
3791
|
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
|
|
@@ -3857,9 +3831,6 @@ export {
|
|
|
3857
3831
|
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
|
|
3858
3832
|
* MIT Licensed
|
|
3859
3833
|
*/
|
|
3860
|
-
/*!
|
|
3861
|
-
* Module variables
|
|
3862
|
-
*/
|
|
3863
3834
|
/*!
|
|
3864
3835
|
* Chai - overwriteChainableMethod utility
|
|
3865
3836
|
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
|
|
@@ -3890,134 +3861,11 @@ export {
|
|
|
3890
3861
|
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
|
3891
3862
|
* MIT Licensed
|
|
3892
3863
|
*/
|
|
3893
|
-
/*!
|
|
3894
|
-
* Dependencies that are used for multiple exports are required here only once
|
|
3895
|
-
*/
|
|
3896
|
-
/*!
|
|
3897
|
-
* test utility
|
|
3898
|
-
*/
|
|
3899
|
-
/*!
|
|
3900
|
-
* type utility
|
|
3901
|
-
*/
|
|
3902
|
-
/*!
|
|
3903
|
-
* expectTypes utility
|
|
3904
|
-
*/
|
|
3905
|
-
/*!
|
|
3906
|
-
* message utility
|
|
3907
|
-
*/
|
|
3908
|
-
/*!
|
|
3909
|
-
* actual utility
|
|
3910
|
-
*/
|
|
3911
|
-
/*!
|
|
3912
|
-
* Inspect util
|
|
3913
|
-
*/
|
|
3914
|
-
/*!
|
|
3915
|
-
* Object Display util
|
|
3916
|
-
*/
|
|
3917
|
-
/*!
|
|
3918
|
-
* Flag utility
|
|
3919
|
-
*/
|
|
3920
|
-
/*!
|
|
3921
|
-
* Flag transferring utility
|
|
3922
|
-
*/
|
|
3923
|
-
/*!
|
|
3924
|
-
* Deep equal utility
|
|
3925
|
-
*/
|
|
3926
|
-
/*!
|
|
3927
|
-
* Deep path info
|
|
3928
|
-
*/
|
|
3929
|
-
/*!
|
|
3930
|
-
* Function name
|
|
3931
|
-
*/
|
|
3932
|
-
/*!
|
|
3933
|
-
* add Property
|
|
3934
|
-
*/
|
|
3935
|
-
/*!
|
|
3936
|
-
* add Method
|
|
3937
|
-
*/
|
|
3938
|
-
/*!
|
|
3939
|
-
* overwrite Property
|
|
3940
|
-
*/
|
|
3941
|
-
/*!
|
|
3942
|
-
* overwrite Method
|
|
3943
|
-
*/
|
|
3944
|
-
/*!
|
|
3945
|
-
* Add a chainable method
|
|
3946
|
-
*/
|
|
3947
|
-
/*!
|
|
3948
|
-
* Overwrite chainable method
|
|
3949
|
-
*/
|
|
3950
|
-
/*!
|
|
3951
|
-
* Compare by inspect method
|
|
3952
|
-
*/
|
|
3953
|
-
/*!
|
|
3954
|
-
* Get own enumerable property symbols method
|
|
3955
|
-
*/
|
|
3956
|
-
/*!
|
|
3957
|
-
* Get own enumerable properties method
|
|
3958
|
-
*/
|
|
3959
|
-
/*!
|
|
3960
|
-
* Checks error against a given set of criteria
|
|
3961
|
-
*/
|
|
3962
|
-
/*!
|
|
3963
|
-
* Proxify util
|
|
3964
|
-
*/
|
|
3965
|
-
/*!
|
|
3966
|
-
* addLengthGuard util
|
|
3967
|
-
*/
|
|
3968
|
-
/*!
|
|
3969
|
-
* isProxyEnabled helper
|
|
3970
|
-
*/
|
|
3971
|
-
/*!
|
|
3972
|
-
* isNaN method
|
|
3973
|
-
*/
|
|
3974
|
-
/*!
|
|
3975
|
-
* getOperator method
|
|
3976
|
-
*/
|
|
3977
3864
|
/*!
|
|
3978
3865
|
* chai
|
|
3979
3866
|
* Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
|
|
3980
3867
|
* MIT Licensed
|
|
3981
3868
|
*/
|
|
3982
|
-
/*!
|
|
3983
|
-
* ### .ifError(object)
|
|
3984
|
-
*
|
|
3985
|
-
* Asserts if value is not a false value, and throws if it is a true value.
|
|
3986
|
-
* This is added to allow for chai to be a drop-in replacement for Node's
|
|
3987
|
-
* assert class.
|
|
3988
|
-
*
|
|
3989
|
-
* var err = new Error('I am a custom error');
|
|
3990
|
-
* assert.ifError(err); // Rethrows err!
|
|
3991
|
-
*
|
|
3992
|
-
* @name ifError
|
|
3993
|
-
* @param {Object} object
|
|
3994
|
-
* @namespace Assert
|
|
3995
|
-
* @api public
|
|
3996
|
-
*/
|
|
3997
|
-
/*!
|
|
3998
|
-
* Aliases.
|
|
3999
|
-
*/
|
|
4000
|
-
/*!
|
|
4001
|
-
* Assertion Error
|
|
4002
|
-
*/
|
|
4003
|
-
/*!
|
|
4004
|
-
* Utility Functions
|
|
4005
|
-
*/
|
|
4006
|
-
/*!
|
|
4007
|
-
* Configuration
|
|
4008
|
-
*/
|
|
4009
|
-
/*!
|
|
4010
|
-
* Primary `Assertion` prototype
|
|
4011
|
-
*/
|
|
4012
|
-
/*!
|
|
4013
|
-
* Expect interface
|
|
4014
|
-
*/
|
|
4015
|
-
/*!
|
|
4016
|
-
* Should interface
|
|
4017
|
-
*/
|
|
4018
|
-
/*!
|
|
4019
|
-
* Assert interface
|
|
4020
|
-
*/
|
|
4021
3869
|
/*! Bundled license information:
|
|
4022
3870
|
|
|
4023
3871
|
deep-eql/index.js:
|
package/lib/chai/assertion.js
CHANGED
|
@@ -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(
|
|
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.
|
|
3144
|
-
new Assertion(subset, flagMsg, ssfi, true).to.be.
|
|
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
|
*
|