chai 1.8.0 → 1.9.2

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.
@@ -1,9 +1,11 @@
1
1
  /*!
2
2
  * Chai - addMethod utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
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
  };
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - addProperty utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - flag utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - getActual utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -14,6 +14,5 @@
14
14
  */
15
15
 
16
16
  module.exports = function (obj, args) {
17
- var actual = args[4];
18
- return 'undefined' !== typeof actual ? actual : obj._obj;
17
+ return args.length > 4 ? args[4] : obj._obj;
19
18
  };
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - getEnumerableProperties utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - message composition utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -39,6 +39,7 @@ module.exports = function (obj, args) {
39
39
  , msg = negate ? args[2] : args[1]
40
40
  , flagMsg = flag(obj, 'message');
41
41
 
42
+ if(typeof msg === "function") msg = msg();
42
43
  msg = msg || '';
43
44
  msg = msg
44
45
  .replace(/#{this}/g, objDisplay(val))
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - getName utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - getPathValue utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * @see https://github.com/logicalparadox/filtr
5
5
  * MIT Licensed
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - getProperties utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -106,3 +106,9 @@ exports.overwriteMethod = require('./overwriteMethod');
106
106
 
107
107
  exports.addChainableMethod = require('./addChainableMethod');
108
108
 
109
+ /*!
110
+ * Overwrite chainable method
111
+ */
112
+
113
+ exports.overwriteChainableMethod = require('./overwriteChainableMethod');
114
+
@@ -27,24 +27,6 @@ function inspect(obj, showHidden, depth, colors) {
27
27
  return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
28
28
  }
29
29
 
30
- // https://gist.github.com/1044128/
31
- var getOuterHTML = function(element) {
32
- if ('outerHTML' in element) return element.outerHTML;
33
- var ns = "http://www.w3.org/1999/xhtml";
34
- var container = document.createElementNS(ns, '_');
35
- var elemProto = (window.HTMLElement || window.Element).prototype;
36
- var xmlSerializer = new XMLSerializer();
37
- var html;
38
- if (document.xmlVersion) {
39
- return xmlSerializer.serializeToString(element);
40
- } else {
41
- container.appendChild(element.cloneNode(false));
42
- html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
43
- container.innerHTML = '';
44
- return html;
45
- }
46
- };
47
-
48
30
  // Returns true if object is a DOM element.
49
31
  var isDOMElement = function (object) {
50
32
  if (typeof HTMLElement === 'object') {
@@ -78,9 +60,37 @@ function formatValue(ctx, value, recurseTimes) {
78
60
  return primitive;
79
61
  }
80
62
 
81
- // If it's DOM elem, get outer HTML.
63
+ // If this is a DOM element, try to get the outer HTML.
82
64
  if (isDOMElement(value)) {
83
- return getOuterHTML(value);
65
+ if ('outerHTML' in value) {
66
+ return value.outerHTML;
67
+ // This value does not have an outerHTML attribute,
68
+ // it could still be an XML element
69
+ } else {
70
+ // Attempt to serialize it
71
+ try {
72
+ if (document.xmlVersion) {
73
+ var xmlSerializer = new XMLSerializer();
74
+ return xmlSerializer.serializeToString(value);
75
+ } else {
76
+ // Firefox 11- do not support outerHTML
77
+ // It does, however, support innerHTML
78
+ // Use the following to render the element
79
+ var ns = "http://www.w3.org/1999/xhtml";
80
+ var container = document.createElementNS(ns, '_');
81
+
82
+ container.appendChild(value.cloneNode(false));
83
+ html = container.innerHTML
84
+ .replace('><', '>' + value.innerHTML + '<');
85
+ container.innerHTML = '';
86
+ return html;
87
+ }
88
+ } catch (err) {
89
+ // This could be a non-native DOM implementation,
90
+ // continue with the normal flow:
91
+ // printing the element as if it is an object.
92
+ }
93
+ }
84
94
  }
85
95
 
86
96
  // Look up the keys of the object.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - flag utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -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 >= 40) {
30
+ if (config.truncateThreshold && str.length >= config.truncateThreshold) {
30
31
  if (type === '[object Function]') {
31
32
  return !obj.name || obj.name === ''
32
33
  ? '[Function]'
@@ -0,0 +1,53 @@
1
+ /*!
2
+ * Chai - overwriteChainableMethod utility
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
+ * MIT Licensed
5
+ */
6
+
7
+ /**
8
+ * ### overwriteChainableMethod (ctx, name, fn)
9
+ *
10
+ * Overwites an already existing chainable method
11
+ * and provides access to the previous function or
12
+ * property. Must return functions to be used for
13
+ * name.
14
+ *
15
+ * utils.overwriteChainableMethod(chai.Assertion.prototype, 'length',
16
+ * function (_super) {
17
+ * }
18
+ * , function (_super) {
19
+ * }
20
+ * );
21
+ *
22
+ * Can also be accessed directly from `chai.Assertion`.
23
+ *
24
+ * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
25
+ *
26
+ * Then can be used as any other assertion.
27
+ *
28
+ * expect(myFoo).to.have.length(3);
29
+ * expect(myFoo).to.have.length.above(3);
30
+ *
31
+ * @param {Object} ctx object whose method / property is to be overwritten
32
+ * @param {String} name of method / property to overwrite
33
+ * @param {Function} method function that returns a function to be used for name
34
+ * @param {Function} chainingBehavior function that returns a function to be used for property
35
+ * @name overwriteChainableMethod
36
+ * @api public
37
+ */
38
+
39
+ module.exports = function (ctx, name, method, chainingBehavior) {
40
+ var chainableBehavior = ctx.__methods[name];
41
+
42
+ var _chainingBehavior = chainableBehavior.chainingBehavior;
43
+ chainableBehavior.chainingBehavior = function () {
44
+ var result = chainingBehavior(_chainingBehavior).call(this);
45
+ return result === undefined ? this : result;
46
+ };
47
+
48
+ var _method = chainableBehavior.method;
49
+ chainableBehavior.method = function () {
50
+ var result = method(_method).apply(this, arguments);
51
+ return result === undefined ? this : result;
52
+ };
53
+ };
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - overwriteMethod utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - overwriteProperty utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - test utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - transferFlags utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * Chai - type utility
3
- * Copyright(c) 2012-2013 Jake Luer <jake@alogicalparadox.com>
3
+ * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
4
4
  * MIT Licensed
5
5
  */
6
6
 
package/lib/chai.js CHANGED
@@ -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
 
@@ -11,7 +11,7 @@ var used = []
11
11
  * Chai version
12
12
  */
13
13
 
14
- exports.version = '1.8.0';
14
+ exports.version = '1.9.2';
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.8.0",
14
+ "version": "1.9.2",
15
15
  "repository": {
16
16
  "type": "git",
17
17
  "url": "https://github.com/chaijs/chai"
@@ -28,16 +28,15 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "assertion-error": "1.0.0"
31
- , "deep-eql": "0.1.2"
31
+ , "deep-eql": "0.1.3"
32
32
  },
33
33
  "devDependencies": {
34
34
  "component": "*"
35
- , "coveralls": "2.0.16"
36
- , "jscoverage": "0.3.7"
37
- , "karma": "canary"
35
+ , "karma": "0.12.x"
38
36
  , "karma-mocha": "*"
39
- , "karma-sauce-launcher": "git://github.com/embarkmobile/karma-sauce-launcher.git#feature-passfail"
40
- , "mocha": "1.8.2"
41
- , "mocha-lcov-reporter": "0.0.1"
37
+ , "karma-sauce-launcher": "0.2.x"
38
+ , "karma-phantomjs-launcher": "0.1.1"
39
+ , "mocha": "1.21.x"
40
+ , "istanbul": "0.2.x"
42
41
  }
43
42
  }