chai 1.7.2 → 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/karma.conf.js ADDED
@@ -0,0 +1,28 @@
1
+ module.exports = function(config) {
2
+ config.set({
3
+ frameworks: [ 'mocha' ]
4
+ , files: [
5
+ 'build/build.js'
6
+ , 'test/bootstrap/karma.js'
7
+ , 'test/*.js'
8
+ ]
9
+ , reporters: [ 'progress' ]
10
+ , colors: true
11
+ , logLevel: config.LOG_INFO
12
+ , autoWatch: false
13
+ , browsers: [ 'PhantomJS' ]
14
+ , browserDisconnectTimeout: 10000
15
+ , browserDisconnectTolerance: 2
16
+ , browserNoActivityTimeout: 20000
17
+ , singleRun: true
18
+ });
19
+
20
+ switch (process.env.CHAI_TEST_ENV) {
21
+ case 'sauce':
22
+ require('./karma.sauce')(config);
23
+ break;
24
+ default:
25
+ // ...
26
+ break;
27
+ };
28
+ };
package/karma.sauce.js ADDED
@@ -0,0 +1,41 @@
1
+ var version = require('./package.json').version;
2
+ var ts = new Date().getTime();
3
+
4
+ module.exports = function(config) {
5
+ var auth;
6
+
7
+ try {
8
+ auth = require('./test/auth/index');
9
+ } catch(ex) {
10
+ auth = {};
11
+ auth.SAUCE_USERNAME = process.env.SAUCE_USERNAME || null;
12
+ auth.SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY || null;
13
+ }
14
+
15
+ if (!auth.SAUCE_USERNAME || !auth.SAUCE_ACCESS_KEY) return;
16
+ if (process.env.SKIP_SAUCE) return;
17
+
18
+ var branch = process.env.TRAVIS_BRANCH || 'local'
19
+ var browserConfig = require('./sauce.browsers');
20
+ var browsers = Object.keys(browserConfig);
21
+ var tags = [ 'chaijs_' + version, auth.SAUCE_USERNAME + '@' + branch ];
22
+ var tunnel = process.env.TRAVIS_JOB_NUMBER || ts;
23
+
24
+ if (process.env.TRAVIS_JOB_NUMBER) {
25
+ tags.push('travis@' + process.env.TRAVIS_JOB_NUMBER);
26
+ }
27
+
28
+ config.browsers = config.browsers.concat(browsers);
29
+ config.customLaunchers = browserConfig;
30
+ config.reporters.push('saucelabs');
31
+ config.transports = [ 'xhr-polling' ];
32
+
33
+ config.sauceLabs = {
34
+ username: auth.SAUCE_USERNAME
35
+ , accessKey: auth.SAUCE_ACCESS_KEY
36
+ , startConnect: true
37
+ , tags: tags
38
+ , testName: 'ChaiJS'
39
+ , tunnelIdentifier: tunnel
40
+ };
41
+ };
@@ -1,10 +1,12 @@
1
1
  /*!
2
2
  * chai
3
3
  * http://chaijs.com
4
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
4
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
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
- * ### Assertion.includeStack
38
- *
39
- * User configurable property, influences whether stack trace
40
- * is included in Assertion error message. Default of false
41
- * suppresses stack trace in the error message
42
- *
43
- * Assertion.includeStack = true; // enable stack on error
44
- *
45
- * @api public
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.showDiff = true;
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);
@@ -81,6 +77,10 @@ module.exports = function (_chai, util) {
81
77
  util.overwriteMethod(this.prototype, name, fn);
82
78
  };
83
79
 
80
+ Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
81
+ util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
82
+ };
83
+
84
84
  /*!
85
85
  * ### .assert(expression, message, negateMessage, expected, actual)
86
86
  *
@@ -98,7 +98,7 @@ module.exports = function (_chai, util) {
98
98
  Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
99
99
  var ok = util.test(this, arguments);
100
100
  if (true !== showDiff) showDiff = false;
101
- if (true !== Assertion.showDiff) showDiff = false;
101
+ if (true !== config.showDiff) showDiff = false;
102
102
 
103
103
  if (!ok) {
104
104
  var msg = util.getMessage(this, arguments)
@@ -107,7 +107,7 @@ module.exports = function (_chai, util) {
107
107
  actual: actual
108
108
  , expected: expected
109
109
  , showDiff: showDiff
110
- }, (Assertion.includeStack) ? this.assert : flag(this, 'ssfi'));
110
+ }, (config.includeStack) ? this.assert : flag(this, 'ssfi'));
111
111
  }
112
112
  };
113
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
+ };
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * chai
3
3
  * http://chaijs.com
4
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
4
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
5
5
  * MIT Licensed
6
6
  */
7
7
 
@@ -13,9 +13,9 @@ module.exports = function (chai, _) {
13
13
  /**
14
14
  * ### Language Chains
15
15
  *
16
- * The following are provide as chainable getters to
16
+ * The following are provided as chainable getters to
17
17
  * improve the readability of your assertions. They
18
- * do not provide an testing capability unless they
18
+ * do not provide testing capabilities unless they
19
19
  * have been overwritten by a plugin.
20
20
  *
21
21
  * **Chains**
@@ -26,6 +26,7 @@ module.exports = function (chai, _) {
26
26
  * - is
27
27
  * - that
28
28
  * - and
29
+ * - has
29
30
  * - have
30
31
  * - with
31
32
  * - at
@@ -37,7 +38,7 @@ module.exports = function (chai, _) {
37
38
  */
38
39
 
39
40
  [ 'to', 'be', 'been'
40
- , 'is', 'and', 'have'
41
+ , 'is', 'and', 'has', 'have'
41
42
  , 'with', 'that', 'at'
42
43
  , 'of', 'same' ].forEach(function (chain) {
43
44
  Assertion.addProperty(chain, function () {
@@ -145,9 +146,28 @@ module.exports = function (chai, _) {
145
146
 
146
147
  function include (val, msg) {
147
148
  if (msg) flag(this, 'message', msg);
148
- var obj = flag(this, 'object')
149
+ var obj = flag(this, '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') {
159
+ if (!flag(this, 'negate')) {
160
+ for (var k in val) new Assertion(obj).property(k, val[k]);
161
+ return;
162
+ }
163
+ var subset = {}
164
+ for (var k in val) subset[k] = obj[k]
165
+ expected = _.eql(subset, val);
166
+ } else {
167
+ expected = obj && ~obj.indexOf(val)
168
+ }
149
169
  this.assert(
150
- ~obj.indexOf(val)
170
+ expected
151
171
  , 'expected #{this} to include ' + _.inspect(val)
152
172
  , 'expected #{this} to not include ' + _.inspect(val));
153
173
  }
@@ -244,8 +264,8 @@ module.exports = function (chai, _) {
244
264
  *
245
265
  * Asserts that the target is `undefined`.
246
266
  *
247
- * expect(undefined).to.be.undefined;
248
- * expect(null).to.not.be.undefined;
267
+ * expect(undefined).to.be.undefined;
268
+ * expect(null).to.not.be.undefined;
249
269
  *
250
270
  * @name undefined
251
271
  * @api public
@@ -1002,6 +1022,7 @@ module.exports = function (chai, _) {
1002
1022
  * @param {String|RegExp} expected error message
1003
1023
  * @param {String} message _optional_
1004
1024
  * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
1025
+ * @returns error for chaining (null if no error)
1005
1026
  * @api public
1006
1027
  */
1007
1028
 
@@ -1026,7 +1047,10 @@ module.exports = function (chai, _) {
1026
1047
  constructor = null;
1027
1048
  errMsg = null;
1028
1049
  } else if (typeof constructor === 'function') {
1029
- name = (new constructor()).name;
1050
+ name = constructor.prototype.name || constructor.name;
1051
+ if (name === 'Error' && constructor !== Error) {
1052
+ name = (new constructor()).name;
1053
+ }
1030
1054
  } else {
1031
1055
  constructor = null;
1032
1056
  }
@@ -1040,12 +1064,14 @@ module.exports = function (chai, _) {
1040
1064
  err === desiredError
1041
1065
  , 'expected #{this} to throw #{exp} but #{act} was thrown'
1042
1066
  , 'expected #{this} to not throw #{exp}'
1043
- , desiredError
1044
- , err
1067
+ , (desiredError instanceof Error ? desiredError.toString() : desiredError)
1068
+ , (err instanceof Error ? err.toString() : err)
1045
1069
  );
1046
1070
 
1071
+ flag(this, 'object', err);
1047
1072
  return this;
1048
1073
  }
1074
+
1049
1075
  // next, check constructor
1050
1076
  if (constructor) {
1051
1077
  this.assert(
@@ -1053,11 +1079,15 @@ module.exports = function (chai, _) {
1053
1079
  , 'expected #{this} to throw #{exp} but #{act} was thrown'
1054
1080
  , 'expected #{this} to not throw #{exp} but #{act} was thrown'
1055
1081
  , name
1056
- , err
1082
+ , (err instanceof Error ? err.toString() : err)
1057
1083
  );
1058
1084
 
1059
- if (!errMsg) return this;
1085
+ if (!errMsg) {
1086
+ flag(this, 'object', err);
1087
+ return this;
1088
+ }
1060
1089
  }
1090
+
1061
1091
  // next, check message
1062
1092
  var message = 'object' === _.type(err) && "message" in err
1063
1093
  ? err.message
@@ -1072,6 +1102,7 @@ module.exports = function (chai, _) {
1072
1102
  , message
1073
1103
  );
1074
1104
 
1105
+ flag(this, 'object', err);
1075
1106
  return this;
1076
1107
  } else if ((message != null) && errMsg && 'string' === typeof errMsg) {
1077
1108
  this.assert(
@@ -1082,6 +1113,7 @@ module.exports = function (chai, _) {
1082
1113
  , message
1083
1114
  );
1084
1115
 
1116
+ flag(this, 'object', err);
1085
1117
  return this;
1086
1118
  } else {
1087
1119
  thrown = true;
@@ -1104,9 +1136,11 @@ module.exports = function (chai, _) {
1104
1136
  thrown === true
1105
1137
  , 'expected #{this} to throw ' + expectedThrown + actuallyGot
1106
1138
  , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
1107
- , desiredError
1108
- , thrownError
1139
+ , (desiredError instanceof Error ? desiredError.toString() : desiredError)
1140
+ , (thrownError instanceof Error ? thrownError.toString() : thrownError)
1109
1141
  );
1142
+
1143
+ flag(this, 'object', thrownError);
1110
1144
  };
1111
1145
 
1112
1146
  Assertion.addMethod('throw', assertThrows);
@@ -1125,8 +1159,8 @@ module.exports = function (chai, _) {
1125
1159
  * To check if a constructor will respond to a static function,
1126
1160
  * set the `itself` flag.
1127
1161
  *
1128
- * Klass.baz = function(){};
1129
- * expect(Klass).itself.to.respondTo('baz');
1162
+ * Klass.baz = function(){};
1163
+ * expect(Klass).itself.to.respondTo('baz');
1130
1164
  *
1131
1165
  * @name respondTo
1132
1166
  * @param {String} method
@@ -1154,12 +1188,12 @@ module.exports = function (chai, _) {
1154
1188
  *
1155
1189
  * Sets the `itself` flag, later used by the `respondTo` assertion.
1156
1190
  *
1157
- * function Foo() {}
1158
- * Foo.bar = function() {}
1159
- * Foo.prototype.baz = function() {}
1191
+ * function Foo() {}
1192
+ * Foo.bar = function() {}
1193
+ * Foo.prototype.baz = function() {}
1160
1194
  *
1161
- * expect(Foo).itself.to.respondTo('bar');
1162
- * expect(Foo).itself.not.to.respondTo('baz');
1195
+ * expect(Foo).itself.to.respondTo('bar');
1196
+ * expect(Foo).itself.not.to.respondTo('baz');
1163
1197
  *
1164
1198
  * @name itself
1165
1199
  * @api public
@@ -1218,9 +1252,13 @@ module.exports = function (chai, _) {
1218
1252
  );
1219
1253
  });
1220
1254
 
1221
- function isSubsetOf(subset, superset) {
1255
+ function isSubsetOf(subset, superset, cmp) {
1222
1256
  return subset.every(function(elem) {
1223
- 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
+ });
1224
1262
  })
1225
1263
  }
1226
1264
 
@@ -1228,7 +1266,9 @@ module.exports = function (chai, _) {
1228
1266
  * ### .members(set)
1229
1267
  *
1230
1268
  * Asserts that the target is a superset of `set`,
1231
- * 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.
1232
1272
  *
1233
1273
  * expect([1, 2, 3]).to.include.members([3, 2]);
1234
1274
  * expect([1, 2, 3]).to.not.include.members([3, 2, 8]);
@@ -1236,6 +1276,8 @@ module.exports = function (chai, _) {
1236
1276
  * expect([4, 2]).to.have.members([2, 4]);
1237
1277
  * expect([5, 2]).to.not.have.members([5, 2, 1]);
1238
1278
  *
1279
+ * expect([{ id: 1 }]).to.deep.include.members([{ id: 1 }]);
1280
+ *
1239
1281
  * @name members
1240
1282
  * @param {Array} set
1241
1283
  * @param {String} message _optional_
@@ -1249,9 +1291,11 @@ module.exports = function (chai, _) {
1249
1291
  new Assertion(obj).to.be.an('array');
1250
1292
  new Assertion(subset).to.be.an('array');
1251
1293
 
1294
+ var cmp = flag(this, 'deep') ? _.eql : undefined;
1295
+
1252
1296
  if (flag(this, 'contains')) {
1253
1297
  return this.assert(
1254
- isSubsetOf(subset, obj)
1298
+ isSubsetOf(subset, obj, cmp)
1255
1299
  , 'expected #{this} to be a superset of #{act}'
1256
1300
  , 'expected #{this} to not be a superset of #{act}'
1257
1301
  , obj
@@ -1260,7 +1304,7 @@ module.exports = function (chai, _) {
1260
1304
  }
1261
1305
 
1262
1306
  this.assert(
1263
- isSubsetOf(obj, subset) && isSubsetOf(subset, obj)
1307
+ isSubsetOf(obj, subset, cmp) && isSubsetOf(subset, obj, cmp)
1264
1308
  , 'expected #{this} to have the same members as #{act}'
1265
1309
  , 'expected #{this} to not have the same members as #{act}'
1266
1310
  , obj
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * chai
3
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -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
@@ -55,13 +55,12 @@ module.exports = function (chai, util) {
55
55
  */
56
56
 
57
57
  assert.fail = function (actual, expected, message, operator) {
58
- throw new chai.AssertionError({
58
+ message = message || 'assert.fail()';
59
+ throw new chai.AssertionError(message, {
59
60
  actual: actual
60
61
  , expected: expected
61
- , message: message
62
62
  , operator: operator
63
- , stackStartFunction: assert.fail
64
- });
63
+ }, assert.fail);
65
64
  };
66
65
 
67
66
  /**
@@ -115,7 +114,7 @@ module.exports = function (chai, util) {
115
114
  */
116
115
 
117
116
  assert.equal = function (act, exp, msg) {
118
- var test = new Assertion(act, msg);
117
+ var test = new Assertion(act, msg, assert.equal);
119
118
 
120
119
  test.assert(
121
120
  exp == flag(test, 'object')
@@ -141,7 +140,7 @@ module.exports = function (chai, util) {
141
140
  */
142
141
 
143
142
  assert.notEqual = function (act, exp, msg) {
144
- var test = new Assertion(act, msg);
143
+ var test = new Assertion(act, msg, assert.notEqual);
145
144
 
146
145
  test.assert(
147
146
  exp != flag(test, 'object')
@@ -392,8 +391,8 @@ module.exports = function (chai, util) {
392
391
  * Asserts that `value` is _not_ an object.
393
392
  *
394
393
  * var selection = 'chai'
395
- * assert.isObject(selection, 'tea selection is not an object');
396
- * assert.isObject(null, 'null is not an object');
394
+ * assert.isNotObject(selection, 'tea selection is not an object');
395
+ * assert.isNotObject(null, 'null is not an object');
397
396
  *
398
397
  * @name isNotObject
399
398
  * @param {Mixed} value
@@ -657,19 +656,7 @@ module.exports = function (chai, util) {
657
656
  */
658
657
 
659
658
  assert.include = function (exp, inc, msg) {
660
- var obj = new Assertion(exp, msg);
661
-
662
- if (Array.isArray(exp)) {
663
- obj.to.include(inc);
664
- } else if ('string' === typeof exp) {
665
- obj.to.contain.string(inc);
666
- } else {
667
- throw new chai.AssertionError(
668
- 'expected an array or string'
669
- , null
670
- , assert.include
671
- );
672
- }
659
+ new Assertion(exp, msg, assert.include).include(inc);
673
660
  };
674
661
 
675
662
  /**
@@ -689,19 +676,7 @@ module.exports = function (chai, util) {
689
676
  */
690
677
 
691
678
  assert.notInclude = function (exp, inc, msg) {
692
- var obj = new Assertion(exp, msg);
693
-
694
- if (Array.isArray(exp)) {
695
- obj.to.not.include(inc);
696
- } else if ('string' === typeof exp) {
697
- obj.to.not.contain.string(inc);
698
- } else {
699
- throw new chai.AssertionError(
700
- 'expected an array or string'
701
- , null
702
- , assert.notInclude
703
- );
704
- }
679
+ new Assertion(exp, msg, assert.notInclude).not.include(inc);
705
680
  };
706
681
 
707
682
  /**
@@ -945,7 +920,8 @@ module.exports = function (chai, util) {
945
920
  errt = null;
946
921
  }
947
922
 
948
- new Assertion(fn, msg).to.Throw(errt, errs);
923
+ var assertErr = new Assertion(fn, msg).to.Throw(errt, errs);
924
+ return flag(assertErr, 'object');
949
925
  };
950
926
 
951
927
  /**
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * chai
3
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * chai
3
- * Copyright(c) 2011-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -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
- set: function (value) {
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