diff --git a/Rakefile b/Rakefile index db5e9932..4ce88387 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "spec/jasmine_helper. def jasmine_sources sources = ["src/base.js", "src/util.js", "src/Env.js", "src/Reporter.js", "src/Block.js"] sources += Dir.glob('src/*.js').reject{|f| f == 'src/base.js' || sources.include?(f)}.sort + sources end def jasmine_filename(version) @@ -26,19 +27,53 @@ def start_jasmine_server(jasmine_includes = nil) :jasmine_files => jasmine_includes) end +task :default => 'jasmine:dist' + namespace :jasmine do + + desc 'Prepares for distribution' + task :dist => ['jasmine:build', 'jasmine:doc'] + + desc 'Check jasmine sources for coding problems' + task :lint do + passed = true + jasmine_sources.each do |src| + lines = File.read(src).split(/\n/) + lines.each_index do |i| + line = lines[i] + undefineds = line.scan(/.?undefined/) + if undefineds.include?(" undefined") || undefineds.include?("\tundefined") + puts "Dangerous undefined at #{src}:#{i}:\n > #{line}" + passed = false + end + end + end + + unless passed + puts "Lint failed!" + exit 1 + end + end + desc 'Builds lib/jasmine from source' - task :build => 'jasmine:doc' do + task :build => :lint do puts 'Building Jasmine from source' require 'json' + sources = jasmine_sources version = version_hash + old_jasmine_files = Dir.glob('lib/jasmine*.js') old_jasmine_files.each do |file| File.delete(file) end + jasmine = File.new("lib/#{jasmine_filename version}", 'w') - jasmine.puts(File.read(sources.shift)) + + sources.each do |source_filename| + jasmine.puts(File.read(source_filename)) + end + jasmine.puts %{ jasmine.version_= { "major": #{version['major']}, @@ -47,9 +82,7 @@ jasmine.version_= { "revision": #{Time.now.to_i} }; } - sources.each do |source_filename| - jasmine.puts(File.read(source_filename)) - end + jasmine.close end diff --git a/lib/jasmine-0.10.0.js b/lib/jasmine-0.10.0.js index e624775a..f7f621b7 100644 --- a/lib/jasmine-0.10.0.js +++ b/lib/jasmine-0.10.0.js @@ -1,2122 +1,2064 @@ -/** - * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. - * - * @namespace - */ -var jasmine = {}; - -/** - * @private - */ -jasmine.unimplementedMethod_ = function() { - throw new Error("unimplemented method"); -}; - -/** - * Large or small values here may result in slow test running & "Too much recursion" errors - * - */ -jasmine.DEFAULT_UPDATE_INTERVAL = 250; - -/** - * Allows for bound functions to be comapred. Internal use only. - * - * @ignore - * @private - * @param base {Object} bound 'this' for the function - * @param name {Function} function to find - */ -jasmine.bindOriginal_ = function(base, name) { - var original = base[name]; - if (original.apply) { - return function() { - return original.apply(base, arguments); - }; - } else { - // IE support - return window[name]; - } -}; - -jasmine.setTimeout = jasmine.bindOriginal_(window, 'setTimeout'); -jasmine.clearTimeout = jasmine.bindOriginal_(window, 'clearTimeout'); -jasmine.setInterval = jasmine.bindOriginal_(window, 'setInterval'); -jasmine.clearInterval = jasmine.bindOriginal_(window, 'clearInterval'); - -jasmine.MessageResult = function(text) { - this.type = 'MessageResult'; - this.text = text; - this.trace = new Error(); // todo: test better -}; - -jasmine.ExpectationResult = function(params) { - this.type = 'ExpectationResult'; - this.matcherName = params.matcherName; - this.passed_ = params.passed; - this.expected = params.expected; - this.actual = params.actual; - - /** @deprecated */ - this.details = params.details; - - this.message = this.passed_ ? 'Passed.' : params.message; - this.trace = this.passed_ ? '' : new Error(this.message); -}; - -jasmine.ExpectationResult.prototype.passed = function () { - return this.passed_; -}; - -/** - * Getter for the Jasmine environment. Ensures one gets created - */ -jasmine.getEnv = function() { - return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); -}; - -/** - * @ignore - * @private - * @param value - * @returns {Boolean} - */ -jasmine.isArray_ = function(value) { - return value && - typeof value === 'object' && - typeof value.length === 'number' && - typeof value.splice === 'function' && - !(value.propertyIsEnumerable('length')); -}; - -/** - * Pretty printer for expecations. Takes any object and turns it into a human-readable string. - * - * @param value {Object} an object to be outputted - * @returns {String} - */ -jasmine.pp = function(value) { - var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); - stringPrettyPrinter.format(value); - return stringPrettyPrinter.string; -}; - -/** - * Returns true if the object is a DOM Node. - * - * @param {Object} obj object to check - * @returns {Boolean} - */ -jasmine.isDomNode = function(obj) { - return obj['nodeType'] > 0; -}; - -/** - * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. - * - * @example - * // don't care about which function is passed in, as long as it's a function - * expect(mySpy).wasCalledWith(jasmine.any(Function)); - * - * @param {Class} clazz - * @returns matchable object of the type clazz - */ -jasmine.any = function(clazz) { - return new jasmine.Matchers.Any(clazz); -}; - -/** - * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. - * - * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine - * expectation syntax. Spies can be checked if they were called or not and what the calling params were. - * - * A Spy has the following mehtod: wasCalled, callCount, mostRecentCall, and argsForCall (see docs) - * 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 - * - * // spy example - * var foo = { - * not: function(bool) { return !bool; } - * } - * - * // actual foo.not will not be called, execution stops - * spyOn(foo, 'not'); - - // foo.not spied upon, execution will continue to implementation - * spyOn(foo, 'not').andCallThrough(); - * - * // fake example - * var foo = { - * not: function(bool) { return !bool; } - * } - * - * // foo.not(val) will return val - * spyOn(foo, 'not').andCallFake(function(value) {return value;}); - * - * // mock example - * foo.not(7 == 7); - * expect(foo.not).wasCalled(); - * expect(foo.not).wasCalledWith(true); - * - * @constructor - * @see spyOn, jasmine.createSpy, jasmine.createSpyObj - * @param {String} name - */ -jasmine.Spy = function(name) { - /** - * The name of the spy, if provided. - */ - this.identity = name || 'unknown'; - /** - * Is this Object a spy? - */ - this.isSpy = true; - /** - * The acutal function this spy stubs. - */ - this.plan = function() { - }; - /** - * Tracking of the most recent call to the spy. - * @example - * var mySpy = jasmine.createSpy('foo'); - * mySpy(1, 2); - * mySpy.mostRecentCall.args = [1, 2]; - */ - this.mostRecentCall = {}; - - /** - * Holds arguments for each call to the spy, indexed by call count - * @example - * var mySpy = jasmine.createSpy('foo'); - * mySpy(1, 2); - * mySpy(7, 8); - * mySpy.mostRecentCall.args = [7, 8]; - * mySpy.argsForCall[0] = [1, 2]; - * mySpy.argsForCall[1] = [7, 8]; - */ - this.argsForCall = []; - this.calls = []; -}; - -/** - * Tells a spy to call through to the actual implemenatation. - * - * @example - * var foo = { - * bar: function() { // do some stuff } - * } - * - * // defining a spy on an existing property: foo.bar - * spyOn(foo, 'bar').andCallThrough(); - */ -jasmine.Spy.prototype.andCallThrough = function() { - this.plan = this.originalValue; - return this; -}; - -/** - * For setting the return value of a spy. - * - * @example - * // defining a spy from scratch: foo() returns 'baz' - * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); - * - * // defining a spy on an existing property: foo.bar() returns 'baz' - * spyOn(foo, 'bar').andReturn('baz'); - * - * @param {Object} value - */ -jasmine.Spy.prototype.andReturn = function(value) { - this.plan = function() { - return value; - }; - return this; -}; - -/** - * For throwing an exception when a spy is called. - * - * @example - * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' - * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); - * - * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' - * spyOn(foo, 'bar').andThrow('baz'); - * - * @param {String} exceptionMsg - */ -jasmine.Spy.prototype.andThrow = function(exceptionMsg) { - this.plan = function() { - throw exceptionMsg; - }; - return this; -}; - -/** - * Calls an alternate implementation when a spy is called. - * - * @example - * var baz = function() { - * // do some stuff, return something - * } - * // defining a spy from scratch: foo() calls the function baz - * var foo = jasmine.createSpy('spy on foo').andCall(baz); - * - * // defining a spy on an existing property: foo.bar() calls an anonymnous function - * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); - * - * @param {Function} fakeFunc - */ -jasmine.Spy.prototype.andCallFake = function(fakeFunc) { - this.plan = fakeFunc; - return this; -}; - -/** - * Resets all of a spy's the tracking variables so that it can be used again. - * - * @example - * spyOn(foo, 'bar'); - * - * foo.bar(); - * - * expect(foo.bar.callCount).toEqual(1); - * - * foo.bar.reset(); - * - * expect(foo.bar.callCount).toEqual(0); - */ -jasmine.Spy.prototype.reset = function() { - this.wasCalled = false; - this.callCount = 0; - this.argsForCall = []; - this.calls = []; - this.mostRecentCall = {}; -}; - -jasmine.createSpy = function(name) { - - var spyObj = function() { - spyObj.wasCalled = true; - spyObj.callCount++; - var args = jasmine.util.argsToArray(arguments); - spyObj.mostRecentCall.object = this; - spyObj.mostRecentCall.args = args; - spyObj.argsForCall.push(args); - spyObj.calls.push({object: this, args: args}); - return spyObj.plan.apply(this, arguments); - }; - - var spy = new jasmine.Spy(name); - - for (var prop in spy) { - spyObj[prop] = spy[prop]; - } - - spyObj.reset(); - - return spyObj; -}; - -/** - * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something - * large in one call. - * - * @param {String} baseName name of spy class - * @param {Array} methodNames array of names of methods to make spies - */ -jasmine.createSpyObj = function(baseName, methodNames) { - var obj = {}; - for (var i = 0; i < methodNames.length; i++) { - obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); - } - return obj; -}; - -jasmine.log = function(message) { - jasmine.getEnv().currentSpec.log(message); -}; - -/** - * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. - * - * @example - * // spy example - * var foo = { - * not: function(bool) { return !bool; } - * } - * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops - * - * @see jasmine.createSpy - * @param obj - * @param methodName - * @returns a Jasmine spy that can be chained with all spy methods - */ -var spyOn = function(obj, methodName) { - return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -}; - -/** - * Creates a Jasmine spec that will be added to the current suite. - * - * // TODO: pending tests - * - * @example - * it('should be true', function() { - * expect(true).toEqual(true); - * }); - * - * @param {String} desc description of this specification - * @param {Function} func defines the preconditions and expectations of the spec - */ -var it = function(desc, func) { - return jasmine.getEnv().it(desc, func); -}; - -/** - * Creates a disabled Jasmine spec. - * - * A convenience method that allows existing specs to be disabled temporarily during development. - * - * @param {String} desc description of this specification - * @param {Function} func defines the preconditions and expectations of the spec - */ -var xit = function(desc, func) { - return jasmine.getEnv().xit(desc, func); -}; - -/** - * Starts a chain for a Jasmine expectation. - * - * It is passed an Object that is the actual value and should chain to one of the many - * jasmine.Matchers functions. - * - * @param {Object} actual Actual value to test against and expected value - */ -var expect = function(actual) { - return jasmine.getEnv().currentSpec.expect(actual); -}; - -/** - * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. - * - * @param {Function} func Function that defines part of a jasmine spec. - */ -var runs = function(func) { - jasmine.getEnv().currentSpec.runs(func); -}; - -/** - * Waits for a timeout before moving to the next runs()-defined block. - * @param {Number} timeout - */ -var waits = function(timeout) { - jasmine.getEnv().currentSpec.waits(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 - */ -var waitsFor = function(timeout, latchFunction, message) { - jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); -}; - -/** - * A function that is called before each spec in a suite. - * - * Used for spec setup, including validating assumptions. - * - * @param {Function} beforeEachFunction - */ -var beforeEach = function(beforeEachFunction) { - jasmine.getEnv().beforeEach(beforeEachFunction); -}; - -/** - * A function that is called after each spec in a suite. - * - * Used for restoring any state that is hijacked during spec execution. - * - * @param {Function} afterEachFunction - */ -var afterEach = function(afterEachFunction) { - jasmine.getEnv().afterEach(afterEachFunction); -}; - -/** - * Defines a suite of specifications. - * - * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared - * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization - * of setup in some tests. - * - * @example - * // TODO: a simple suite - * - * // TODO: a simple suite with a nested describe block - * - * @param {String} description A string, usually the class under test. - * @param {Function} specDefinitions function that defines several specs. - */ -var describe = function(description, specDefinitions) { - return jasmine.getEnv().describe(description, specDefinitions); -}; - -/** - * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. - * - * @param {String} description A string, usually the class under test. - * @param {Function} specDefinitions function that defines several specs. - */ -var xdescribe = function(description, specDefinitions) { - return jasmine.getEnv().xdescribe(description, specDefinitions); -}; - - -jasmine.XmlHttpRequest = XMLHttpRequest; - -// Provide the XMLHttpRequest class for IE 5.x-6.x: -if (typeof XMLHttpRequest == "undefined") jasmine.XmlHttpRequest = function() { - try { - return new ActiveXObject("Msxml2.XMLHTTP.6.0"); - } catch(e) { - } - try { - return new ActiveXObject("Msxml2.XMLHTTP.3.0"); - } catch(e) { - } - try { - return new ActiveXObject("Msxml2.XMLHTTP"); - } catch(e) { - } - try { - return new ActiveXObject("Microsoft.XMLHTTP"); - } catch(e) { - } - throw new Error("This browser does not support XMLHttpRequest."); -}; - -/** - * Adds suite files to an HTML document so that they are executed, thus adding them to the current - * Jasmine environment. - * - * @param {String} url path to the file to include - * @param {Boolean} opt_global - */ -jasmine.include = function(url, opt_global) { - if (opt_global) { - document.write(' + diff --git a/spec/suites/JsApiReporterSpec.js b/spec/suites/JsApiReporterSpec.js index 6615fe59..1645fb83 100644 --- a/spec/suites/JsApiReporterSpec.js +++ b/spec/suites/JsApiReporterSpec.js @@ -60,8 +60,8 @@ describe('jasmine.jsApiReporter', function() { expect(summarizedResult.messages[0].message).toEqual(result.messages[0].message); expect(summarizedResult.messages[0].passed).toBeTruthy(); expect(summarizedResult.messages[0].type).toEqual('ExpectationResult'); - expect(summarizedResult.messages[0].text).toEqual(undefined); - expect(summarizedResult.messages[0].trace.stack).toEqual(undefined); + expect(summarizedResult.messages[0].text).toEqual(jasmine.undefined); + expect(summarizedResult.messages[0].trace.stack).toEqual(jasmine.undefined); }); it("should have a stack trace for failing specs", function() { diff --git a/spec/suites/MatchersSpec.js b/spec/suites/MatchersSpec.js index 4944727e..10137835 100644 --- a/spec/suites/MatchersSpec.js +++ b/spec/suites/MatchersSpec.js @@ -43,8 +43,8 @@ describe("jasmine.Matchers", function() { expect(match(true).toNotEqual(false)).toEqual(true); expect((match(true).toNotEqual(true))).toEqual(false); - expect((match(['a', 'b']).toEqual(['a', undefined]))).toEqual(false); - expect((match(['a', 'b']).toEqual(['a', 'b', undefined]))).toEqual(false); + expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toEqual(false); + expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toEqual(false); }); it("toEqual to build an Expectation Result", function() { @@ -197,11 +197,11 @@ describe("jasmine.Matchers", function() { it("toBeDefined", function() { expect(match('foo').toBeDefined()).toEqual(true); - expect(match(undefined).toBeDefined()).toEqual(false); + expect(match(jasmine.undefined).toBeDefined()).toEqual(false); }); it("toBeDefined to build an ExpectationResult", function() { - var matcher = match(undefined); + var matcher = match(jasmine.undefined); matcher.toBeDefined(); var result = mockSpec.addMatcherResult.mostRecentCall.args[0]; @@ -209,17 +209,17 @@ describe("jasmine.Matchers", function() { expect(result.matcherName).toEqual("toBeDefined"); expect(result.passed()).toEqual(false); expect(result.message).toEqual('Expected undefined to be defined.'); - expect(result.actual).toEqual(undefined); + expect(result.actual).toEqual(jasmine.undefined); }); it("toBeUndefined", function() { expect(match('foo').toBeUndefined()).toEqual(false); - expect(match(undefined).toBeUndefined()).toEqual(true); + expect(match(jasmine.undefined).toBeUndefined()).toEqual(true); }); it("toBeNull", function() { expect(match(null).toBeNull()).toEqual(true); - expect(match(undefined).toBeNull()).toEqual(false); + expect(match(jasmine.undefined).toBeNull()).toEqual(false); expect(match("foo").toBeNull()).toEqual(false); }); @@ -254,7 +254,7 @@ describe("jasmine.Matchers", function() { it("toBeFalsy", function() { expect(match(false).toBeFalsy()).toEqual(true); expect(match(true).toBeFalsy()).toEqual(false); - expect(match(undefined).toBeFalsy()).toEqual(true); + expect(match(jasmine.undefined).toBeFalsy()).toEqual(true); expect(match(0).toBeFalsy()).toEqual(true); expect(match("").toBeFalsy()).toEqual(true); }); @@ -276,7 +276,7 @@ describe("jasmine.Matchers", function() { it("toBeTruthy", function() { expect(match(false).toBeTruthy()).toEqual(false); expect(match(true).toBeTruthy()).toEqual(true); - expect(match(undefined).toBeTruthy()).toEqual(false); + expect(match(jasmine.undefined).toBeTruthy()).toEqual(false); expect(match(0).toBeTruthy()).toEqual(false); expect(match("").toBeTruthy()).toEqual(false); expect(match("hi").toBeTruthy()).toEqual(true); @@ -297,11 +297,11 @@ describe("jasmine.Matchers", function() { }); it("toEqual", function() { - expect(match(undefined).toEqual(undefined)).toEqual(true); + expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toEqual(true); expect(match({foo:'bar'}).toEqual({foo:'bar'})).toEqual(true); - expect(match("foo").toEqual({bar: undefined})).toEqual(false); - expect(match({foo: undefined}).toEqual("goo")).toEqual(false); - expect(match({foo: {bar :undefined}}).toEqual("goo")).toEqual(false); + expect(match("foo").toEqual({bar: jasmine.undefined})).toEqual(false); + expect(match({foo: jasmine.undefined}).toEqual("goo")).toEqual(false); + expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toEqual(false); }); it("toEqual with jasmine.any()", function() { @@ -321,7 +321,7 @@ describe("jasmine.Matchers", function() { }); it("toEqual handles circular objects ok", function() { - expect(match({foo: "bar", baz: undefined}).toEqual({foo: "bar", baz: undefined})).toEqual(true); + expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toEqual(true); expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toEqual(true); expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toEqual(true); @@ -488,7 +488,7 @@ describe("jasmine.Matchers", function() { }).toThrow('Expected a spy, but got Function.'); expect(function() { - match(undefined)[methodName](); + match(jasmine.undefined)[methodName](); }).toThrow('Expected a spy, but got undefined.'); expect(function() { diff --git a/spec/suites/PrettyPrintSpec.js b/spec/suites/PrettyPrintSpec.js index cf5f95ac..1f046f2c 100644 --- a/spec/suites/PrettyPrintSpec.js +++ b/spec/suites/PrettyPrintSpec.js @@ -8,14 +8,14 @@ describe("jasmine.pp", function () { expect(jasmine.pp(true)).toEqual("true"); expect(jasmine.pp(false)).toEqual("false"); expect(jasmine.pp(null)).toEqual("null"); - expect(jasmine.pp(undefined)).toEqual("undefined"); + expect(jasmine.pp(jasmine.undefined)).toEqual("undefined"); expect(jasmine.pp(3)).toEqual("3"); expect(jasmine.pp(-3.14)).toEqual("-3.14"); }); it("should stringify arrays properly", function() { expect(jasmine.pp([1, 2])).toEqual("[ 1, 2 ]"); - expect(jasmine.pp([1, 'foo', {}, undefined, null])).toEqual("[ 1, 'foo', { }, undefined, null ]"); + expect(jasmine.pp([1, 'foo', {}, jasmine.undefined, null])).toEqual("[ 1, 'foo', { }, undefined, null ]"); }); it("should indicate circular array references", function() { @@ -27,7 +27,7 @@ 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:'bar', baz:3, nullValue: null, undefinedValue: jasmine.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 ] }"); }); diff --git a/spec/suites/SpecRunningSpec.js b/spec/suites/SpecRunningSpec.js index 7282a134..ec49a77c 100644 --- a/spec/suites/SpecRunningSpec.js +++ b/spec/suites/SpecRunningSpec.js @@ -1111,7 +1111,7 @@ describe("jasmine spec running", function () { expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected"); expect(spec2Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: yyy; expected: expected"); - expect(spec2Matcher.matcherForSpec).toBe(undefined); + expect(spec2Matcher.matcherForSpec).toBe(jasmine.undefined); }); }); diff --git a/src/Env.js b/src/Env.js index dac30f17..142ddfba 100644 --- a/src/Env.js +++ b/src/Env.js @@ -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 diff --git a/src/JsApiReporter.js b/src/JsApiReporter.js index dae9cc84..83f6bf7a 100644 --- a/src/JsApiReporter.js +++ b/src/JsApiReporter.js @@ -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 } }); }; diff --git a/src/Matchers.js b/src/Matchers.js index 74a63ecf..79f5d533 100644 --- a/src/Matchers.js +++ b/src/Matchers.js @@ -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."; diff --git a/src/PrettyPrinter.js b/src/PrettyPrinter.js index a5476347..06b38c3c 100644 --- a/src/PrettyPrinter.js +++ b/src/PrettyPrinter.js @@ -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'); diff --git a/src/Spec.js b/src/Spec.js index 4931432d..fa6ddd47 100644 --- a/src/Spec.js +++ b/src/Spec.js @@ -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'; } diff --git a/src/base.js b/src/base.js index 58b23946..8850f28e 100755 --- a/src/base.js +++ b/src/base.js @@ -12,6 +12,14 @@ jasmine.unimplementedMethod_ = function() { throw new Error("unimplemented method"); }; +/** + * Use jasmine.undefined instead of undefined, since undefined= oldMillis && scheduledFunc.runAtMillis <= nowMillis) { funcsToRun.push(scheduledFunc); - this.scheduledFunctions[timeoutKey] = undefined; + this.scheduledFunctions[timeoutKey] = jasmine.undefined; } }