Upgrade Jasmine to 2.2.0

Change-Id: Ifb73f24ba78238e02e860a1a6402261c09d6c006
This commit is contained in:
woomatt 2015-06-08 15:01:28 -06:00
parent a55f5db1db
commit 0274ed3433
5 changed files with 326 additions and 174 deletions

View File

@ -11,10 +11,10 @@ NAME = __name__.split('.')[-1] # package name (e.g. 'foo' or 'foo_bar')
# please use a all-lowercase valid python # please use a all-lowercase valid python
# package name # package name
VERSION = '2.1.2' # version of the packaged files, please use the upstream VERSION = '2.2.0' # version of the packaged files, please use the upstream
# version number # version number
BUILD = '0' # our package build number, so we can release new builds BUILD = '0' # our package build number, so we can release new builds
# with fixes for xstatic stuff. # with fixes for xstatic stuff.
PACKAGE_VERSION = VERSION + '.' + BUILD # version used for PyPi PACKAGE_VERSION = VERSION + '.' + BUILD # version used for PyPi
DESCRIPTION = "%s %s (XStatic packaging standard)" % (DISPLAY_NAME, VERSION) DESCRIPTION = "%s %s (XStatic packaging standard)" % (DISPLAY_NAME, VERSION)

View File

@ -62,7 +62,8 @@
*/ */
var htmlReporter = new jasmine.HtmlReporter({ var htmlReporter = new jasmine.HtmlReporter({
env: env, env: env,
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); }, onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); },
addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); },
getContainer: function() { return document.body; }, getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); }, createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }, createTextNode: function() { return document.createTextNode.apply(document, arguments); },

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2008-2014 Pivotal Labs Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2008-2014 Pivotal Labs Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
@ -40,6 +40,7 @@ jasmineRequire.HtmlReporter = function(j$) {
createElement = options.createElement, createElement = options.createElement,
createTextNode = options.createTextNode, createTextNode = options.createTextNode,
onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
addToExistingQueryString = options.addToExistingQueryString || defaultQueryString,
timer = options.timer || noopTimer, timer = options.timer || noopTimer,
results = [], results = [],
specsExecuted = 0, specsExecuted = 0,
@ -220,6 +221,9 @@ jasmineRequire.HtmlReporter = function(j$) {
if(noExpectations(resultNode.result)) { if(noExpectations(resultNode.result)) {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
} }
if(resultNode.result.status === 'pending' && resultNode.result.pendingReason !== '') {
specDescription = specDescription + ' PENDING WITH MESSAGE: ' + resultNode.result.pendingReason;
}
specListNode.appendChild( specListNode.appendChild(
createDom('li', { createDom('li', {
className: resultNode.result.status, className: resultNode.result.status,
@ -267,7 +271,7 @@ jasmineRequire.HtmlReporter = function(j$) {
function clearPrior() { function clearPrior() {
// return the reporter // return the reporter
var oldReporter = find(''); var oldReporter = find('');
if(oldReporter) { if(oldReporter) {
getContainer().removeChild(oldReporter); getContainer().removeChild(oldReporter);
} }
@ -306,7 +310,11 @@ jasmineRequire.HtmlReporter = function(j$) {
} }
function specHref(result) { function specHref(result) {
return '?spec=' + encodeURIComponent(result.fullName); return addToExistingQueryString('spec', result.fullName);
}
function defaultQueryString(key, value) {
return '?' + key + '=' + value;
} }
function setMenuModeTo(mode) { function setMenuModeTo(mode) {
@ -358,10 +366,14 @@ jasmineRequire.ResultsNode = function() {
jasmineRequire.QueryString = function() { jasmineRequire.QueryString = function() {
function QueryString(options) { function QueryString(options) {
this.setParam = function(key, value) { this.navigateWithNewParam = function(key, value) {
options.getWindowLocation().search = this.fullStringWithNewParam(key, value);
};
this.fullStringWithNewParam = function(key, value) {
var paramMap = queryStringToParamMap(); var paramMap = queryStringToParamMap();
paramMap[key] = value; paramMap[key] = value;
options.getWindowLocation().search = toQueryString(paramMap); return toQueryString(paramMap);
}; };
this.getParam = function(key) { this.getParam = function(key) {

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2008-2014 Pivotal Labs Copyright (c) 2008-2015 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the
@ -20,13 +20,16 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
getJasmineRequireObj = (function (jasmineGlobal) { var getJasmineRequireObj = (function (jasmineGlobal) {
var jasmineRequire; var jasmineRequire;
if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
jasmineGlobal = global; jasmineGlobal = global;
jasmineRequire = exports; jasmineRequire = exports;
} else { } else {
if (typeof window !== 'undefined' && typeof window.toString === 'function' && window.toString() === '[object GjsGlobal]') {
jasmineGlobal = window;
}
jasmineRequire = jasmineGlobal.jasmineRequire = jasmineGlobal.jasmineRequire || {}; jasmineRequire = jasmineGlobal.jasmineRequire = jasmineGlobal.jasmineRequire || {};
} }
@ -40,6 +43,7 @@ getJasmineRequireObj = (function (jasmineGlobal) {
jRequire.base(j$, jasmineGlobal); jRequire.base(j$, jasmineGlobal);
j$.util = jRequire.util(); j$.util = jRequire.util();
j$.Any = jRequire.Any(); j$.Any = jRequire.Any();
j$.Anything = jRequire.Anything(j$);
j$.CallTracker = jRequire.CallTracker(); j$.CallTracker = jRequire.CallTracker();
j$.MockDate = jRequire.MockDate(); j$.MockDate = jRequire.MockDate();
j$.Clock = jRequire.Clock(); j$.Clock = jRequire.Clock();
@ -51,12 +55,14 @@ getJasmineRequireObj = (function (jasmineGlobal) {
j$.JsApiReporter = jRequire.JsApiReporter(); j$.JsApiReporter = jRequire.JsApiReporter();
j$.matchersUtil = jRequire.matchersUtil(j$); j$.matchersUtil = jRequire.matchersUtil(j$);
j$.ObjectContaining = jRequire.ObjectContaining(j$); j$.ObjectContaining = jRequire.ObjectContaining(j$);
j$.ArrayContaining = jRequire.ArrayContaining(j$);
j$.pp = jRequire.pp(j$); j$.pp = jRequire.pp(j$);
j$.QueueRunner = jRequire.QueueRunner(j$); j$.QueueRunner = jRequire.QueueRunner(j$);
j$.ReportDispatcher = jRequire.ReportDispatcher(); j$.ReportDispatcher = jRequire.ReportDispatcher();
j$.Spec = jRequire.Spec(j$); j$.Spec = jRequire.Spec(j$);
j$.SpyRegistry = jRequire.SpyRegistry(j$); j$.SpyRegistry = jRequire.SpyRegistry(j$);
j$.SpyStrategy = jRequire.SpyStrategy(); j$.SpyStrategy = jRequire.SpyStrategy();
j$.StringMatching = jRequire.StringMatching(j$);
j$.Suite = jRequire.Suite(); j$.Suite = jRequire.Suite();
j$.Timer = jRequire.Timer(); j$.Timer = jRequire.Timer();
j$.version = jRequire.version(); j$.version = jRequire.version();
@ -138,14 +144,30 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
return obj.nodeType > 0; return obj.nodeType > 0;
}; };
j$.fnNameFor = function(func) {
return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
};
j$.any = function(clazz) { j$.any = function(clazz) {
return new j$.Any(clazz); return new j$.Any(clazz);
}; };
j$.anything = function() {
return new j$.Anything();
};
j$.objectContaining = function(sample) { j$.objectContaining = function(sample) {
return new j$.ObjectContaining(sample); return new j$.ObjectContaining(sample);
}; };
j$.stringMatching = function(expected) {
return new j$.StringMatching(expected);
};
j$.arrayContaining = function(sample) {
return new j$.ArrayContaining(sample);
};
j$.createSpy = function(name, originalFn) { j$.createSpy = function(name, originalFn) {
var spyStrategy = new j$.SpyStrategy({ var spyStrategy = new j$.SpyStrategy({
@ -190,6 +212,11 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
}; };
j$.createSpyObj = function(baseName, methodNames) { j$.createSpyObj = function(baseName, methodNames) {
if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) {
methodNames = baseName;
baseName = 'unknown';
}
if (!j$.isArray_(methodNames) || methodNames.length === 0) { if (!j$.isArray_(methodNames) || methodNames.length === 0) {
throw 'createSpyObj requires a non-empty array of method names to create spies for'; throw 'createSpyObj requires a non-empty array of method names to create spies for';
} }
@ -285,7 +312,8 @@ getJasmineRequireObj().Spec = function(j$) {
description: this.description, description: this.description,
fullName: this.getFullName(), fullName: this.getFullName(),
failedExpectations: [], failedExpectations: [],
passedExpectations: [] passedExpectations: [],
pendingReason: ''
}; };
} }
@ -334,7 +362,7 @@ getJasmineRequireObj().Spec = function(j$) {
Spec.prototype.onException = function onException(e) { Spec.prototype.onException = function onException(e) {
if (Spec.isPendingSpecException(e)) { if (Spec.isPendingSpecException(e)) {
this.pend(); this.pend(extractCustomPendingMessage(e));
return; return;
} }
@ -351,8 +379,11 @@ getJasmineRequireObj().Spec = function(j$) {
this.disabled = true; this.disabled = true;
}; };
Spec.prototype.pend = function() { Spec.prototype.pend = function(message) {
this.markedPending = true; this.markedPending = true;
if (message) {
this.result.pendingReason = message;
}
}; };
Spec.prototype.status = function() { Spec.prototype.status = function() {
@ -379,6 +410,14 @@ getJasmineRequireObj().Spec = function(j$) {
return this.getSpecName(this); return this.getSpecName(this);
}; };
var extractCustomPendingMessage = function(e) {
var fullMessage = e.toString(),
boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage),
boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length;
return fullMessage.substr(boilerplateEnd);
};
Spec.pendingSpecExceptionMessage = '=> marked Pending'; Spec.pendingSpecExceptionMessage = '=> marked Pending';
Spec.isPendingSpecException = function(e) { Spec.isPendingSpecException = function(e) {
@ -573,13 +612,7 @@ getJasmineRequireObj().Env = function(j$) {
env: this, env: this,
id: getNextSuiteId(), id: getNextSuiteId(),
description: 'Jasmine__TopLevel__Suite', description: 'Jasmine__TopLevel__Suite',
queueRunner: queueRunnerFactory, queueRunner: queueRunnerFactory
onStart: function(suite) {
reporter.suiteStarted(suite.result);
},
resultCallback: function(attrs) {
reporter.suiteDone(attrs);
}
}); });
runnableLookupTable[topSuite.id] = topSuite; runnableLookupTable[topSuite.id] = topSuite;
defaultResourcesForRunnable(topSuite.id); defaultResourcesForRunnable(topSuite.id);
@ -637,11 +670,12 @@ getJasmineRequireObj().Env = function(j$) {
onStart: suiteStarted, onStart: suiteStarted,
expectationFactory: expectationFactory, expectationFactory: expectationFactory,
expectationResultFactory: expectationResultFactory, expectationResultFactory: expectationResultFactory,
runnablesExplictlySetGetter: runnablesExplictlySetGetter,
resultCallback: function(attrs) { resultCallback: function(attrs) {
if (!suite.disabled) { if (!suite.disabled) {
clearResourcesForRunnable(suite.id); clearResourcesForRunnable(suite.id);
currentlyExecutingSuites.pop();
} }
currentlyExecutingSuites.pop();
reporter.suiteDone(attrs); reporter.suiteDone(attrs);
} }
}); });
@ -829,8 +863,12 @@ getJasmineRequireObj().Env = function(j$) {
}); });
}; };
this.pending = function() { this.pending = function(message) {
throw j$.Spec.pendingSpecExceptionMessage; var fullMessage = j$.Spec.pendingSpecExceptionMessage;
if(message) {
fullMessage += message;
}
throw fullMessage;
}; };
this.fail = function(error) { this.fail = function(error) {
@ -845,7 +883,8 @@ getJasmineRequireObj().Env = function(j$) {
passed: false, passed: false,
expected: '', expected: '',
actual: '', actual: '',
message: message message: message,
error: error && error.message ? error : null
}); });
}; };
} }
@ -932,43 +971,6 @@ getJasmineRequireObj().JsApiReporter = function() {
return JsApiReporter; return JsApiReporter;
}; };
getJasmineRequireObj().Any = function() {
function Any(expectedObject) {
this.expectedObject = expectedObject;
}
Any.prototype.jasmineMatches = function(other) {
if (this.expectedObject == String) {
return typeof other == 'string' || other instanceof String;
}
if (this.expectedObject == Number) {
return typeof other == 'number' || other instanceof Number;
}
if (this.expectedObject == Function) {
return typeof other == 'function' || other instanceof Function;
}
if (this.expectedObject == Object) {
return typeof other == 'object';
}
if (this.expectedObject == Boolean) {
return typeof other == 'boolean';
}
return other instanceof this.expectedObject;
};
Any.prototype.jasmineToString = function() {
return '<jasmine.any(' + this.expectedObject + ')>';
};
return Any;
};
getJasmineRequireObj().CallTracker = function() { getJasmineRequireObj().CallTracker = function() {
function CallTracker() { function CallTracker() {
@ -1250,6 +1252,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
scheduledFn.runAtMillis + scheduledFn.millis); scheduledFn.runAtMillis + scheduledFn.millis);
} }
function forEachFunction(funcsToRun, callback) {
for (var i = 0; i < funcsToRun.length; ++i) {
callback(funcsToRun[i]);
}
}
function runScheduledFunctions(endTime) { function runScheduledFunctions(endTime) {
if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
return; return;
@ -1261,15 +1269,15 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() {
var funcsToRun = scheduledFunctions[currentTime]; var funcsToRun = scheduledFunctions[currentTime];
delete scheduledFunctions[currentTime]; delete scheduledFunctions[currentTime];
for (var i = 0; i < funcsToRun.length; ++i) { forEachFunction(funcsToRun, function(funcToRun) {
var funcToRun = funcsToRun[i];
if (funcToRun.recurring) { if (funcToRun.recurring) {
reschedule(funcToRun); reschedule(funcToRun);
} }
});
forEachFunction(funcsToRun, function(funcToRun) {
funcToRun.funcToCall.apply(null, funcToRun.params || []); funcToRun.funcToCall.apply(null, funcToRun.params || []);
} });
} while (scheduledLookup.length > 0 && } while (scheduledLookup.length > 0 &&
// checking first if we're out of time prevents setTimeout(0) // checking first if we're out of time prevents setTimeout(0)
// scheduled in a funcToRun from forcing an extra iteration // scheduled in a funcToRun from forcing an extra iteration
@ -1411,15 +1419,20 @@ getJasmineRequireObj().buildExpectationResult = function() {
var messageFormatter = options.messageFormatter || function() {}, var messageFormatter = options.messageFormatter || function() {},
stackFormatter = options.stackFormatter || function() {}; stackFormatter = options.stackFormatter || function() {};
return { var result = {
matcherName: options.matcherName, matcherName: options.matcherName,
expected: options.expected,
actual: options.actual,
message: message(), message: message(),
stack: stack(), stack: stack(),
passed: options.passed passed: options.passed
}; };
if(!result.passed) {
result.expected = options.expected;
result.actual = options.actual;
}
return result;
function message() { function message() {
if (options.passed) { if (options.passed) {
return 'Passed.'; return 'Passed.';
@ -1507,7 +1520,7 @@ getJasmineRequireObj().MockDate = function() {
case 6: case 6:
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
arguments[4], arguments[5]); arguments[4], arguments[5]);
case 7: default:
return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
arguments[4], arguments[5], arguments[6]); arguments[4], arguments[5], arguments[6]);
} }
@ -1534,41 +1547,6 @@ getJasmineRequireObj().MockDate = function() {
return MockDate; return MockDate;
}; };
getJasmineRequireObj().ObjectContaining = function(j$) {
function ObjectContaining(sample) {
this.sample = sample;
}
ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
mismatchKeys = mismatchKeys || [];
mismatchValues = mismatchValues || [];
var hasKey = function(obj, keyName) {
return obj !== null && !j$.util.isUndefined(obj[keyName]);
};
for (var property in this.sample) {
if (!hasKey(other, property) && hasKey(this.sample, property)) {
mismatchKeys.push('expected has key \'' + property + '\', but missing from actual.');
}
else if (!j$.matchersUtil.equals(other[property], this.sample[property])) {
mismatchValues.push('\'' + property + '\' was \'' + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + '\' in actual, but was \'' + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + '\' in expected.');
}
}
return (mismatchKeys.length === 0 && mismatchValues.length === 0);
};
ObjectContaining.prototype.jasmineToString = function() {
return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
};
return ObjectContaining;
};
getJasmineRequireObj().pp = function(j$) { getJasmineRequireObj().pp = function(j$) {
function PrettyPrinter() { function PrettyPrinter() {
@ -1668,13 +1646,15 @@ getJasmineRequireObj().pp = function(j$) {
}; };
StringPrettyPrinter.prototype.emitObject = function(obj) { StringPrettyPrinter.prototype.emitObject = function(obj) {
var constructorName = obj.constructor ? j$.fnNameFor(obj.constructor) : 'null';
this.append(constructorName);
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
this.append('Object');
return; return;
} }
var self = this; var self = this;
this.append('{ '); this.append('({ ');
var first = true; var first = true;
this.iterateObject(obj, function(property, isGetter) { this.iterateObject(obj, function(property, isGetter) {
@ -1693,7 +1673,7 @@ getJasmineRequireObj().pp = function(j$) {
} }
}); });
this.append(' }'); this.append(' })');
}; };
StringPrettyPrinter.prototype.append = function(value) { StringPrettyPrinter.prototype.append = function(value) {
@ -1743,7 +1723,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var queueableFn = queueableFns[iterativeIndex]; var queueableFn = queueableFns[iterativeIndex];
if (queueableFn.fn.length > 0) { if (queueableFn.fn.length > 0) {
return attemptAsync(queueableFn); attemptAsync(queueableFn);
return;
} else { } else {
attemptSync(queueableFn); attemptSync(queueableFn);
} }
@ -1858,6 +1839,10 @@ getJasmineRequireObj().SpyRegistry = function(j$) {
throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()'); throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()');
} }
if (j$.util.isUndefined(methodName)) {
throw new Error('No method name supplied');
}
if (j$.util.isUndefined(obj[methodName])) { if (j$.util.isUndefined(obj[methodName])) {
throw new Error(methodName + '() method does not exist'); throw new Error(methodName + '() method does not exist');
} }
@ -1964,6 +1949,7 @@ getJasmineRequireObj().Suite = function() {
this.clearStack = attrs.clearStack || function(fn) {fn();}; this.clearStack = attrs.clearStack || function(fn) {fn();};
this.expectationFactory = attrs.expectationFactory; this.expectationFactory = attrs.expectationFactory;
this.expectationResultFactory = attrs.expectationResultFactory; this.expectationResultFactory = attrs.expectationResultFactory;
this.runnablesExplictlySetGetter = attrs.runnablesExplictlySetGetter || function() {};
this.beforeFns = []; this.beforeFns = [];
this.afterFns = []; this.afterFns = [];
@ -2075,14 +2061,8 @@ getJasmineRequireObj().Suite = function() {
}; };
Suite.prototype.isExecutable = function() { Suite.prototype.isExecutable = function() {
var foundActive = false; var runnablesExplicitlySet = this.runnablesExplictlySetGetter();
for(var i = 0; i < this.children.length; i++) { return !runnablesExplicitlySet && hasExecutableChild(this.children);
if(this.children[i].isExecutable()) {
foundActive = true;
break;
}
}
return foundActive;
}; };
Suite.prototype.sharedUserContext = function() { Suite.prototype.sharedUserContext = function() {
@ -2135,6 +2115,17 @@ getJasmineRequireObj().Suite = function() {
return !args[0]; return !args[0];
} }
function hasExecutableChild(children) {
var foundActive = false;
for (var i = 0; i < children.length; i++) {
if (children[i].isExecutable()) {
foundActive = true;
break;
}
}
return foundActive;
}
function clone(obj) { function clone(obj) {
var clonedObj = {}; var clonedObj = {};
for (var prop in obj) { for (var prop in obj) {
@ -2176,6 +2167,131 @@ getJasmineRequireObj().Timer = function() {
return Timer; return Timer;
}; };
getJasmineRequireObj().Any = function() {
function Any(expectedObject) {
this.expectedObject = expectedObject;
}
Any.prototype.asymmetricMatch = function(other) {
if (this.expectedObject == String) {
return typeof other == 'string' || other instanceof String;
}
if (this.expectedObject == Number) {
return typeof other == 'number' || other instanceof Number;
}
if (this.expectedObject == Function) {
return typeof other == 'function' || other instanceof Function;
}
if (this.expectedObject == Object) {
return typeof other == 'object';
}
if (this.expectedObject == Boolean) {
return typeof other == 'boolean';
}
return other instanceof this.expectedObject;
};
Any.prototype.jasmineToString = function() {
return '<jasmine.any(' + this.expectedObject + ')>';
};
return Any;
};
getJasmineRequireObj().Anything = function(j$) {
function Anything() {}
Anything.prototype.asymmetricMatch = function(other) {
return !j$.util.isUndefined(other) && other !== null;
};
Anything.prototype.jasmineToString = function() {
return '<jasmine.anything>';
};
return Anything;
};
getJasmineRequireObj().ArrayContaining = function(j$) {
function ArrayContaining(sample) {
this.sample = sample;
}
ArrayContaining.prototype.asymmetricMatch = function(other) {
var className = Object.prototype.toString.call(this.sample);
if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); }
for (var i = 0; i < this.sample.length; i++) {
var item = this.sample[i];
if (!j$.matchersUtil.contains(other, item)) {
return false;
}
}
return true;
};
ArrayContaining.prototype.jasmineToString = function () {
return '<jasmine.arrayContaining(' + jasmine.pp(this.sample) +')>';
};
return ArrayContaining;
};
getJasmineRequireObj().ObjectContaining = function(j$) {
function ObjectContaining(sample) {
this.sample = sample;
}
ObjectContaining.prototype.asymmetricMatch = function(other) {
if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
for (var property in this.sample) {
if (!Object.prototype.hasOwnProperty.call(other, property) ||
!j$.matchersUtil.equals(this.sample[property], other[property])) {
return false;
}
}
return true;
};
ObjectContaining.prototype.jasmineToString = function() {
return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
};
return ObjectContaining;
};
getJasmineRequireObj().StringMatching = function(j$) {
function StringMatching(expected) {
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
throw new Error('Expected is not a String or a RegExp');
}
this.regexp = new RegExp(expected);
}
StringMatching.prototype.asymmetricMatch = function(other) {
return this.regexp.test(other);
};
StringMatching.prototype.jasmineToString = function() {
return '<jasmine.stringMatching(' + this.regexp + ')>';
};
return StringMatching;
};
getJasmineRequireObj().matchersUtil = function(j$) { getJasmineRequireObj().matchersUtil = function(j$) {
// TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter? // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter?
@ -2229,11 +2345,37 @@ getJasmineRequireObj().matchersUtil = function(j$) {
} }
}; };
function isAsymmetric(obj) {
return obj && j$.isA_('Function', obj.asymmetricMatch);
}
function asymmetricMatch(a, b) {
var asymmetricA = isAsymmetric(a),
asymmetricB = isAsymmetric(b);
if (asymmetricA && asymmetricB) {
return undefined;
}
if (asymmetricA) {
return a.asymmetricMatch(b);
}
if (asymmetricB) {
return b.asymmetricMatch(a);
}
}
// Equality function lovingly adapted from isEqual in // Equality function lovingly adapted from isEqual in
// [Underscore](http://underscorejs.org) // [Underscore](http://underscorejs.org)
function eq(a, b, aStack, bStack, customTesters) { function eq(a, b, aStack, bStack, customTesters) {
var result = true; var result = true;
var asymmetricResult = asymmetricMatch(a, b);
if (!j$.util.isUndefined(asymmetricResult)) {
return asymmetricResult;
}
for (var i = 0; i < customTesters.length; i++) { for (var i = 0; i < customTesters.length; i++) {
var customTesterResult = customTesters[i](a, b); var customTesterResult = customTesters[i](a, b);
if (!j$.util.isUndefined(customTesterResult)) { if (!j$.util.isUndefined(customTesterResult)) {
@ -2241,27 +2383,6 @@ getJasmineRequireObj().matchersUtil = function(j$) {
} }
} }
if (a instanceof j$.Any) {
result = a.jasmineMatches(b);
if (result) {
return true;
}
}
if (b instanceof j$.Any) {
result = b.jasmineMatches(a);
if (result) {
return true;
}
}
if (b instanceof j$.ObjectContaining) {
result = b.jasmineMatches(a);
if (result) {
return true;
}
}
if (a instanceof Error && b instanceof Error) { if (a instanceof Error && b instanceof Error) {
return a.message == b.message; return a.message == b.message;
} }
@ -2297,6 +2418,29 @@ getJasmineRequireObj().matchersUtil = function(j$) {
a.ignoreCase == b.ignoreCase; a.ignoreCase == b.ignoreCase;
} }
if (typeof a != 'object' || typeof b != 'object') { return false; } if (typeof a != 'object' || typeof b != 'object') { return false; }
var aIsDomNode = j$.isDomNode(a);
var bIsDomNode = j$.isDomNode(b);
if (aIsDomNode && bIsDomNode) {
// At first try to use DOM3 method isEqualNode
if (a.isEqualNode) {
return a.isEqualNode(b);
}
// IE8 doesn't support isEqualNode, try to use outerHTML && innerText
var aIsElement = a instanceof Element;
var bIsElement = b instanceof Element;
if (aIsElement && bIsElement) {
return a.outerHTML == b.outerHTML;
}
if (aIsElement || bIsElement) {
return false;
}
return a.innerText == b.innerText && a.textContent == b.textContent;
}
if (aIsDomNode || bIsDomNode) {
return false;
}
// Assume equality for cyclic structures. The algorithm for detecting cyclic // Assume equality for cyclic structures. The algorithm for detecting cyclic
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
var length = aStack.length; var length = aStack.length;
@ -2310,17 +2454,12 @@ getJasmineRequireObj().matchersUtil = function(j$) {
bStack.push(b); bStack.push(b);
var size = 0; var size = 0;
// Recursively compare objects and arrays. // Recursively compare objects and arrays.
if (className == '[object Array]') { // Compare array lengths to determine if a deep comparison is necessary.
// Compare array lengths to determine if a deep comparison is necessary. if (className == '[object Array]' && a.length !== b.length) {
size = a.length; result = false;
result = size == b.length; }
if (result) {
// Deep compare the contents, ignoring non-numeric properties. if (result) {
while (size--) {
if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; }
}
}
} else {
// Objects with different constructors are not equivalent, but `Object`s // Objects with different constructors are not equivalent, but `Object`s
// from different frames are. // from different frames are.
var aCtor = a.constructor, bCtor = b.constructor; var aCtor = a.constructor, bCtor = b.constructor;
@ -2352,7 +2491,7 @@ getJasmineRequireObj().matchersUtil = function(j$) {
return result; return result;
function has(obj, key) { function has(obj, key) {
return obj.hasOwnProperty(key); return Object.prototype.hasOwnProperty.call(obj, key);
} }
function isFunction(obj) { function isFunction(obj) {
@ -2621,11 +2760,15 @@ getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
return toHaveBeenCalledWith; return toHaveBeenCalledWith;
}; };
getJasmineRequireObj().toMatch = function() { getJasmineRequireObj().toMatch = function(j$) {
function toMatch() { function toMatch() {
return { return {
compare: function(actual, expected) { compare: function(actual, expected) {
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
throw new Error('Expected is not a String or a RegExp');
}
var regexp = new RegExp(expected); var regexp = new RegExp(expected);
return { return {
@ -2718,7 +2861,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
} }
if (errorMatcher.hasNoSpecifics()) { if (errorMatcher.hasNoSpecifics()) {
pass.message = 'Expected function not to throw an Error, but it threw ' + fnNameFor(thrown) + '.'; pass.message = 'Expected function not to throw an Error, but it threw ' + j$.fnNameFor(thrown) + '.';
return pass; return pass;
} }
@ -2772,9 +2915,9 @@ getJasmineRequireObj().toThrowError = function(j$) {
} }
return { return {
errorTypeDescription: errorType ? fnNameFor(errorType) : 'an exception', errorTypeDescription: errorType ? j$.fnNameFor(errorType) : 'an exception',
thrownDescription: function(thrown) { thrownDescription: function(thrown) {
var thrownName = errorType ? fnNameFor(thrown.constructor) : 'an exception', var thrownName = errorType ? j$.fnNameFor(thrown.constructor) : 'an exception',
thrownMessage = ''; thrownMessage = '';
if (expected) { if (expected) {
@ -2802,10 +2945,6 @@ getJasmineRequireObj().toThrowError = function(j$) {
}; };
} }
function fnNameFor(func) {
return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
}
function isStringOrRegExp(potential) { function isStringOrRegExp(potential) {
return potential instanceof RegExp || (typeof potential == 'string'); return potential instanceof RegExp || (typeof potential == 'string');
} }
@ -2838,32 +2977,32 @@ getJasmineRequireObj().interface = function(jasmine, env) {
return env.fdescribe(description, specDefinitions); return env.fdescribe(description, specDefinitions);
}, },
it: function(desc, func) { it: function() {
return env.it(desc, func); return env.it.apply(env, arguments);
}, },
xit: function(desc, func) { xit: function() {
return env.xit(desc, func); return env.xit.apply(env, arguments);
}, },
fit: function(desc, func) { fit: function() {
return env.fit(desc, func); return env.fit.apply(env, arguments);
}, },
beforeEach: function(beforeEachFunction) { beforeEach: function() {
return env.beforeEach(beforeEachFunction); return env.beforeEach.apply(env, arguments);
}, },
afterEach: function(afterEachFunction) { afterEach: function() {
return env.afterEach(afterEachFunction); return env.afterEach.apply(env, arguments);
}, },
beforeAll: function(beforeAllFunction) { beforeAll: function() {
return env.beforeAll(beforeAllFunction); return env.beforeAll.apply(env, arguments);
}, },
afterAll: function(afterAllFunction) { afterAll: function() {
return env.afterAll(afterAllFunction); return env.afterAll.apply(env, arguments);
}, },
expect: function(actual) { expect: function(actual) {
@ -2871,7 +3010,7 @@ getJasmineRequireObj().interface = function(jasmine, env) {
}, },
pending: function() { pending: function() {
return env.pending(); return env.pending.apply(env, arguments);
}, },
fail: function() { fail: function() {
@ -2905,5 +3044,5 @@ getJasmineRequireObj().interface = function(jasmine, env) {
}; };
getJasmineRequireObj().version = function() { getJasmineRequireObj().version = function() {
return '2.1.2'; return '2.2.0';
}; };