Permalink
Browse files

fix browser tests

  • Loading branch information...
1 parent 4595c69 commit 6263e5a98bd08b857dea16017174b7507e5fa355 @oyyd oyyd committed Jan 5, 2016
Showing with 9,348 additions and 2,238 deletions.
  1. +1 −0 index.js
  2. +79 −49 tests/browser/expect.js
  3. +9,260 −2,181 tests/browser/mocha.js
  4. +2 −2 tests/filters.js
  5. +1 −1 tests/globals.js
  6. +2 −2 tests/lexer.js
  7. +3 −3 tests/parser.js
View
@@ -20,6 +20,7 @@ module.exports.parser = require('./src/parser');
module.exports.lexer = require('./src/lexer');
module.exports.runtime = require('./src/runtime');
module.exports.lib = lib;
+module.exports.nodes = require('./src/nodes');
module.exports.installJinjaCompat = require('./src/jinja-compat.js');
@@ -1,11 +1,6 @@
-
(function (global, module) {
- 'use strict';
- if ('undefined' === typeof module) {
- var module = { exports: {} }
- , exports = module.exports;
- }
+ var exports = module.exports;
/**
* Exports.
@@ -18,7 +13,7 @@
* Exports version.
*/
- expect.version = '0.1.2';
+ expect.version = '0.3.1';
/**
* Possible assertion flags.
@@ -57,7 +52,7 @@
}
var $flags = flag ? flags[flag] : keys(flags)
- , self = this
+ , self = this;
if ($flags) {
for (var i = 0, l = $flags.length; i < l; i++) {
@@ -72,7 +67,7 @@
var old = this[name];
this[name] = function () {
return old.apply(self, arguments);
- }
+ };
for (var fn in Assertion.prototype) {
if (Assertion.prototype.hasOwnProperty(fn) && fn != name) {
@@ -84,20 +79,27 @@
}
}
}
- };
+ }
/**
* Performs an assertion
*
* @api private
*/
- Assertion.prototype.assert = function (truth, msg, error) {
+ Assertion.prototype.assert = function (truth, msg, error, expected) {
var msg = this.flags.not ? error : msg
- , ok = this.flags.not ? !truth : truth;
+ , ok = this.flags.not ? !truth : truth
+ , err;
if (!ok) {
- throw new Error(msg.call(this));
+ err = new Error(msg.call(this));
+ if (arguments.length > 3) {
+ err.actual = this.obj;
+ err.expected = expected;
+ err.showDiff = true;
+ }
+ throw err;
}
this.and = new Assertion(this.obj);
@@ -117,6 +119,19 @@
};
/**
+ * Creates an anonymous function which calls fn with arguments.
+ *
+ * @api public
+ */
+
+ Assertion.prototype.withArgs = function() {
+ expect(this.obj).to.be.a('function');
+ var fn = this.obj;
+ var args = Array.prototype.slice.call(arguments);
+ return expect(function() { fn.apply(null, args); });
+ };
+
+ /**
* Assert that the function throws.
*
* @param {Function|RegExp} callback, or regexp to match error string against
@@ -128,25 +143,25 @@
expect(this.obj).to.be.a('function');
var thrown = false
- , not = this.flags.not
+ , not = this.flags.not;
try {
this.obj();
} catch (e) {
- if ('function' == typeof fn) {
- fn(e);
- } else if ('object' == typeof fn) {
+ if (isRegExp(fn)) {
var subject = 'string' == typeof e ? e : e.message;
if (not) {
expect(subject).to.not.match(fn);
} else {
expect(subject).to.match(fn);
}
+ } else if ('function' == typeof fn) {
+ fn(e);
}
thrown = true;
}
- if ('object' == typeof fn && not) {
+ if (isRegExp(fn) && not) {
// in the presence of a matcher, ensure the `not` only applies to
// the matching.
this.flags.not = false;
@@ -213,9 +228,10 @@
Assertion.prototype.eql = function (obj) {
this.assert(
- expect.eql(obj, this.obj)
+ expect.eql(this.obj, obj)
, function(){ return 'expected ' + i(this.obj) + ' to sort of equal ' + i(obj) }
- , function(){ return 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj) });
+ , function(){ return 'expected ' + i(this.obj) + ' to sort of not equal ' + i(obj) }
+ , obj);
return this;
};
@@ -251,9 +267,10 @@
// typeof with support for 'array'
this.assert(
'array' == type ? isArray(this.obj) :
- 'object' == type
- ? 'object' == typeof this.obj && null !== this.obj
- : type == typeof this.obj
+ 'regexp' == type ? isRegExp(this.obj) :
+ 'object' == type
+ ? 'object' == typeof this.obj && null !== this.obj
+ : type == typeof this.obj
, function(){ return 'expected ' + i(this.obj) + ' to be a' + n + ' ' + type }
, function(){ return 'expected ' + i(this.obj) + ' not to be a' + n + ' ' + type });
} else {
@@ -460,15 +477,16 @@
return this;
};
+
/**
* Assert a failure.
*
* @param {String ...} custom message
* @api public
*/
Assertion.prototype.fail = function (msg) {
- msg = msg || "explicit failure";
- this.assert(false, msg, msg);
+ var error = function() { return msg || "explicit failure"; }
+ this.assert(false, error, error);
return this;
};
@@ -497,7 +515,7 @@
}
}
return true;
- };
+ }
/**
* Array indexOf compatibility.
@@ -519,14 +537,13 @@
; i < j && arr[i] !== o; i++);
return j <= i ? -1 : i;
- };
+ }
// https://gist.github.com/1044128/
var getOuterHTML = function(element) {
if ('outerHTML' in element) return element.outerHTML;
var ns = "http://www.w3.org/1999/xhtml";
var container = document.createElementNS(ns, '_');
- var elemProto = (window.HTMLElement || window.Element).prototype;
var xmlSerializer = new XMLSerializer();
var html;
if (document.xmlVersion) {
@@ -563,7 +580,7 @@
function stylize (str) {
return str;
- };
+ }
function format (value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
@@ -621,6 +638,11 @@
return stylize(value.toUTCString(), 'date');
}
+ // Error objects can be shortcutted
+ if (value instanceof Error) {
+ return stylize("["+value.toString()+"]", 'Error');
+ }
+
var base, type, braces;
// Determine the object type
if (isArray(value)) {
@@ -741,11 +763,13 @@
return output;
}
return format(obj, (typeof depth === 'undefined' ? 2 : depth));
- };
+ }
+
+ expect.stringify = i;
function isArray (ar) {
- return Object.prototype.toString.call(ar) == '[object Array]';
- };
+ return Object.prototype.toString.call(ar) === '[object Array]';
+ }
function isRegExp(re) {
var s;
@@ -763,12 +787,11 @@
re.test &&
re.exec &&
s.match(/^\/.*\/[gim]{0,3}$/);
- };
+ }
function isDate(d) {
- if (d instanceof Date) return true;
- return false;
- };
+ return d instanceof Date;
+ }
function keys (obj) {
if (Object.keys) {
@@ -798,7 +821,7 @@
other[i] = mapper.call(that, arr[i], i, arr);
return other;
- };
+ }
function reduce (arr, fun) {
if (Array.prototype.reduce) {
@@ -839,7 +862,7 @@
}
return rv;
- };
+ }
/**
* Asserts deep equality
@@ -848,12 +871,12 @@
* @api private
*/
- expect.eql = function eql (actual, expected) {
+ expect.eql = function eql(actual, expected) {
// 7.1. All identical values are equivalent, as determined by ===.
if (actual === expected) {
return true;
} else if ('undefined' != typeof Buffer
- && Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
+ && Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
if (actual.length != expected.length) return false;
for (var i = 0; i < actual.length; i++) {
@@ -862,16 +885,19 @@
return true;
- // 7.2. If the expected value is a Date object, the actual value is
- // equivalent if it is also a Date object that refers to the same time.
+ // 7.2. If the expected value is a Date object, the actual value is
+ // equivalent if it is also a Date object that refers to the same time.
} else if (actual instanceof Date && expected instanceof Date) {
return actual.getTime() === expected.getTime();
- // 7.3. Other pairs that do not both pass typeof value == "object",
- // equivalence is determined by ==.
+ // 7.3. Other pairs that do not both pass typeof value == "object",
+ // equivalence is determined by ==.
} else if (typeof actual != 'object' && typeof expected != 'object') {
return actual == expected;
-
+ // If both are regular expression use the special `regExpEquiv` method
+ // to determine equivalence.
+ } else if (isRegExp(actual) && isRegExp(expected)) {
+ return regExpEquiv(actual, expected);
// 7.4. For all other Object pairs, including Array objects, equivalence is
// determined by having the same number of owned properties (as verified
// with Object.prototype.hasOwnProperty.call), the same set of keys
@@ -881,7 +907,7 @@
} else {
return objEquiv(actual, expected);
}
- }
+ };
function isUndefinedOrNull (value) {
return value === null || value === undefined;
@@ -891,6 +917,11 @@
return Object.prototype.toString.call(object) == '[object Arguments]';
}
+ function regExpEquiv (a, b) {
+ return a.source === b.source && a.global === b.global &&
+ a.ignoreCase === b.ignoreCase && a.multiline === b.multiline;
+ }
+
function objEquiv (a, b) {
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
return false;
@@ -959,7 +990,7 @@
f(d.getUTCHours()) + ':' +
f(d.getUTCMinutes()) + ':' +
f(d.getUTCSeconds()) + 'Z' : null;
- };
+ }
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
@@ -1249,6 +1280,5 @@
})(
this
- , 'undefined' != typeof module ? module : {}
- , 'undefined' != typeof exports ? exports : {}
+ , 'undefined' != typeof module ? module : {exports: {}}
);
Oops, something went wrong.

0 comments on commit 6263e5a

Please sign in to comment.