From 85d3b2d14b0152c8e741f675b4a0b788d9535f06 Mon Sep 17 00:00:00 2001 From: ragaskar Date: Thu, 15 Oct 2009 17:48:28 -0700 Subject: [PATCH] IE7 fixes --- spec/suites/PrettyPrintSpec.js | 17 +++++++++++++--- src/PrettyPrinter.js | 2 +- src/base.js | 36 +++++++++++++++++++++------------- src/mock-timeout.js | 27 ++++++++++++++++++++----- 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/spec/suites/PrettyPrintSpec.js b/spec/suites/PrettyPrintSpec.js index 00559c08..48b1c7d4 100644 --- a/spec/suites/PrettyPrintSpec.js +++ b/spec/suites/PrettyPrintSpec.js @@ -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 : }"); + 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 : }"); + } + else { + expect(jasmine.pp(sampleValue)).toEqual("{ id : 1 }"); + } }); it("should stringify HTML nodes properly", function() { diff --git a/src/PrettyPrinter.js b/src/PrettyPrinter.js index ff793a91..d0447535 100644 --- a/src/PrettyPrinter.js +++ b/src/PrettyPrinter.js @@ -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); } }; diff --git a/src/base.js b/src/base.js index 682438ae..7448d426 100755 --- a/src/base.js +++ b/src/base.js @@ -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 not 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 diff --git a/src/mock-timeout.js b/src/mock-timeout.js index c959949f..bec43eed 100755 --- a/src/mock-timeout.js +++ b/src/mock-timeout.js @@ -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); + } };