chai 1.9.0 → 1.9.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/CONTRIBUTING.md +3 -3
- package/History.md +24 -0
- package/README.md +22 -9
- package/ReleaseNotes.md +84 -0
- package/bower.json +1 -1
- package/chai.js +160 -74
- package/lib/chai/assertion.js +24 -28
- package/lib/chai/config.js +50 -0
- package/lib/chai/core/assertions.js +27 -10
- package/lib/chai/interface/assert.js +7 -7
- package/lib/chai/interface/should.js +26 -24
- package/lib/chai/utils/addChainableMethod.js +6 -1
- package/lib/chai/utils/addMethod.js +6 -0
- package/lib/chai/utils/getActual.js +1 -2
- package/lib/chai/utils/objDisplay.js +2 -1
- package/lib/chai.js +8 -1
- package/package.json +5 -5
package/CONTRIBUTING.md
CHANGED
|
@@ -31,7 +31,7 @@ Following these guidelines helps to communicate that you respect the time of the
|
|
|
31
31
|
## Contributing
|
|
32
32
|
|
|
33
33
|
The issue tracker is the preferred channel for [bug reports](#bugs),
|
|
34
|
-
[
|
|
34
|
+
[feature requests](#features) and [submitting pull
|
|
35
35
|
requests](#pull-requests), but please respect the following restrictions:
|
|
36
36
|
|
|
37
37
|
* Please **do not** use the issue tracker for personal support requests (use
|
|
@@ -75,7 +75,7 @@ Example:
|
|
|
75
75
|
|
|
76
76
|
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to *you* to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible.
|
|
77
77
|
|
|
78
|
-
Furthermore, since Chai.js has a [robust plugin API](http://chaijs.com/guide/plugins/), we encourage you to publish **new Assertions** as plugins. If your feature is an enhancement to an **existing Assertion**, please propose your changes as an issue prior to opening a pull request. If the core Chai.js contributors feel your plugin would be better suited as a core assertion, they will invite you to open a PR in [chaijs/chai](https
|
|
78
|
+
Furthermore, since Chai.js has a [robust plugin API](http://chaijs.com/guide/plugins/), we encourage you to publish **new Assertions** as plugins. If your feature is an enhancement to an **existing Assertion**, please propose your changes as an issue prior to opening a pull request. If the core Chai.js contributors feel your plugin would be better suited as a core assertion, they will invite you to open a PR in [chaijs/chai](https://github.com/chaijs/chai).
|
|
79
79
|
|
|
80
80
|
<a name="pull-requests"></a>
|
|
81
81
|
### Pull Requests
|
|
@@ -90,7 +90,7 @@ Good pull requests - patches, improvements, new features - are a fantastic help.
|
|
|
90
90
|
|
|
91
91
|
**Please ask first** before embarking on any significant pull request (e.g. implementing features, refactoring code), otherwise you risk spending a lot of time working on something that the project's developers might not want to merge into the project.
|
|
92
92
|
|
|
93
|
-
Please adhere to the coding conventions used throughout a project (indentation, accurate comments, etc.) and any other requirements (such as test coverage). Please review the [Chai.js
|
|
93
|
+
Please adhere to the coding conventions used throughout a project (indentation, accurate comments, etc.) and any other requirements (such as test coverage). Please review the [Chai.js Coding Style Guide](https://github.com/chaijs/chai/wiki/Chai-Coding-Style-Guide).
|
|
94
94
|
|
|
95
95
|
Follow this process if you'd like your work considered for inclusion in the project:
|
|
96
96
|
|
package/History.md
CHANGED
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
|
|
2
|
+
1.9.1 / 2014-03-19
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* deps update
|
|
6
|
+
* util: [getActual] select actual logic now allows undefined for actual. Closes #183
|
|
7
|
+
* docs: [config] make public, express param type
|
|
8
|
+
* Merge pull request #251 from romario333/threshold3
|
|
9
|
+
* Fix issue #166 - configurable threshold in objDisplay.
|
|
10
|
+
* Move configuration options to config.js.
|
|
11
|
+
* Merge pull request #233 from Empeeric/master
|
|
12
|
+
* Merge pull request #244 from leider/fix_for_contains
|
|
13
|
+
* Merge pull request #247 from didoarellano/typo-fixes
|
|
14
|
+
* Fix typos
|
|
15
|
+
* Merge pull request #245 from lfac-pt/patch-1
|
|
16
|
+
* Update `exports.version` to 1.9.0
|
|
17
|
+
* aborting loop on finding
|
|
18
|
+
* declaring variable only once
|
|
19
|
+
* additional test finds incomplete implementation
|
|
20
|
+
* simplified code
|
|
21
|
+
* fixing #239 (without changing chai.js)
|
|
22
|
+
* ssfi as it should be
|
|
23
|
+
* Merge pull request #228 from duncanbeevers/deep_members
|
|
24
|
+
* Deep equality check for collection membership
|
|
25
|
+
|
|
2
26
|
1.9.0 / 2014-01-29
|
|
3
27
|
==================
|
|
4
28
|
|
package/README.md
CHANGED
|
@@ -9,6 +9,14 @@ For more information or to download plugins, view the [documentation](http://cha
|
|
|
9
9
|
|
|
10
10
|
[](https://saucelabs.com/u/chaijs)
|
|
11
11
|
|
|
12
|
+
### Plugins
|
|
13
|
+
|
|
14
|
+
Chai offers a robust Plugin architecture for extending Chai's assertions and interfaces.
|
|
15
|
+
|
|
16
|
+
- Need a plugin? View the [official plugin list](http://chaijs.com/plugins).
|
|
17
|
+
- Have a plugin and want it listed? Open a Pull Request at [chaijs/chai-docs:plugin.js](https://github.com/chaijs/chai-docs/blob/master/plugins.js#L1-L12).
|
|
18
|
+
- Want to build a plugin? Read the [plugin api documentation](http://chaijs.com/guide/plugins/).
|
|
19
|
+
|
|
12
20
|
### Related Projects
|
|
13
21
|
|
|
14
22
|
- [chaijs / assertion-error](https://github.com/chaijs/assertion-error): Custom `Error` constructor thrown upon an assertion failing.
|
|
@@ -17,31 +25,34 @@ For more information or to download plugins, view the [documentation](http://cha
|
|
|
17
25
|
### Contributors
|
|
18
26
|
|
|
19
27
|
project : chai
|
|
20
|
-
repo age : 2 years,
|
|
21
|
-
commits :
|
|
22
|
-
active :
|
|
23
|
-
files :
|
|
28
|
+
repo age : 2 years, 3 months ago
|
|
29
|
+
commits : 756
|
|
30
|
+
active : 170 days
|
|
31
|
+
files : 57
|
|
24
32
|
authors :
|
|
25
|
-
|
|
26
|
-
79 Veselin Todorov 10.
|
|
27
|
-
43 Domenic Denicola 5.
|
|
33
|
+
540 Jake Luer 71.4%
|
|
34
|
+
79 Veselin Todorov 10.4%
|
|
35
|
+
43 Domenic Denicola 5.7%
|
|
28
36
|
6 Ruben Verborgh 0.8%
|
|
29
37
|
5 George Kats 0.7%
|
|
30
38
|
5 Jo Liss 0.7%
|
|
31
39
|
5 Juliusz Gonera 0.7%
|
|
32
40
|
5 Scott Nonnenberg 0.7%
|
|
41
|
+
5 leider 0.7%
|
|
33
42
|
4 John Firebaugh 0.5%
|
|
34
43
|
4 Max Edmands 0.5%
|
|
35
44
|
4 Nick Heiner 0.5%
|
|
36
45
|
4 josher19 0.5%
|
|
37
46
|
3 Andrei Neculau 0.4%
|
|
47
|
+
3 Duncan Beevers 0.4%
|
|
38
48
|
3 Jake Rosoman 0.4%
|
|
39
49
|
3 Jeff Barczewski 0.4%
|
|
40
50
|
3 Ryunosuke SATO 0.4%
|
|
51
|
+
3 Veselin 0.4%
|
|
41
52
|
2 Bartvds 0.3%
|
|
42
|
-
2 Duncan Beevers 0.3%
|
|
43
53
|
2 Edwin Shao 0.3%
|
|
44
54
|
2 Jakub Nešetřil 0.3%
|
|
55
|
+
2 Roman Masek 0.3%
|
|
45
56
|
2 Teddy Cross 0.3%
|
|
46
57
|
1 Anand Patil 0.1%
|
|
47
58
|
1 Benjamin Horsleben 0.1%
|
|
@@ -49,12 +60,14 @@ For more information or to download plugins, view the [documentation](http://cha
|
|
|
49
60
|
1 Chris Connelly 0.1%
|
|
50
61
|
1 Chun-Yi 0.1%
|
|
51
62
|
1 DD 0.1%
|
|
63
|
+
1 Dido Arellano 0.1%
|
|
52
64
|
1 Jeff Welch 0.1%
|
|
53
65
|
1 Kilian Ciuffolo 0.1%
|
|
66
|
+
1 Luís Cardoso 0.1%
|
|
54
67
|
1 Niklas Närhinen 0.1%
|
|
55
68
|
1 Paul Miller 0.1%
|
|
69
|
+
1 Refael Ackermann 0.1%
|
|
56
70
|
1 Sasha Koss 0.1%
|
|
57
|
-
1 Veselin 0.1%
|
|
58
71
|
1 Victor Costan 0.1%
|
|
59
72
|
1 Vinay Pulim 0.1%
|
|
60
73
|
1 Virginie BARDALES 0.1%
|
package/ReleaseNotes.md
CHANGED
|
@@ -1,5 +1,89 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## 1.9.1 / 2014-03-19
|
|
4
|
+
|
|
5
|
+
The following changes are required if you are upgrading from the previous version:
|
|
6
|
+
|
|
7
|
+
- **Users:**
|
|
8
|
+
- Migrate configuration options to new interface. (see notes)
|
|
9
|
+
- **Plugin Developers:**
|
|
10
|
+
- No changes required
|
|
11
|
+
- **Core Contributors:**
|
|
12
|
+
- Refresh `node_modules` folder for updated dependencies.
|
|
13
|
+
|
|
14
|
+
### Configuration
|
|
15
|
+
|
|
16
|
+
There have been requests for changes and additions to the configuration mechanisms
|
|
17
|
+
and their impact in the Chai architecture. As such, we have decoupled the
|
|
18
|
+
configuration from the `Assertion` constructor. This not only allows for centralized
|
|
19
|
+
configuration, but will allow us to shift the responsibility from the `Assertion`
|
|
20
|
+
constructor to the `assert` interface in future releases.
|
|
21
|
+
|
|
22
|
+
These changes have been implemented in a non-breaking way, but a depretiation
|
|
23
|
+
warning will be presented to users until they migrate. The old config method will
|
|
24
|
+
be removed in either `v1.11.0` or `v2.0.0`, whichever comes first.
|
|
25
|
+
|
|
26
|
+
#### Quick Migration
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// change this:
|
|
30
|
+
chai.Assertion.includeStack = true;
|
|
31
|
+
chai.Assertion.showDiff = false;
|
|
32
|
+
|
|
33
|
+
// ... to this:
|
|
34
|
+
chai.config.includeStack = true;
|
|
35
|
+
chai.config.showDiff = false;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
#### All Config Options
|
|
39
|
+
|
|
40
|
+
##### config.includeStack
|
|
41
|
+
|
|
42
|
+
- **@param** _{Boolean}_
|
|
43
|
+
- **@default** `false`
|
|
44
|
+
|
|
45
|
+
User configurable property, influences whether stack trace is included in
|
|
46
|
+
Assertion error message. Default of `false` suppresses stack trace in the error
|
|
47
|
+
message.
|
|
48
|
+
|
|
49
|
+
##### config.showDiff
|
|
50
|
+
|
|
51
|
+
- **@param** _{Boolean}_
|
|
52
|
+
- **@default** `true`
|
|
53
|
+
|
|
54
|
+
User configurable property, influences whether or not the `showDiff` flag
|
|
55
|
+
should be included in the thrown AssertionErrors. `false` will always be `false`;
|
|
56
|
+
`true` will be true when the assertion has requested a diff be shown.
|
|
57
|
+
|
|
58
|
+
##### config.truncateThreshold **(NEW)**
|
|
59
|
+
|
|
60
|
+
- **@param** _{Number}_
|
|
61
|
+
- **@default** `40`
|
|
62
|
+
|
|
63
|
+
User configurable property, sets length threshold for actual and expected values
|
|
64
|
+
in assertion errors. If this threshold is exceeded, the value is truncated.
|
|
65
|
+
|
|
66
|
+
Set it to zero if you want to disable truncating altogether.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
chai.config.truncateThreshold = 0; // disable truncating
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Community Contributions
|
|
73
|
+
|
|
74
|
+
- [#228](https://github.com/chaijs/chai/pull/228) Deep equality check for memebers. [@duncanbeevers](https://github.com/duncanbeevers)
|
|
75
|
+
- [#247](https://github.com/chaijs/chai/pull/247) Proofreading. [@didorellano](https://github.com/didoarellano)
|
|
76
|
+
- [#244](https://github.com/chaijs/chai/pull/244) Fix `contain`/`include` 1.9.0 regression. [@leider](https://github.com/leider)
|
|
77
|
+
- [#233](https://github.com/chaijs/chai/pull/233) Improvements to `ssfi` for `assert` interface. [@refack](https://github.com/refack)
|
|
78
|
+
- [#251](https://github.com/chaijs/chai/pull/251) New config option: object display threshold. [@romario333](https://github.com/romario333)
|
|
79
|
+
|
|
80
|
+
Thank you to all who took time to contribute!
|
|
81
|
+
|
|
82
|
+
### Other Bug Fixes
|
|
83
|
+
|
|
84
|
+
- [#183](https://github.com/chaijs/chai/issues/183) Allow `undefined` for actual. (internal api)
|
|
85
|
+
- Update Karam(+plugins)/Istanbul to most recent versions.
|
|
86
|
+
|
|
3
87
|
## 1.9.0 / 2014-01-29
|
|
4
88
|
|
|
5
89
|
The following changes are required if you are upgrading from the previous version:
|
package/bower.json
CHANGED
package/chai.js
CHANGED
|
@@ -736,7 +736,7 @@ var used = []
|
|
|
736
736
|
* Chai version
|
|
737
737
|
*/
|
|
738
738
|
|
|
739
|
-
exports.version = '1.
|
|
739
|
+
exports.version = '1.9.1';
|
|
740
740
|
|
|
741
741
|
/*!
|
|
742
742
|
* Assertion Error
|
|
@@ -769,6 +769,13 @@ exports.use = function (fn) {
|
|
|
769
769
|
return this;
|
|
770
770
|
};
|
|
771
771
|
|
|
772
|
+
/*!
|
|
773
|
+
* Configuration
|
|
774
|
+
*/
|
|
775
|
+
|
|
776
|
+
var config = require('./chai/config');
|
|
777
|
+
exports.config = config;
|
|
778
|
+
|
|
772
779
|
/*!
|
|
773
780
|
* Primary `Assertion` prototype
|
|
774
781
|
*/
|
|
@@ -813,6 +820,8 @@ require.register("chai/lib/chai/assertion.js", function(exports, require, module
|
|
|
813
820
|
* MIT Licensed
|
|
814
821
|
*/
|
|
815
822
|
|
|
823
|
+
var config = require('./config');
|
|
824
|
+
|
|
816
825
|
module.exports = function (_chai, util) {
|
|
817
826
|
/*!
|
|
818
827
|
* Module dependencies.
|
|
@@ -841,33 +850,27 @@ module.exports = function (_chai, util) {
|
|
|
841
850
|
flag(this, 'message', msg);
|
|
842
851
|
}
|
|
843
852
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
*/
|
|
855
|
-
|
|
856
|
-
Assertion.includeStack = false;
|
|
857
|
-
|
|
858
|
-
/*!
|
|
859
|
-
* ### Assertion.showDiff
|
|
860
|
-
*
|
|
861
|
-
* User configurable property, influences whether or not
|
|
862
|
-
* the `showDiff` flag should be included in the thrown
|
|
863
|
-
* AssertionErrors. `false` will always be `false`; `true`
|
|
864
|
-
* will be true when the assertion has requested a diff
|
|
865
|
-
* be shown.
|
|
866
|
-
*
|
|
867
|
-
* @api public
|
|
868
|
-
*/
|
|
853
|
+
Object.defineProperty(Assertion, 'includeStack', {
|
|
854
|
+
get: function() {
|
|
855
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
856
|
+
return config.includeStack;
|
|
857
|
+
},
|
|
858
|
+
set: function(value) {
|
|
859
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
860
|
+
config.includeStack = value;
|
|
861
|
+
}
|
|
862
|
+
});
|
|
869
863
|
|
|
870
|
-
Assertion
|
|
864
|
+
Object.defineProperty(Assertion, 'showDiff', {
|
|
865
|
+
get: function() {
|
|
866
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
867
|
+
return config.showDiff;
|
|
868
|
+
},
|
|
869
|
+
set: function(value) {
|
|
870
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
871
|
+
config.showDiff = value;
|
|
872
|
+
}
|
|
873
|
+
});
|
|
871
874
|
|
|
872
875
|
Assertion.addProperty = function (name, fn) {
|
|
873
876
|
util.addProperty(this.prototype, name, fn);
|
|
@@ -910,7 +913,7 @@ module.exports = function (_chai, util) {
|
|
|
910
913
|
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
|
|
911
914
|
var ok = util.test(this, arguments);
|
|
912
915
|
if (true !== showDiff) showDiff = false;
|
|
913
|
-
if (true !==
|
|
916
|
+
if (true !== config.showDiff) showDiff = false;
|
|
914
917
|
|
|
915
918
|
if (!ok) {
|
|
916
919
|
var msg = util.getMessage(this, arguments)
|
|
@@ -919,7 +922,7 @@ module.exports = function (_chai, util) {
|
|
|
919
922
|
actual: actual
|
|
920
923
|
, expected: expected
|
|
921
924
|
, showDiff: showDiff
|
|
922
|
-
}, (
|
|
925
|
+
}, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
|
|
923
926
|
}
|
|
924
927
|
};
|
|
925
928
|
|
|
@@ -941,6 +944,59 @@ module.exports = function (_chai, util) {
|
|
|
941
944
|
});
|
|
942
945
|
};
|
|
943
946
|
|
|
947
|
+
});
|
|
948
|
+
require.register("chai/lib/chai/config.js", function(exports, require, module){
|
|
949
|
+
module.exports = {
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* ### config.includeStack
|
|
953
|
+
*
|
|
954
|
+
* User configurable property, influences whether stack trace
|
|
955
|
+
* is included in Assertion error message. Default of false
|
|
956
|
+
* suppresses stack trace in the error message.
|
|
957
|
+
*
|
|
958
|
+
* chai.config.includeStack = true; // enable stack on error
|
|
959
|
+
*
|
|
960
|
+
* @param {Boolean}
|
|
961
|
+
* @api public
|
|
962
|
+
*/
|
|
963
|
+
|
|
964
|
+
includeStack: false,
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* ### config.showDiff
|
|
968
|
+
*
|
|
969
|
+
* User configurable property, influences whether or not
|
|
970
|
+
* the `showDiff` flag should be included in the thrown
|
|
971
|
+
* AssertionErrors. `false` will always be `false`; `true`
|
|
972
|
+
* will be true when the assertion has requested a diff
|
|
973
|
+
* be shown.
|
|
974
|
+
*
|
|
975
|
+
* @param {Boolean}
|
|
976
|
+
* @api public
|
|
977
|
+
*/
|
|
978
|
+
|
|
979
|
+
showDiff: true,
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* ### config.truncateThreshold
|
|
983
|
+
*
|
|
984
|
+
* User configurable property, sets length threshold for actual and
|
|
985
|
+
* expected values in assertion errors. If this threshold is exceeded,
|
|
986
|
+
* the value is truncated.
|
|
987
|
+
*
|
|
988
|
+
* Set it to zero if you want to disable truncating altogether.
|
|
989
|
+
*
|
|
990
|
+
* chai.config.truncateThreshold = 0; // disable truncating
|
|
991
|
+
*
|
|
992
|
+
* @param {Number}
|
|
993
|
+
* @api public
|
|
994
|
+
*/
|
|
995
|
+
|
|
996
|
+
truncateThreshold: 40
|
|
997
|
+
|
|
998
|
+
};
|
|
999
|
+
|
|
944
1000
|
});
|
|
945
1001
|
require.register("chai/lib/chai/core/assertions.js", function(exports, require, module){
|
|
946
1002
|
/*!
|
|
@@ -960,7 +1016,7 @@ module.exports = function (chai, _) {
|
|
|
960
1016
|
*
|
|
961
1017
|
* The following are provided as chainable getters to
|
|
962
1018
|
* improve the readability of your assertions. They
|
|
963
|
-
* do not provide
|
|
1019
|
+
* do not provide testing capabilities unless they
|
|
964
1020
|
* have been overwritten by a plugin.
|
|
965
1021
|
*
|
|
966
1022
|
* **Chains**
|
|
@@ -1092,17 +1148,24 @@ module.exports = function (chai, _) {
|
|
|
1092
1148
|
function include (val, msg) {
|
|
1093
1149
|
if (msg) flag(this, 'message', msg);
|
|
1094
1150
|
var obj = flag(this, 'object');
|
|
1095
|
-
|
|
1096
|
-
if (_.type(val) === 'object') {
|
|
1151
|
+
var expected = false;
|
|
1152
|
+
if (_.type(obj) === 'array' && _.type(val) === 'object') {
|
|
1153
|
+
for (var i in obj) {
|
|
1154
|
+
if (_.eql(obj[i], val)) {
|
|
1155
|
+
expected = true;
|
|
1156
|
+
break;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
} else if (_.type(val) === 'object') {
|
|
1097
1160
|
if (!flag(this, 'negate')) {
|
|
1098
1161
|
for (var k in val) new Assertion(obj).property(k, val[k]);
|
|
1099
1162
|
return;
|
|
1100
1163
|
}
|
|
1101
1164
|
var subset = {}
|
|
1102
1165
|
for (var k in val) subset[k] = obj[k]
|
|
1103
|
-
|
|
1166
|
+
expected = _.eql(subset, val);
|
|
1104
1167
|
} else {
|
|
1105
|
-
|
|
1168
|
+
expected = obj && ~obj.indexOf(val)
|
|
1106
1169
|
}
|
|
1107
1170
|
this.assert(
|
|
1108
1171
|
expected
|
|
@@ -2190,9 +2253,13 @@ module.exports = function (chai, _) {
|
|
|
2190
2253
|
);
|
|
2191
2254
|
});
|
|
2192
2255
|
|
|
2193
|
-
function isSubsetOf(subset, superset) {
|
|
2256
|
+
function isSubsetOf(subset, superset, cmp) {
|
|
2194
2257
|
return subset.every(function(elem) {
|
|
2195
|
-
return superset.indexOf(elem) !== -1;
|
|
2258
|
+
if (!cmp) return superset.indexOf(elem) !== -1;
|
|
2259
|
+
|
|
2260
|
+
return superset.some(function(elem2) {
|
|
2261
|
+
return cmp(elem, elem2);
|
|
2262
|
+
});
|
|
2196
2263
|
})
|
|
2197
2264
|
}
|
|
2198
2265
|
|
|
@@ -2200,7 +2267,9 @@ module.exports = function (chai, _) {
|
|
|
2200
2267
|
* ### .members(set)
|
|
2201
2268
|
*
|
|
2202
2269
|
* Asserts that the target is a superset of `set`,
|
|
2203
|
-
* or that the target and `set` have the same members.
|
|
2270
|
+
* or that the target and `set` have the same strictly-equal (===) members.
|
|
2271
|
+
* Alternately, if the `deep` flag is set, set members are compared for deep
|
|
2272
|
+
* equality.
|
|
2204
2273
|
*
|
|
2205
2274
|
* expect([1, 2, 3]).to.include.members([3, 2]);
|
|
2206
2275
|
* expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
|
|
@@ -2208,6 +2277,8 @@ module.exports = function (chai, _) {
|
|
|
2208
2277
|
* expect([4, 2]).to.have.members([2, 4]);
|
|
2209
2278
|
* expect([5, 2]).to.not.have.members([5, 2, 1]);
|
|
2210
2279
|
*
|
|
2280
|
+
* expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
|
|
2281
|
+
*
|
|
2211
2282
|
* @name members
|
|
2212
2283
|
* @param {Array} set
|
|
2213
2284
|
* @param {String} message _optional_
|
|
@@ -2221,9 +2292,11 @@ module.exports = function (chai, _) {
|
|
|
2221
2292
|
new Assertion(obj).to.be.an('array');
|
|
2222
2293
|
new Assertion(subset).to.be.an('array');
|
|
2223
2294
|
|
|
2295
|
+
var cmp = flag(this, 'deep') ? _.eql : undefined;
|
|
2296
|
+
|
|
2224
2297
|
if (flag(this, 'contains')) {
|
|
2225
2298
|
return this.assert(
|
|
2226
|
-
isSubsetOf(subset, obj)
|
|
2299
|
+
isSubsetOf(subset, obj, cmp)
|
|
2227
2300
|
, 'expected #{this} to be a superset of #{act}'
|
|
2228
2301
|
, 'expected #{this} to not be a superset of #{act}'
|
|
2229
2302
|
, obj
|
|
@@ -2232,7 +2305,7 @@ module.exports = function (chai, _) {
|
|
|
2232
2305
|
}
|
|
2233
2306
|
|
|
2234
2307
|
this.assert(
|
|
2235
|
-
isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
|
|
2308
|
+
isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
|
|
2236
2309
|
, 'expected #{this} to have the same members as #{act}'
|
|
2237
2310
|
, 'expected #{this} to not have the same members as #{act}'
|
|
2238
2311
|
, obj
|
|
@@ -2278,7 +2351,7 @@ module.exports = function (chai, util) {
|
|
|
2278
2351
|
*/
|
|
2279
2352
|
|
|
2280
2353
|
var assert = chai.assert = function (express, errmsg) {
|
|
2281
|
-
var test = new Assertion(null);
|
|
2354
|
+
var test = new Assertion(null, null, chai.assert);
|
|
2282
2355
|
test.assert(
|
|
2283
2356
|
express
|
|
2284
2357
|
, errmsg
|
|
@@ -2359,7 +2432,7 @@ module.exports = function (chai, util) {
|
|
|
2359
2432
|
*/
|
|
2360
2433
|
|
|
2361
2434
|
assert.equal = function (act, exp, msg) {
|
|
2362
|
-
var test = new Assertion(act, msg);
|
|
2435
|
+
var test = new Assertion(act, msg, assert.equal);
|
|
2363
2436
|
|
|
2364
2437
|
test.assert(
|
|
2365
2438
|
exp == flag(test, 'object')
|
|
@@ -2385,7 +2458,7 @@ module.exports = function (chai, util) {
|
|
|
2385
2458
|
*/
|
|
2386
2459
|
|
|
2387
2460
|
assert.notEqual = function (act, exp, msg) {
|
|
2388
|
-
var test = new Assertion(act, msg);
|
|
2461
|
+
var test = new Assertion(act, msg, assert.notEqual);
|
|
2389
2462
|
|
|
2390
2463
|
test.assert(
|
|
2391
2464
|
exp != flag(test, 'object')
|
|
@@ -2636,8 +2709,8 @@ module.exports = function (chai, util) {
|
|
|
2636
2709
|
* Asserts that `value` is _not_ an object.
|
|
2637
2710
|
*
|
|
2638
2711
|
* var selection = 'chai'
|
|
2639
|
-
* assert.
|
|
2640
|
-
* assert.
|
|
2712
|
+
* assert.isNotObject(selection, 'tea selection is not an object');
|
|
2713
|
+
* assert.isNotObject(null, 'null is not an object');
|
|
2641
2714
|
*
|
|
2642
2715
|
* @name isNotObject
|
|
2643
2716
|
* @param {Mixed} value
|
|
@@ -2901,7 +2974,7 @@ module.exports = function (chai, util) {
|
|
|
2901
2974
|
*/
|
|
2902
2975
|
|
|
2903
2976
|
assert.include = function (exp, inc, msg) {
|
|
2904
|
-
new Assertion(exp, msg).include(inc);
|
|
2977
|
+
new Assertion(exp, msg, assert.include).include(inc);
|
|
2905
2978
|
};
|
|
2906
2979
|
|
|
2907
2980
|
/**
|
|
@@ -2921,7 +2994,7 @@ module.exports = function (chai, util) {
|
|
|
2921
2994
|
*/
|
|
2922
2995
|
|
|
2923
2996
|
assert.notInclude = function (exp, inc, msg) {
|
|
2924
|
-
new Assertion(exp, msg).not.include(inc);
|
|
2997
|
+
new Assertion(exp, msg, assert.notInclude).not.include(inc);
|
|
2925
2998
|
};
|
|
2926
2999
|
|
|
2927
3000
|
/**
|
|
@@ -3327,31 +3400,33 @@ module.exports = function (chai, util) {
|
|
|
3327
3400
|
var Assertion = chai.Assertion;
|
|
3328
3401
|
|
|
3329
3402
|
function loadShould () {
|
|
3403
|
+
// explicitly define this method as function as to have it's name to include as `ssfi`
|
|
3404
|
+
function shouldGetter() {
|
|
3405
|
+
if (this instanceof String || this instanceof Number) {
|
|
3406
|
+
return new Assertion(this.constructor(this), null, shouldGetter);
|
|
3407
|
+
} else if (this instanceof Boolean) {
|
|
3408
|
+
return new Assertion(this == true, null, shouldGetter);
|
|
3409
|
+
}
|
|
3410
|
+
return new Assertion(this, null, shouldGetter);
|
|
3411
|
+
}
|
|
3412
|
+
function shouldSetter(value) {
|
|
3413
|
+
// See https://github.com/chaijs/chai/issues/86: this makes
|
|
3414
|
+
// `whatever.should = someValue` actually set `someValue`, which is
|
|
3415
|
+
// especially useful for `global.should = require('chai').should()`.
|
|
3416
|
+
//
|
|
3417
|
+
// Note that we have to use [[DefineProperty]] instead of [[Put]]
|
|
3418
|
+
// since otherwise we would trigger this very setter!
|
|
3419
|
+
Object.defineProperty(this, 'should', {
|
|
3420
|
+
value: value,
|
|
3421
|
+
enumerable: true,
|
|
3422
|
+
configurable: true,
|
|
3423
|
+
writable: true
|
|
3424
|
+
});
|
|
3425
|
+
}
|
|
3330
3426
|
// modify Object.prototype to have `should`
|
|
3331
|
-
Object.defineProperty(Object.prototype, 'should',
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
// See https://github.com/chaijs/chai/issues/86: this makes
|
|
3335
|
-
// `whatever.should = someValue` actually set `someValue`, which is
|
|
3336
|
-
// especially useful for `global.should = require('chai').should()`.
|
|
3337
|
-
//
|
|
3338
|
-
// Note that we have to use [[DefineProperty]] instead of [[Put]]
|
|
3339
|
-
// since otherwise we would trigger this very setter!
|
|
3340
|
-
Object.defineProperty(this, 'should', {
|
|
3341
|
-
value: value,
|
|
3342
|
-
enumerable: true,
|
|
3343
|
-
configurable: true,
|
|
3344
|
-
writable: true
|
|
3345
|
-
});
|
|
3346
|
-
}
|
|
3347
|
-
, get: function(){
|
|
3348
|
-
if (this instanceof String || this instanceof Number) {
|
|
3349
|
-
return new Assertion(this.constructor(this));
|
|
3350
|
-
} else if (this instanceof Boolean) {
|
|
3351
|
-
return new Assertion(this == true);
|
|
3352
|
-
}
|
|
3353
|
-
return new Assertion(this);
|
|
3354
|
-
}
|
|
3427
|
+
Object.defineProperty(Object.prototype, 'should', {
|
|
3428
|
+
set: shouldSetter
|
|
3429
|
+
, get: shouldGetter
|
|
3355
3430
|
, configurable: true
|
|
3356
3431
|
});
|
|
3357
3432
|
|
|
@@ -3407,6 +3482,8 @@ require.register("chai/lib/chai/utils/addChainableMethod.js", function(exports,
|
|
|
3407
3482
|
*/
|
|
3408
3483
|
|
|
3409
3484
|
var transferFlags = require('./transferFlags');
|
|
3485
|
+
var flag = require('./flag');
|
|
3486
|
+
var config = require('../config');
|
|
3410
3487
|
|
|
3411
3488
|
/*!
|
|
3412
3489
|
* Module variables
|
|
@@ -3472,7 +3549,10 @@ module.exports = function (ctx, name, method, chainingBehavior) {
|
|
|
3472
3549
|
{ get: function () {
|
|
3473
3550
|
chainableBehavior.chainingBehavior.call(this);
|
|
3474
3551
|
|
|
3475
|
-
var assert = function () {
|
|
3552
|
+
var assert = function assert() {
|
|
3553
|
+
var old_ssfi = flag(this, 'ssfi');
|
|
3554
|
+
if (old_ssfi && config.includeStack === false)
|
|
3555
|
+
flag(this, 'ssfi', assert);
|
|
3476
3556
|
var result = chainableBehavior.method.apply(this, arguments);
|
|
3477
3557
|
return result === undefined ? this : result;
|
|
3478
3558
|
};
|
|
@@ -3511,6 +3591,8 @@ require.register("chai/lib/chai/utils/addMethod.js", function(exports, require,
|
|
|
3511
3591
|
* MIT Licensed
|
|
3512
3592
|
*/
|
|
3513
3593
|
|
|
3594
|
+
var config = require('../config');
|
|
3595
|
+
|
|
3514
3596
|
/**
|
|
3515
3597
|
* ### .addMethod (ctx, name, method)
|
|
3516
3598
|
*
|
|
@@ -3535,9 +3617,13 @@ require.register("chai/lib/chai/utils/addMethod.js", function(exports, require,
|
|
|
3535
3617
|
* @name addMethod
|
|
3536
3618
|
* @api public
|
|
3537
3619
|
*/
|
|
3620
|
+
var flag = require('./flag');
|
|
3538
3621
|
|
|
3539
3622
|
module.exports = function (ctx, name, method) {
|
|
3540
3623
|
ctx[name] = function () {
|
|
3624
|
+
var old_ssfi = flag(this, 'ssfi');
|
|
3625
|
+
if (old_ssfi && config.includeStack === false)
|
|
3626
|
+
flag(this, 'ssfi', ctx[name]);
|
|
3541
3627
|
var result = method.apply(this, arguments);
|
|
3542
3628
|
return result === undefined ? this : result;
|
|
3543
3629
|
};
|
|
@@ -3639,8 +3725,7 @@ require.register("chai/lib/chai/utils/getActual.js", function(exports, require,
|
|
|
3639
3725
|
*/
|
|
3640
3726
|
|
|
3641
3727
|
module.exports = function (obj, args) {
|
|
3642
|
-
|
|
3643
|
-
return 'undefined' !== typeof actual ? actual : obj._obj;
|
|
3728
|
+
return args.length > 4 ? args[4] : obj._obj;
|
|
3644
3729
|
};
|
|
3645
3730
|
|
|
3646
3731
|
});
|
|
@@ -4342,6 +4427,7 @@ require.register("chai/lib/chai/utils/objDisplay.js", function(exports, require,
|
|
|
4342
4427
|
*/
|
|
4343
4428
|
|
|
4344
4429
|
var inspect = require('./inspect');
|
|
4430
|
+
var config = require('../config');
|
|
4345
4431
|
|
|
4346
4432
|
/**
|
|
4347
4433
|
* ### .objDisplay (object)
|
|
@@ -4359,7 +4445,7 @@ module.exports = function (obj) {
|
|
|
4359
4445
|
var str = inspect(obj)
|
|
4360
4446
|
, type = Object.prototype.toString.call(obj);
|
|
4361
4447
|
|
|
4362
|
-
if (str.length >=
|
|
4448
|
+
if (config.truncateThreshold && str.length >= config.truncateThreshold) {
|
|
4363
4449
|
if (type === '[object Function]') {
|
|
4364
4450
|
return !obj.name || obj.name === ''
|
|
4365
4451
|
? '[Function]'
|
package/lib/chai/assertion.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* MIT Licensed
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
var config = require('./config');
|
|
9
|
+
|
|
8
10
|
module.exports = function (_chai, util) {
|
|
9
11
|
/*!
|
|
10
12
|
* Module dependencies.
|
|
@@ -33,33 +35,27 @@ module.exports = function (_chai, util) {
|
|
|
33
35
|
flag(this, 'message', msg);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
Assertion.includeStack = false;
|
|
49
|
-
|
|
50
|
-
/*!
|
|
51
|
-
* ### Assertion.showDiff
|
|
52
|
-
*
|
|
53
|
-
* User configurable property, influences whether or not
|
|
54
|
-
* the `showDiff` flag should be included in the thrown
|
|
55
|
-
* AssertionErrors. `false` will always be `false`; `true`
|
|
56
|
-
* will be true when the assertion has requested a diff
|
|
57
|
-
* be shown.
|
|
58
|
-
*
|
|
59
|
-
* @api public
|
|
60
|
-
*/
|
|
38
|
+
Object.defineProperty(Assertion, 'includeStack', {
|
|
39
|
+
get: function() {
|
|
40
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
41
|
+
return config.includeStack;
|
|
42
|
+
},
|
|
43
|
+
set: function(value) {
|
|
44
|
+
console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
|
|
45
|
+
config.includeStack = value;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
61
48
|
|
|
62
|
-
Assertion
|
|
49
|
+
Object.defineProperty(Assertion, 'showDiff', {
|
|
50
|
+
get: function() {
|
|
51
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
52
|
+
return config.showDiff;
|
|
53
|
+
},
|
|
54
|
+
set: function(value) {
|
|
55
|
+
console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
|
|
56
|
+
config.showDiff = value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
63
59
|
|
|
64
60
|
Assertion.addProperty = function (name, fn) {
|
|
65
61
|
util.addProperty(this.prototype, name, fn);
|
|
@@ -102,7 +98,7 @@ module.exports = function (_chai, util) {
|
|
|
102
98
|
Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
|
|
103
99
|
var ok = util.test(this, arguments);
|
|
104
100
|
if (true !== showDiff) showDiff = false;
|
|
105
|
-
if (true !==
|
|
101
|
+
if (true !== config.showDiff) showDiff = false;
|
|
106
102
|
|
|
107
103
|
if (!ok) {
|
|
108
104
|
var msg = util.getMessage(this, arguments)
|
|
@@ -111,7 +107,7 @@ module.exports = function (_chai, util) {
|
|
|
111
107
|
actual: actual
|
|
112
108
|
, expected: expected
|
|
113
109
|
, showDiff: showDiff
|
|
114
|
-
}, (
|
|
110
|
+
}, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
|
|
115
111
|
}
|
|
116
112
|
};
|
|
117
113
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ### config.includeStack
|
|
5
|
+
*
|
|
6
|
+
* User configurable property, influences whether stack trace
|
|
7
|
+
* is included in Assertion error message. Default of false
|
|
8
|
+
* suppresses stack trace in the error message.
|
|
9
|
+
*
|
|
10
|
+
* chai.config.includeStack = true; // enable stack on error
|
|
11
|
+
*
|
|
12
|
+
* @param {Boolean}
|
|
13
|
+
* @api public
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
includeStack: false,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* ### config.showDiff
|
|
20
|
+
*
|
|
21
|
+
* User configurable property, influences whether or not
|
|
22
|
+
* the `showDiff` flag should be included in the thrown
|
|
23
|
+
* AssertionErrors. `false` will always be `false`; `true`
|
|
24
|
+
* will be true when the assertion has requested a diff
|
|
25
|
+
* be shown.
|
|
26
|
+
*
|
|
27
|
+
* @param {Boolean}
|
|
28
|
+
* @api public
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
showDiff: true,
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* ### config.truncateThreshold
|
|
35
|
+
*
|
|
36
|
+
* User configurable property, sets length threshold for actual and
|
|
37
|
+
* expected values in assertion errors. If this threshold is exceeded,
|
|
38
|
+
* the value is truncated.
|
|
39
|
+
*
|
|
40
|
+
* Set it to zero if you want to disable truncating altogether.
|
|
41
|
+
*
|
|
42
|
+
* chai.config.truncateThreshold = 0; // disable truncating
|
|
43
|
+
*
|
|
44
|
+
* @param {Number}
|
|
45
|
+
* @api public
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
truncateThreshold: 40
|
|
49
|
+
|
|
50
|
+
};
|
|
@@ -15,7 +15,7 @@ module.exports = function (chai, _) {
|
|
|
15
15
|
*
|
|
16
16
|
* The following are provided as chainable getters to
|
|
17
17
|
* improve the readability of your assertions. They
|
|
18
|
-
* do not provide
|
|
18
|
+
* do not provide testing capabilities unless they
|
|
19
19
|
* have been overwritten by a plugin.
|
|
20
20
|
*
|
|
21
21
|
* **Chains**
|
|
@@ -147,17 +147,24 @@ module.exports = function (chai, _) {
|
|
|
147
147
|
function include (val, msg) {
|
|
148
148
|
if (msg) flag(this, 'message', msg);
|
|
149
149
|
var obj = flag(this, 'object');
|
|
150
|
-
|
|
151
|
-
if (_.type(val) === 'object') {
|
|
150
|
+
var expected = false;
|
|
151
|
+
if (_.type(obj) === 'array' && _.type(val) === 'object') {
|
|
152
|
+
for (var i in obj) {
|
|
153
|
+
if (_.eql(obj[i], val)) {
|
|
154
|
+
expected = true;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else if (_.type(val) === 'object') {
|
|
152
159
|
if (!flag(this, 'negate')) {
|
|
153
160
|
for (var k in val) new Assertion(obj).property(k, val[k]);
|
|
154
161
|
return;
|
|
155
162
|
}
|
|
156
163
|
var subset = {}
|
|
157
164
|
for (var k in val) subset[k] = obj[k]
|
|
158
|
-
|
|
165
|
+
expected = _.eql(subset, val);
|
|
159
166
|
} else {
|
|
160
|
-
|
|
167
|
+
expected = obj && ~obj.indexOf(val)
|
|
161
168
|
}
|
|
162
169
|
this.assert(
|
|
163
170
|
expected
|
|
@@ -1245,9 +1252,13 @@ module.exports = function (chai, _) {
|
|
|
1245
1252
|
);
|
|
1246
1253
|
});
|
|
1247
1254
|
|
|
1248
|
-
function isSubsetOf(subset, superset) {
|
|
1255
|
+
function isSubsetOf(subset, superset, cmp) {
|
|
1249
1256
|
return subset.every(function(elem) {
|
|
1250
|
-
return superset.indexOf(elem) !== -1;
|
|
1257
|
+
if (!cmp) return superset.indexOf(elem) !== -1;
|
|
1258
|
+
|
|
1259
|
+
return superset.some(function(elem2) {
|
|
1260
|
+
return cmp(elem, elem2);
|
|
1261
|
+
});
|
|
1251
1262
|
})
|
|
1252
1263
|
}
|
|
1253
1264
|
|
|
@@ -1255,7 +1266,9 @@ module.exports = function (chai, _) {
|
|
|
1255
1266
|
* ### .members(set)
|
|
1256
1267
|
*
|
|
1257
1268
|
* Asserts that the target is a superset of `set`,
|
|
1258
|
-
* or that the target and `set` have the same members.
|
|
1269
|
+
* or that the target and `set` have the same strictly-equal (===) members.
|
|
1270
|
+
* Alternately, if the `deep` flag is set, set members are compared for deep
|
|
1271
|
+
* equality.
|
|
1259
1272
|
*
|
|
1260
1273
|
* expect([1, 2, 3]).to.include.members([3, 2]);
|
|
1261
1274
|
* expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
|
|
@@ -1263,6 +1276,8 @@ module.exports = function (chai, _) {
|
|
|
1263
1276
|
* expect([4, 2]).to.have.members([2, 4]);
|
|
1264
1277
|
* expect([5, 2]).to.not.have.members([5, 2, 1]);
|
|
1265
1278
|
*
|
|
1279
|
+
* expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
|
|
1280
|
+
*
|
|
1266
1281
|
* @name members
|
|
1267
1282
|
* @param {Array} set
|
|
1268
1283
|
* @param {String} message _optional_
|
|
@@ -1276,9 +1291,11 @@ module.exports = function (chai, _) {
|
|
|
1276
1291
|
new Assertion(obj).to.be.an('array');
|
|
1277
1292
|
new Assertion(subset).to.be.an('array');
|
|
1278
1293
|
|
|
1294
|
+
var cmp = flag(this, 'deep') ? _.eql : undefined;
|
|
1295
|
+
|
|
1279
1296
|
if (flag(this, 'contains')) {
|
|
1280
1297
|
return this.assert(
|
|
1281
|
-
isSubsetOf(subset, obj)
|
|
1298
|
+
isSubsetOf(subset, obj, cmp)
|
|
1282
1299
|
, 'expected #{this} to be a superset of #{act}'
|
|
1283
1300
|
, 'expected #{this} to not be a superset of #{act}'
|
|
1284
1301
|
, obj
|
|
@@ -1287,7 +1304,7 @@ module.exports = function (chai, _) {
|
|
|
1287
1304
|
}
|
|
1288
1305
|
|
|
1289
1306
|
this.assert(
|
|
1290
|
-
isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
|
|
1307
|
+
isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
|
|
1291
1308
|
, 'expected #{this} to have the same members as #{act}'
|
|
1292
1309
|
, 'expected #{this} to not have the same members as #{act}'
|
|
1293
1310
|
, obj
|
|
@@ -33,7 +33,7 @@ module.exports = function (chai, util) {
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
var assert = chai.assert = function (express, errmsg) {
|
|
36
|
-
var test = new Assertion(null);
|
|
36
|
+
var test = new Assertion(null, null, chai.assert);
|
|
37
37
|
test.assert(
|
|
38
38
|
express
|
|
39
39
|
, errmsg
|
|
@@ -114,7 +114,7 @@ module.exports = function (chai, util) {
|
|
|
114
114
|
*/
|
|
115
115
|
|
|
116
116
|
assert.equal = function (act, exp, msg) {
|
|
117
|
-
var test = new Assertion(act, msg);
|
|
117
|
+
var test = new Assertion(act, msg, assert.equal);
|
|
118
118
|
|
|
119
119
|
test.assert(
|
|
120
120
|
exp == flag(test, 'object')
|
|
@@ -140,7 +140,7 @@ module.exports = function (chai, util) {
|
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
142
|
assert.notEqual = function (act, exp, msg) {
|
|
143
|
-
var test = new Assertion(act, msg);
|
|
143
|
+
var test = new Assertion(act, msg, assert.notEqual);
|
|
144
144
|
|
|
145
145
|
test.assert(
|
|
146
146
|
exp != flag(test, 'object')
|
|
@@ -391,8 +391,8 @@ module.exports = function (chai, util) {
|
|
|
391
391
|
* Asserts that `value` is _not_ an object.
|
|
392
392
|
*
|
|
393
393
|
* var selection = 'chai'
|
|
394
|
-
* assert.
|
|
395
|
-
* assert.
|
|
394
|
+
* assert.isNotObject(selection, 'tea selection is not an object');
|
|
395
|
+
* assert.isNotObject(null, 'null is not an object');
|
|
396
396
|
*
|
|
397
397
|
* @name isNotObject
|
|
398
398
|
* @param {Mixed} value
|
|
@@ -656,7 +656,7 @@ module.exports = function (chai, util) {
|
|
|
656
656
|
*/
|
|
657
657
|
|
|
658
658
|
assert.include = function (exp, inc, msg) {
|
|
659
|
-
new Assertion(exp, msg).include(inc);
|
|
659
|
+
new Assertion(exp, msg, assert.include).include(inc);
|
|
660
660
|
};
|
|
661
661
|
|
|
662
662
|
/**
|
|
@@ -676,7 +676,7 @@ module.exports = function (chai, util) {
|
|
|
676
676
|
*/
|
|
677
677
|
|
|
678
678
|
assert.notInclude = function (exp, inc, msg) {
|
|
679
|
-
new Assertion(exp, msg).not.include(inc);
|
|
679
|
+
new Assertion(exp, msg, assert.notInclude).not.include(inc);
|
|
680
680
|
};
|
|
681
681
|
|
|
682
682
|
/**
|
|
@@ -8,31 +8,33 @@ module.exports = function (chai, util) {
|
|
|
8
8
|
var Assertion = chai.Assertion;
|
|
9
9
|
|
|
10
10
|
function loadShould () {
|
|
11
|
+
// explicitly define this method as function as to have it's name to include as `ssfi`
|
|
12
|
+
function shouldGetter() {
|
|
13
|
+
if (this instanceof String || this instanceof Number) {
|
|
14
|
+
return new Assertion(this.constructor(this), null, shouldGetter);
|
|
15
|
+
} else if (this instanceof Boolean) {
|
|
16
|
+
return new Assertion(this == true, null, shouldGetter);
|
|
17
|
+
}
|
|
18
|
+
return new Assertion(this, null, shouldGetter);
|
|
19
|
+
}
|
|
20
|
+
function shouldSetter(value) {
|
|
21
|
+
// See https://github.com/chaijs/chai/issues/86: this makes
|
|
22
|
+
// `whatever.should = someValue` actually set `someValue`, which is
|
|
23
|
+
// especially useful for `global.should = require('chai').should()`.
|
|
24
|
+
//
|
|
25
|
+
// Note that we have to use [[DefineProperty]] instead of [[Put]]
|
|
26
|
+
// since otherwise we would trigger this very setter!
|
|
27
|
+
Object.defineProperty(this, 'should', {
|
|
28
|
+
value: value,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
});
|
|
33
|
+
}
|
|
11
34
|
// modify Object.prototype to have `should`
|
|
12
|
-
Object.defineProperty(Object.prototype, 'should',
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// See https://github.com/chaijs/chai/issues/86: this makes
|
|
16
|
-
// `whatever.should = someValue` actually set `someValue`, which is
|
|
17
|
-
// especially useful for `global.should = require('chai').should()`.
|
|
18
|
-
//
|
|
19
|
-
// Note that we have to use [[DefineProperty]] instead of [[Put]]
|
|
20
|
-
// since otherwise we would trigger this very setter!
|
|
21
|
-
Object.defineProperty(this, 'should', {
|
|
22
|
-
value: value,
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
writable: true
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
, get: function(){
|
|
29
|
-
if (this instanceof String || this instanceof Number) {
|
|
30
|
-
return new Assertion(this.constructor(this));
|
|
31
|
-
} else if (this instanceof Boolean) {
|
|
32
|
-
return new Assertion(this == true);
|
|
33
|
-
}
|
|
34
|
-
return new Assertion(this);
|
|
35
|
-
}
|
|
35
|
+
Object.defineProperty(Object.prototype, 'should', {
|
|
36
|
+
set: shouldSetter
|
|
37
|
+
, get: shouldGetter
|
|
36
38
|
, configurable: true
|
|
37
39
|
});
|
|
38
40
|
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
var transferFlags = require('./transferFlags');
|
|
12
|
+
var flag = require('./flag');
|
|
13
|
+
var config = require('../config');
|
|
12
14
|
|
|
13
15
|
/*!
|
|
14
16
|
* Module variables
|
|
@@ -74,7 +76,10 @@ module.exports = function (ctx, name, method, chainingBehavior) {
|
|
|
74
76
|
{ get: function () {
|
|
75
77
|
chainableBehavior.chainingBehavior.call(this);
|
|
76
78
|
|
|
77
|
-
var assert = function () {
|
|
79
|
+
var assert = function assert() {
|
|
80
|
+
var old_ssfi = flag(this, 'ssfi');
|
|
81
|
+
if (old_ssfi && config.includeStack === false)
|
|
82
|
+
flag(this, 'ssfi', assert);
|
|
78
83
|
var result = chainableBehavior.method.apply(this, arguments);
|
|
79
84
|
return result === undefined ? this : result;
|
|
80
85
|
};
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* MIT Licensed
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
var config = require('../config');
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* ### .addMethod (ctx, name, method)
|
|
9
11
|
*
|
|
@@ -28,9 +30,13 @@
|
|
|
28
30
|
* @name addMethod
|
|
29
31
|
* @api public
|
|
30
32
|
*/
|
|
33
|
+
var flag = require('./flag');
|
|
31
34
|
|
|
32
35
|
module.exports = function (ctx, name, method) {
|
|
33
36
|
ctx[name] = function () {
|
|
37
|
+
var old_ssfi = flag(this, 'ssfi');
|
|
38
|
+
if (old_ssfi && config.includeStack === false)
|
|
39
|
+
flag(this, 'ssfi', ctx[name]);
|
|
34
40
|
var result = method.apply(this, arguments);
|
|
35
41
|
return result === undefined ? this : result;
|
|
36
42
|
};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
var inspect = require('./inspect');
|
|
12
|
+
var config = require('../config');
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* ### .objDisplay (object)
|
|
@@ -26,7 +27,7 @@ module.exports = function (obj) {
|
|
|
26
27
|
var str = inspect(obj)
|
|
27
28
|
, type = Object.prototype.toString.call(obj);
|
|
28
29
|
|
|
29
|
-
if (str.length >=
|
|
30
|
+
if (config.truncateThreshold && str.length >= config.truncateThreshold) {
|
|
30
31
|
if (type === '[object Function]') {
|
|
31
32
|
return !obj.name || obj.name === ''
|
|
32
33
|
? '[Function]'
|
package/lib/chai.js
CHANGED
|
@@ -11,7 +11,7 @@ var used = []
|
|
|
11
11
|
* Chai version
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
exports.version = '1.
|
|
14
|
+
exports.version = '1.9.1';
|
|
15
15
|
|
|
16
16
|
/*!
|
|
17
17
|
* Assertion Error
|
|
@@ -44,6 +44,13 @@ exports.use = function (fn) {
|
|
|
44
44
|
return this;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
/*!
|
|
48
|
+
* Configuration
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
var config = require('./chai/config');
|
|
52
|
+
exports.config = config;
|
|
53
|
+
|
|
47
54
|
/*!
|
|
48
55
|
* Primary `Assertion` prototype
|
|
49
56
|
*/
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Veselin Todorov <hi@vesln.com>",
|
|
12
12
|
"John Firebaugh <john.firebaugh@gmail.com>"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.9.
|
|
14
|
+
"version": "1.9.1",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"component": "*"
|
|
35
|
-
, "karma": "0.
|
|
35
|
+
, "karma": "0.12.x"
|
|
36
36
|
, "karma-mocha": "*"
|
|
37
|
-
, "karma-sauce-launcher": "0.2.
|
|
37
|
+
, "karma-sauce-launcher": "0.2.x"
|
|
38
38
|
, "karma-phantomjs-launcher": "0.1.1"
|
|
39
|
-
, "mocha": "1.
|
|
40
|
-
, "istanbul": "
|
|
39
|
+
, "mocha": "1.17.x"
|
|
40
|
+
, "istanbul": "0.2.x"
|
|
41
41
|
}
|
|
42
42
|
}
|