Added grunt to project.

Move from embedded "fork" of jsHint to using grunt's jsHint module.
Cleaned ALL jsHint errors.
Added jasmine.util.isUndefined as alternative to extra careful protection against undefined clobbering
This commit is contained in:
Dan Hansen and Davis W. Frank
2013-03-01 14:24:30 -08:00
parent b22bf9a031
commit cf7bb0269b
27 changed files with 146 additions and 6181 deletions

View File

@@ -56,7 +56,7 @@ jasmine.Clock = function(global, delayedFunctionScheduler) {
self.tick = function(millis) {
if (installed) {
delayedFunctionScheduler.tick(millis)
delayedFunctionScheduler.tick(millis);
} else {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
}

View File

@@ -12,8 +12,6 @@
this.spies_ = [];
this.currentSpec = null;
this.undefined = jasmine.undefined;
this.reporter = new jasmine.ReportDispatcher([
"jasmineStarted",
"jasmineDone",
@@ -55,20 +53,20 @@
return function() {
var befores = [];
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
befores = befores.concat(suite.beforeFns)
befores = befores.concat(suite.beforeFns);
}
return befores.reverse();
}
};
};
var afterFns = function(currentSuite) {
return function() {
var afters = [];
for (var suite = currentSuite; suite; suite = suite.parentSuite) {
afters = afters.concat(suite.afterFns)
afters = afters.concat(suite.afterFns);
}
return afters;
}
};
};
var specConstructor = jasmine.Spec;
@@ -133,7 +131,7 @@
exceptionFormatter: exceptionFormatter,
resultCallback: specResultCallback,
getSpecName: function(spec) {
return getSpecName(spec, suite)
return getSpecName(spec, suite);
},
onStart: specStarted,
description: description,
@@ -218,11 +216,11 @@
};
jasmine.Env.prototype.spyOn = function(obj, methodName) {
if (obj == this.undefined) {
if (jasmine.util.isUndefined(obj)) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
}
if (obj[methodName] === this.undefined) {
if (jasmine.util.isUndefined(obj[methodName])) {
throw methodName + '() method does not exist';
}
@@ -377,7 +375,7 @@
b.__Jasmine_been_here_before__ = a;
var hasKey = function(obj, keyName) {
return obj !== null && obj[keyName] !== this.undefined;
return obj !== null && !jasmine.util.isUndefined(obj[keyName]);
};
for (var property in b) {
@@ -413,13 +411,15 @@
for (var i = 0; i < this.equalityTesters_.length; i++) {
var equalityTester = this.equalityTesters_[i];
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
if (result !== this.undefined) return result;
if (!jasmine.util.isUndefined(result)) {
return result;
}
}
if (a === b) return true;
if (a === this.undefined || a === null || b === this.undefined || b === null) {
return (a == this.undefined && b == this.undefined);
if (jasmine.util.isUndefined(a) || a === null || jasmine.util.isUndefined(b) || b === null) {
return (jasmine.util.isUndefined(a) && jasmine.util.isUndefined(b));
}
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {

View File

@@ -1,15 +1,15 @@
jasmine.ExceptionFormatter = function() {
this.message = function(error) {
var message = error.name
+ ': '
+ error.message;
var message = error.name +
': ' +
error.message;
if (error.fileName || error.sourceURL) {
message += " in " + (error.fileName || error.sourceURL);
}
if (error.line || error.lineNumber) {
message += " (line " + (error.line || error.lineNumber) + ")"
message += " (line " + (error.line || error.lineNumber) + ")";
}
return message;
@@ -17,5 +17,5 @@ jasmine.ExceptionFormatter = function() {
this.stack = function(error) {
return error ? error.stack : null;
}
};
};

View File

@@ -14,13 +14,13 @@ jasmine.buildExpectationResult = function(options) {
function message() {
if (options.passed) {
return "Passed."
return "Passed.";
} else if (options.message) {
return options.message
return options.message;
} else if (options.error) {
return messageFormatter(options.error);
}
return ""
return "";
}
function stack() {

View File

@@ -61,7 +61,7 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
actual: this.actual,
message: message
});
return jasmine.undefined;
return void 0;
};
};
@@ -124,14 +124,14 @@ jasmine.Matchers.prototype.toNotMatch = function(expected) {
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeDefined = function() {
return (this.actual !== jasmine.undefined);
return !jasmine.util.isUndefined(this.actual);
};
/**
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeUndefined = function() {
return (this.actual === jasmine.undefined);
return jasmine.util.isUndefined(this.actual);
};
/**
@@ -234,7 +234,7 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() {
if (this.actual.callCount === 0) {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.";
} else {
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '')
positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '');
}
return [positiveMessage, invertedMessage];
};
@@ -297,7 +297,7 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) {
* @param {Number} precision, as number of decimal places
*/
jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) {
if (!(precision === 0)) {
if (precision !== 0) {
precision = precision || 2;
}
return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2);
@@ -319,14 +319,15 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
} catch (e) {
exception = e;
}
if (exception) {
result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
result = (jasmine.util.isUndefined(expected) || this.env.equals_(exception.message || exception, expected.message || expected));
}
var not = this.isNot ? "not " : "";
this.message = function() {
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
if (exception && (jasmine.util.isUndefined(expected) || !this.env.equals_(exception.message || exception, expected.message || expected))) {
return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' ');
} else {
return "Expected function to throw an exception.";
@@ -375,7 +376,7 @@ jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mis
var env = jasmine.getEnv();
var hasKey = function(obj, keyName) {
return obj != null && obj[keyName] !== jasmine.undefined;
return obj !== null && !jasmine.util.isUndefined(obj[keyName]);
};
for (var property in this.sample) {

View File

@@ -13,7 +13,7 @@ jasmine.PrettyPrinter = function() {
jasmine.PrettyPrinter.prototype.format = function(value) {
this.ppNestLevel_++;
try {
if (value === jasmine.undefined) {
if (jasmine.util.isUndefined(value)) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');
@@ -55,7 +55,7 @@ jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
for (var property in obj) {
if (!obj.hasOwnProperty(property)) continue;
if (property == '__Jasmine_been_here_before__') continue;
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined &&
fn(property, obj.__lookupGetter__ ? (!jasmine.util.isUndefined(obj.__lookupGetter__(property)) &&
obj.__lookupGetter__(property) !== null) : false);
}
};

View File

@@ -1,13 +1,13 @@
jasmine.QueueRunner = function(attrs) {
this.fns = attrs.fns || [];
this.onComplete = attrs.onComplete || function() {};
this.encourageGC = attrs.encourageGC || function(fn) {fn()};
this.encourageGC = attrs.encourageGC || function(fn) {fn();};
this.onException = attrs.onException || function() {};
this.catchException = attrs.catchException || function() { return true; };
};
jasmine.QueueRunner.prototype.execute = function() {
this.run(this.fns, 0)
this.run(this.fns, 0);
};
jasmine.QueueRunner.prototype.run = function(fns, index) {
@@ -19,7 +19,7 @@ jasmine.QueueRunner.prototype.run = function(fns, index) {
var fn = fns[index];
var self = this;
if (fn.length > 0) {
attempt(function() { fn.call(self, function() { self.run(fns, index + 1) }) });
attempt(function() { fn.call(self, function() { self.run(fns, index + 1); }); });
} else {
attempt(function() { fn.call(self); });
self.run(fns, index + 1);

View File

@@ -94,6 +94,6 @@ jasmine.Suite.prototype.execute = function(onComplete) {
function wrapChild(child) {
return function (done) {
child.execute(done);
}
};
}
};

View File

@@ -8,7 +8,7 @@ var jasmine = {};
// TODO: do we need this now that we have boot.js?
if (typeof window == "undefined" && typeof exports == "object") {
exports.jasmine = jasmine
exports.jasmine = jasmine;
}
/**
@@ -18,14 +18,6 @@ jasmine.unimplementedMethod_ = function() {
throw new Error("unimplemented method");
};
/**
* Use <code>jasmine.undefined</code> instead of <code>undefined</code>, since <code>undefined</code> is just
* a plain old variable and may be redefined by somebody else.
*
* @private
*/
jasmine.undefined = jasmine.___undefined___;
/**
* Default interval in milliseconds for event loop yields (e.g. to allow network activity or to refresh the screen with the HTML-based runner). Small values here may result in slow test running. Zero means no updates until all tests have completed.
*

View File

@@ -58,4 +58,8 @@ jasmine.util.argsToArray = function(args) {
var arrayOfArgs = [];
for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]);
return arrayOfArgs;
};
};
jasmine.util.isUndefined = function(obj) {
return obj === void 0;
};