Use jasmine.undefined for all comparisons to the undefined value, since undefined itself may be redefined elsewhere

in app code.  Thanks to Charlie Meyer at UIUC for the suggestion.
This commit is contained in:
Christian Williams
2009-11-26 11:12:06 -05:00
parent 2cb5bf146c
commit 7653107f0c
14 changed files with 100 additions and 59 deletions

View File

@@ -151,7 +151,7 @@ jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchVal
b.__Jasmine_been_here_before__ = a;
var hasKey = function(obj, keyName) {
return obj != null && obj[keyName] !== undefined;
return obj != null && obj[keyName] !== jasmine.undefined;
};
for (var property in b) {
@@ -186,8 +186,8 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
if (a === b) return true;
if (a === undefined || a === null || b === undefined || b === null) {
return (a == undefined && b == undefined);
if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) {
return (a == jasmine.undefined && b == jasmine.undefined);
}
if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) {
@@ -213,7 +213,7 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) {
for (var i = 0; i < this.equalityTesters_.length; i++) {
var equalityTester = this.equalityTesters_[i];
var result = equalityTester(a, b, this, mismatchKeys, mismatchValues);
if (result !== undefined) return result;
if (result !== jasmine.undefined) return result;
}
//Straight check

View File

@@ -88,7 +88,7 @@ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){
type: resultMessage.type,
message: resultMessage.message,
trace: {
stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : undefined
stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined
}
});
};

View File

@@ -113,17 +113,17 @@ jasmine.Matchers.prototype.toNotMatch = function(expected) {
};
/**
* Matcher that compares the actual to undefined.
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeDefined = function() {
return (this.actual !== undefined);
return (this.actual !== jasmine.undefined);
};
/**
* Matcher that compares the actual to undefined.
* Matcher that compares the actual to jasmine.undefined.
*/
jasmine.Matchers.prototype.toBeUndefined = function() {
return (this.actual === undefined);
return (this.actual === jasmine.undefined);
};
/**
@@ -252,12 +252,12 @@ jasmine.Matchers.prototype.toThrow = function(expected) {
var result = false;
var exception = getException_(this.actual, expected);
if (exception) {
result = (expected === undefined || this.env.equals_(exception.message || exception, expected.message || expected));
result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected));
}
this.message = function(expected) {
var exception = getException_(this.actual, expected);
if (exception && (expected === undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) {
return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception ].join(' ');
} else {
return "Expected function to throw an exception.";

View File

@@ -17,7 +17,7 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
this.ppNestLevel_++;
try {
if (value === undefined) {
if (value === jasmine.undefined) {
this.emitScalar('undefined');
} else if (value === null) {
this.emitScalar('null');

View File

@@ -171,11 +171,11 @@ jasmine.Spec.prototype.explodes = function() {
};
jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) {
if (obj == undefined) {
if (obj == jasmine.undefined) {
throw "spyOn could not find an object to spy upon for " + methodName + "()";
}
if (!ignoreMethodDoesntExist && obj[methodName] === undefined) {
if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) {
throw methodName + '() method does not exist';
}

View File

@@ -12,6 +12,14 @@ 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 for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed.
*

View File

@@ -18,11 +18,11 @@ jasmine.FakeTimer = function() {
};
self.clearTimeout = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = undefined;
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
};
self.clearInterval = function(timeoutKey) {
self.scheduledFunctions[timeoutKey] = undefined;
self.scheduledFunctions[timeoutKey] = jasmine.undefined;
};
};
@@ -45,11 +45,11 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil
var funcsToRun = [];
for (var timeoutKey in this.scheduledFunctions) {
scheduledFunc = this.scheduledFunctions[timeoutKey];
if (scheduledFunc != undefined &&
if (scheduledFunc != jasmine.undefined &&
scheduledFunc.runAtMillis >= oldMillis &&
scheduledFunc.runAtMillis <= nowMillis) {
funcsToRun.push(scheduledFunc);
this.scheduledFunctions[timeoutKey] = undefined;
this.scheduledFunctions[timeoutKey] = jasmine.undefined;
}
}