IE7 fixes

This commit is contained in:
ragaskar 2009-10-15 17:48:28 -07:00
parent 1b1c2b1998
commit 85d3b2d14b
4 changed files with 59 additions and 23 deletions

View File

@ -28,7 +28,8 @@ describe("jasmine.pp", function () {
it("should stringify objects properly", function() {
expect(jasmine.pp({foo: 'bar'})).toEqual("{ foo : 'bar' }");
expect(jasmine.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: undefined})).toEqual("{ foo : 'bar', baz : 3, nullValue : null, undefinedValue : undefined }");
expect(jasmine.pp({foo: function () { }, bar: [1, 2, 3]})).toEqual("{ foo : Function, bar : [ 1, 2, 3 ] }");
expect(jasmine.pp({foo: function () {
}, bar: [1, 2, 3]})).toEqual("{ foo : Function, bar : [ 1, 2, 3 ] }");
});
it("should indicate circular object references", function() {
@ -39,8 +40,18 @@ describe("jasmine.pp", function () {
it("should indicate getters on objects as such", function() {
var sampleValue = {id: 1};
sampleValue.__defineGetter__('calculatedValue', function() { throw new Error("don't call me!"); });
expect(jasmine.pp(sampleValue)).toEqual("{ id : 1, calculatedValue : <getter> }");
if (sampleValue.__defineGetter__) {
//not supported in IE!
sampleValue.__defineGetter__('calculatedValue', function() {
throw new Error("don't call me!");
});
}
if (sampleValue.__defineGetter__) {
expect(jasmine.pp(sampleValue)).toEqual("{ id : 1, calculatedValue : <getter> }");
}
else {
expect(jasmine.pp(sampleValue)).toEqual("{ id : 1 }");
}
});
it("should stringify HTML nodes properly", function() {

View File

@ -56,7 +56,7 @@ jasmine.PrettyPrinter.prototype.format = function(value) {
jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) {
for (var property in obj) {
if (property == '__Jasmine_been_here_before__') continue;
fn(property, obj.__lookupGetter__(property) != null);
fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) != null) : false);
}
};

View File

@ -1,6 +1,6 @@
/**
* Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.
*
*
* @namespace
*/
var jasmine = {};
@ -14,7 +14,7 @@ jasmine.unimplementedMethod_ = function() {
/**
* Large or small values here may result in slow test running & "Too much recursion" errors
*
*
*/
jasmine.UPDATE_INTERVAL = 250;
@ -29,7 +29,14 @@ jasmine.UPDATE_INTERVAL = 250;
jasmine.bindOriginal_ = function(base, name) {
var original = base[name];
return function() {
return original.apply(base, arguments);
if (original.apply) {
return original.apply(base, arguments);
} else {
//IE support
if (base == window) {
return window[name].apply(window, arguments);
}
}
};
};
@ -71,10 +78,10 @@ jasmine.getEnv = function() {
*/
jasmine.isArray_ = function(value) {
return value &&
typeof value === 'object' &&
typeof value.length === 'number' &&
typeof value.splice === 'function' &&
!(value.propertyIsEnumerable('length'));
typeof value === 'object' &&
typeof value.length === 'number' &&
typeof value.splice === 'function' &&
!(value.propertyIsEnumerable('length'));
};
/**
@ -123,7 +130,7 @@ jasmine.any = function(clazz) {
* Spies are torn down at the end of every spec.
*
* Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj.
*
*
* @example
* // a stub
* var myStub = jasmine.createSpy('myStub'); // can be used anywhere
@ -168,7 +175,8 @@ jasmine.Spy = function(name) {
/**
* The acutal function this spy stubs.
*/
this.plan = function() {};
this.plan = function() {
};
/**
* Tracking of the most recent call to the spy.
* @example
@ -199,7 +207,7 @@ jasmine.Spy = function(name) {
* var foo = {
* bar: function() { // do some stuff }
* }
*
*
* // defining a spy on an existing property: foo.bar
* spyOn(foo, 'bar').andCallThrough();
*/
@ -302,11 +310,11 @@ jasmine.createSpy = function(name) {
};
var spy = new jasmine.Spy(name);
for(var prop in spy) {
for (var prop in spy) {
spyObj[prop] = spy[prop];
}
spyObj.reset();
return spyObj;
@ -410,7 +418,7 @@ var waits = function(timeout) {
/**
* Waits for the latchFunction to return true before proceeding to the next runs()-defined block.
*
*
* @param {Number} timeout
* @param {Function} latchFunction
* @param {String} message

View File

@ -134,25 +134,42 @@ jasmine.Clock = {
if (jasmine.Clock.installed != jasmine.Clock.defaultFakeTimer) {
throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()");
}
},
},
installed: null
};
jasmine.Clock.installed = jasmine.Clock.real;
//else for IE support
window.setTimeout = function(funcToCall, millis) {
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
if (jasmine.Clock.installed.setTimeout.apply) {
return jasmine.Clock.installed.setTimeout.apply(this, arguments);
} else {
return jasmine.Clock.installed.setTimeout(funcToCall, millis);
}
};
window.setInterval = function(funcToCall, millis) {
return jasmine.Clock.installed.setInterval.apply(this, arguments);
if (jasmine.Clock.installed.setInterval.apply) {
return jasmine.Clock.installed.setInterval.apply(this, arguments);
} else {
return jasmine.Clock.installed.setInterval(funcToCall, millis);
}
};
window.clearTimeout = function(timeoutKey) {
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
if (jasmine.Clock.installed.clearTimeout.apply) {
return jasmine.Clock.installed.clearTimeout.apply(this, arguments);
} else {
return jasmine.Clock.installed.clearTimeout(timeoutKey);
}
};
window.clearInterval = function(timeoutKey) {
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
if (jasmine.Clock.installed.clearTimeout.apply) {
return jasmine.Clock.installed.clearInterval.apply(this, arguments);
} else {
return jasmine.Clock.installed.clearInterval(timeoutKey);
}
};