diff --git a/downloads/jasmine-standalone-1.0.0.rc1.zip b/downloads/jasmine-standalone-1.0.0.rc1.zip new file mode 100644 index 0000000..553e41c Binary files /dev/null and b/downloads/jasmine-standalone-1.0.0.rc1.zip differ diff --git a/index.html b/index.html index 440036e..4291e95 100644 --- a/index.html +++ b/index.html @@ -25,11 +25,20 @@ describe("Jasmine", function() { + + + + + + + + +
VersionSizeDateSHA1
1.0.0.rc119k2010/08/26 13:09:41 PDT20e7da22bc7ce3433331a5ad44eb199f4ff34065
0.11.1 18k 2010/06/25 16:05:30 PDT 26998c7ca047e47f84c382a4efeb1dc5cb8661a6
diff --git a/jsdoc/files.html b/jsdoc/files.html index 1a1710b..74f98eb 100644 --- a/jsdoc/files.html +++ b/jsdoc/files.html @@ -214,6 +214,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -442,7 +444,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    \ No newline at end of file diff --git a/jsdoc/index.html b/jsdoc/index.html index d506978..7e18bc4 100644 --- a/jsdoc/index.html +++ b/jsdoc/index.html @@ -214,6 +214,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -312,11 +314,17 @@ ul.inheritsList
    +
    +

    jasmine.WaitsForBlock

    + +
    +
    +
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    \ No newline at end of file diff --git a/jsdoc/symbols/_global_.html b/jsdoc/symbols/_global_.html index 7998093..f38f29e 100644 --- a/jsdoc/symbols/_global_.html +++ b/jsdoc/symbols/_global_.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -364,16 +366,16 @@ ul.inheritsList
    waits(timeout)
    -
    Waits for a timeout before moving to the next runs()-defined block.
    +
    Waits a fixed time period before moving to the next block.
      -
    waitsFor(timeout, latchFunction, message) +
    waitsFor(latchFunction, optional_timeoutMessage, optional_timeout)
    -
    Waits for the latchFunction to return true before proceeding to the next runs()-defined block.
    +
    Waits for the latchFunction to return true before proceeding to the next block.
    @@ -930,7 +932,7 @@ spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
    - Waits for a timeout before moving to the next runs()-defined block. + Waits a fixed time period before moving to the next block.
    Defined in: base.js. @@ -948,11 +950,18 @@ spyOn(foo, 'not'); // actual foo.not will not be called, execution stops {Number} timeout -
    +
    milliseconds to wait
    +
    +
    Deprecated:
    +
    + Use waitsFor() instead +
    +
    + @@ -965,11 +974,11 @@ spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
    - waitsFor(timeout, latchFunction, message) + waitsFor(latchFunction, optional_timeoutMessage, optional_timeout)
    - Waits for the latchFunction to return true before proceeding to the next runs()-defined block. + Waits for the latchFunction to return true before proceeding to the next block.
    Defined in: base.js. @@ -983,12 +992,6 @@ spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
    Parameters:
    -
    - {Number} timeout - -
    -
    -
    {Function} latchFunction @@ -996,7 +999,13 @@ spyOn(foo, 'not'); // actual foo.not will not be called, execution stops
    - {String} message + {String} optional_timeoutMessage + +
    +
    + +
    + {Number} optional_timeout
    @@ -1116,7 +1125,7 @@ A convenience method that allows existing specs to be disabled temporarily durin
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:42 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Block.html b/jsdoc/symbols/jasmine.Block.html index 6cf50c2..0232a4b 100644 --- a/jsdoc/symbols/jasmine.Block.html +++ b/jsdoc/symbols/jasmine.Block.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -411,7 +413,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:42 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Clock.html b/jsdoc/symbols/jasmine.Clock.html index 3241aa7..fd7463f 100644 --- a/jsdoc/symbols/jasmine.Clock.html +++ b/jsdoc/symbols/jasmine.Clock.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -706,7 +708,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:42 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Env.html b/jsdoc/symbols/jasmine.Env.html index 52c42f6..2fd6300 100644 --- a/jsdoc/symbols/jasmine.Env.html +++ b/jsdoc/symbols/jasmine.Env.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -1204,7 +1206,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.JsApiReporter.html b/jsdoc/symbols/jasmine.JsApiReporter.html index afa2bea..2e8f012 100644 --- a/jsdoc/symbols/jasmine.JsApiReporter.html +++ b/jsdoc/symbols/jasmine.JsApiReporter.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -816,7 +818,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Matchers.html b/jsdoc/symbols/jasmine.Matchers.html index 97d9708..67c471a 100644 --- a/jsdoc/symbols/jasmine.Matchers.html +++ b/jsdoc/symbols/jasmine.Matchers.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -268,6 +270,44 @@ ul.inheritsList + + + + + + + + + + + + + + + + + + + + + + + +
    Field Summary
    Field AttributesField Name and Description
      +
    + wasCalled +
    +
    +
      + +
    +
    + + + + @@ -490,24 +530,6 @@ ul.inheritsList - -   - - -
    - - - - -   - - -
    - - -   @@ -605,6 +627,69 @@ ul.inheritsList +
    + Field Detail +
    + + +
    + + + wasCalled + +
    +
    + + + +
    + + + + +
    +
    Deprecated:
    +
    + Use expect(xxx).toHaveBeenCalled() instead +
    +
    + + + + + +
    + + +
    + + + wasCalledWith + +
    +
    + + + +
    + + + + +
    +
    Deprecated:
    +
    + Use expect(xxx).toHaveBeenCalledWith() instead +
    +
    + + + + + + + + @@ -1223,6 +1308,13 @@ a pattern or a String.
    +
    +
    Deprecated:
    +
    + as of 1.0. Use not.toBe() instead. +
    +
    + @@ -1259,6 +1351,13 @@ a pattern or a String. +
    +
    Deprecated:
    +
    + as of 1.0. Use not.toNotContain() instead. +
    +
    + @@ -1295,6 +1394,13 @@ a pattern or a String. +
    +
    Deprecated:
    +
    + as of 1.0. Use not.toNotEqual() instead. +
    +
    + @@ -1331,6 +1437,13 @@ a pattern or a String. +
    +
    Deprecated:
    +
    + as of 1.0. Use not.toMatch() instead. +
    +
    + @@ -1373,70 +1486,6 @@ a pattern or a String. -
    - - -
    - - - wasCalled() - -
    -
    - - - -
    - - - - - -
    -
    Deprecated:
    -
    - Use expect(xxx).toHaveBeenCalled() instead -
    -
    - - - - - - - -
    - - -
    - - - wasCalledWith() - -
    -
    - - - -
    - - - - - -
    -
    Deprecated:
    -
    - Use expect(xxx).toHaveBeenCalledWith() instead -
    -
    - - - - - - -
    @@ -1557,7 +1606,7 @@ a pattern or a String.
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:43 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.MultiReporter.html b/jsdoc/symbols/jasmine.MultiReporter.html index c40920c..666a4fa 100644 --- a/jsdoc/symbols/jasmine.MultiReporter.html +++ b/jsdoc/symbols/jasmine.MultiReporter.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -388,7 +390,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.NestedResults.html b/jsdoc/symbols/jasmine.NestedResults.html index 4d38756..773d9fb 100644 --- a/jsdoc/symbols/jasmine.NestedResults.html +++ b/jsdoc/symbols/jasmine.NestedResults.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -704,7 +706,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Reporter.html b/jsdoc/symbols/jasmine.Reporter.html index fcf9d4b..78a5784 100644 --- a/jsdoc/symbols/jasmine.Reporter.html +++ b/jsdoc/symbols/jasmine.Reporter.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -613,7 +615,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Runner.html b/jsdoc/symbols/jasmine.Runner.html index e7b99b8..5f2e590 100644 --- a/jsdoc/symbols/jasmine.Runner.html +++ b/jsdoc/symbols/jasmine.Runner.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -738,7 +740,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Spec.html b/jsdoc/symbols/jasmine.Spec.html index f39f5f2..aaf709d 100644 --- a/jsdoc/symbols/jasmine.Spec.html +++ b/jsdoc/symbols/jasmine.Spec.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -450,16 +452,16 @@ ul.inheritsList
    waits(timeout)
    -
    +
    Waits a fixed time period before moving to the next block.
      -
    waitsFor(timeout, latchFunction, timeoutMessage) +
    waitsFor(latchFunction, optional_timeoutMessage, optional_timeout)
    -
    +
    Waits for the latchFunction to return true before proceeding to the next block.
    @@ -1116,7 +1118,7 @@ Be careful not to leave calls to jasmine.log in production code.
    - + Waits a fixed time period before moving to the next block.
    @@ -1128,14 +1130,21 @@ Be careful not to leave calls to jasmine.log in production code.
    Parameters:
    - timeout + {Number} timeout
    -
    +
    milliseconds to wait
    +
    +
    Deprecated:
    +
    + Use waitsFor() instead +
    +
    + @@ -1148,11 +1157,11 @@ Be careful not to leave calls to jasmine.log in production code.
    - waitsFor(timeout, latchFunction, timeoutMessage) + waitsFor(latchFunction, optional_timeoutMessage, optional_timeout)
    - + Waits for the latchFunction to return true before proceeding to the next block.
    @@ -1164,19 +1173,19 @@ Be careful not to leave calls to jasmine.log in production code.
    Parameters:
    - timeout + {Function} latchFunction
    - latchFunction + {String} optional_timeoutMessage
    - timeoutMessage + {Number} optional_timeout
    @@ -1204,7 +1213,7 @@ Be careful not to leave calls to jasmine.log in production code.
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Spy.html b/jsdoc/symbols/jasmine.Spy.html index 818ed9e..d0d9eb0 100644 --- a/jsdoc/symbols/jasmine.Spy.html +++ b/jsdoc/symbols/jasmine.Spy.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -850,7 +852,7 @@ expect(foo.bar.callCount).toEqual(0);
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.Suite.html b/jsdoc/symbols/jasmine.Suite.html index d177a29..6cb2311 100644 --- a/jsdoc/symbols/jasmine.Suite.html +++ b/jsdoc/symbols/jasmine.Suite.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -767,7 +769,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.WaitsForBlock.html b/jsdoc/symbols/jasmine.WaitsForBlock.html new file mode 100644 index 0000000..7843117 --- /dev/null +++ b/jsdoc/symbols/jasmine.WaitsForBlock.html @@ -0,0 +1,437 @@ + + + + + + + JsDoc Reference - jasmine.WaitsForBlock + + + + + + + + + + + + + +
    + +

    + + Class jasmine.WaitsForBlock +

    + + +

    +
    Extends + jasmine.Block.
    + + + + + +
    Defined in: WaitsForBlock.js. + +

    + + + + + + + + + + + + + + + + + +
    Class Summary
    Constructor AttributesConstructor Name and Description
      +
    + jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec) +
    +
    A block which waits for some condition to become true, with timeout.
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    Method Summary
    Method AttributesMethod Name and Description
      +
    execute(onComplete) +
    +
    +
    + + + +
    + +
    + + + + + + + +
    +
    + Class Detail +
    + +
    + jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec) +
    + +
    + A block which waits for some condition to become true, with timeout. + +
    + + + + + +
    +
    Parameters:
    + +
    + {jasmine.Env} env + +
    +
    The Jasmine environment.
    + +
    + {Number} timeout + +
    +
    The maximum time in milliseconds to wait for the condition to become true.
    + +
    + {Function} latchFunction + +
    +
    A function which returns true when the desired condition has been met.
    + +
    + {String} message + +
    +
    The message to display if the desired condition hasn't been met within the given time period.
    + +
    + {jasmine.Spec} spec + +
    +
    The Jasmine spec.
    + +
    + + + + + + + + +
    + + + + + + + +
    + Method Detail +
    + + +
    + + + execute(onComplete) + +
    +
    + + + +
    + + + + +
    +
    Parameters:
    + +
    + onComplete + +
    +
    + +
    + + + + + + + + + + + + + + + +
    +
    + + + +
    + + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT) +
    + + diff --git a/jsdoc/symbols/jasmine.html b/jsdoc/symbols/jasmine.html index 66b739f..0f7bc52 100644 --- a/jsdoc/symbols/jasmine.html +++ b/jsdoc/symbols/jasmine.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -280,13 +282,23 @@ ul.inheritsList + + <static>   + + +
    Default timeout interval in milliseconds for waitsFor() blocks.
    + + + <static>   -
    Default interval for event loop yields.
    +
    Default interval in milliseconds for event loop yields (e.g.
    @@ -464,15 +476,6 @@ ul.inheritsList - - <static>   - -
    jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec) -
    -
    - - - @@ -518,6 +521,28 @@ ul.inheritsList Field Detail
    + +
    <static> + + + jasmine.DEFAULT_TIMEOUT_INTERVAL + +
    +
    + Default timeout interval in milliseconds for waitsFor() blocks. + + +
    + + + + + + + + +
    +
    <static> @@ -526,7 +551,7 @@ ul.inheritsList
    - Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed. + 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.
    @@ -1164,69 +1189,6 @@ Be careful not to leave calls to jasmine.log in production code. -
    - - -
    <static> - - - jasmine.WaitsForBlock(env, timeout, latchFunction, message, spec) - -
    -
    - - -
    - Defined in: WaitsForBlock.js. - - -
    - - - - -
    -
    Parameters:
    - -
    - env - -
    -
    - -
    - timeout - -
    -
    - -
    - latchFunction - -
    -
    - -
    - message - -
    -
    - -
    - spec - -
    -
    - -
    - - - - - - - - @@ -1241,7 +1203,7 @@ Be careful not to leave calls to jasmine.log in production code.
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:42 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/jasmine.util.html b/jsdoc/symbols/jasmine.util.html index 0526e02..87585a7 100644 --- a/jsdoc/symbols/jasmine.util.html +++ b/jsdoc/symbols/jasmine.util.html @@ -219,6 +219,8 @@ ul.inheritsList
  • jasmine.util
  • +
  • jasmine.WaitsForBlock
  • +
    @@ -529,7 +531,7 @@ ul.inheritsList
    - Documentation generated by JsDoc Toolkit 2.1.0 on Fri Jun 25 2010 18:09:44 GMT-0700 (PDT) + Documentation generated by JsDoc Toolkit 2.1.0 on Wed Aug 25 2010 18:21:27 GMT-0700 (PDT)
    diff --git a/jsdoc/symbols/src/src_Env.js.html b/jsdoc/symbols/src/src_Env.js.html index 3d8863c..bdcf2ef 100644 --- a/jsdoc/symbols/src/src_Env.js.html +++ b/jsdoc/symbols/src/src_Env.js.html @@ -18,254 +18,255 @@ 11 this.reporter = new jasmine.MultiReporter(); 12 13 this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL; - 14 this.lastUpdate = 0; - 15 this.specFilter = function() { - 16 return true; - 17 }; - 18 - 19 this.nextSpecId_ = 0; - 20 this.nextSuiteId_ = 0; - 21 this.equalityTesters_ = []; - 22 - 23 // wrap matchers - 24 this.matchersClass = function() { - 25 jasmine.Matchers.apply(this, arguments); - 26 }; - 27 jasmine.util.inherit(this.matchersClass, jasmine.Matchers); - 28 - 29 jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); - 30 }; - 31 + 14 this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL; + 15 this.lastUpdate = 0; + 16 this.specFilter = function() { + 17 return true; + 18 }; + 19 + 20 this.nextSpecId_ = 0; + 21 this.nextSuiteId_ = 0; + 22 this.equalityTesters_ = []; + 23 + 24 // wrap matchers + 25 this.matchersClass = function() { + 26 jasmine.Matchers.apply(this, arguments); + 27 }; + 28 jasmine.util.inherit(this.matchersClass, jasmine.Matchers); + 29 + 30 jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); + 31 }; 32 - 33 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; - 34 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; - 35 jasmine.Env.prototype.setInterval = jasmine.setInterval; - 36 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; - 37 - 38 /** - 39 * @returns an object containing jasmine version build info, if set. - 40 */ - 41 jasmine.Env.prototype.version = function () { - 42 if (jasmine.version_) { - 43 return jasmine.version_; - 44 } else { - 45 throw new Error('Version not set'); - 46 } - 47 }; - 48 - 49 /** - 50 * @returns string containing jasmine version build info, if set. - 51 */ - 52 jasmine.Env.prototype.versionString = function() { - 53 if (jasmine.version_) { - 54 var version = this.version(); - 55 return version.major + "." + version.minor + "." + version.build + " revision " + version.revision; - 56 } else { - 57 return "version unknown"; - 58 } - 59 }; - 60 - 61 /** - 62 * @returns a sequential integer starting at 0 - 63 */ - 64 jasmine.Env.prototype.nextSpecId = function () { - 65 return this.nextSpecId_++; - 66 }; - 67 - 68 /** - 69 * @returns a sequential integer starting at 0 - 70 */ - 71 jasmine.Env.prototype.nextSuiteId = function () { - 72 return this.nextSuiteId_++; - 73 }; - 74 - 75 /** - 76 * Register a reporter to receive status updates from Jasmine. - 77 * @param {jasmine.Reporter} reporter An object which will receive status updates. - 78 */ - 79 jasmine.Env.prototype.addReporter = function(reporter) { - 80 this.reporter.addReporter(reporter); - 81 }; - 82 - 83 jasmine.Env.prototype.execute = function() { - 84 this.currentRunner_.execute(); - 85 }; - 86 - 87 jasmine.Env.prototype.describe = function(description, specDefinitions) { - 88 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); - 89 - 90 var parentSuite = this.currentSuite; - 91 if (parentSuite) { - 92 parentSuite.add(suite); - 93 } else { - 94 this.currentRunner_.add(suite); - 95 } - 96 - 97 this.currentSuite = suite; - 98 - 99 var declarationError = null; -100 try { -101 specDefinitions.call(suite); -102 } catch(e) { -103 declarationError = e; -104 } -105 -106 this.currentSuite = parentSuite; -107 -108 if (declarationError) { -109 this.it("encountered a declaration exception", function() { -110 throw declarationError; -111 }); -112 } -113 -114 return suite; -115 }; -116 -117 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { -118 if (this.currentSuite) { -119 this.currentSuite.beforeEach(beforeEachFunction); -120 } else { -121 this.currentRunner_.beforeEach(beforeEachFunction); -122 } -123 }; -124 -125 jasmine.Env.prototype.currentRunner = function () { -126 return this.currentRunner_; -127 }; -128 -129 jasmine.Env.prototype.afterEach = function(afterEachFunction) { -130 if (this.currentSuite) { -131 this.currentSuite.afterEach(afterEachFunction); -132 } else { -133 this.currentRunner_.afterEach(afterEachFunction); -134 } -135 -136 }; -137 -138 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { -139 return { -140 execute: function() { -141 } -142 }; -143 }; -144 -145 jasmine.Env.prototype.it = function(description, func) { -146 var spec = new jasmine.Spec(this, this.currentSuite, description); -147 this.currentSuite.add(spec); -148 this.currentSpec = spec; -149 -150 if (func) { -151 spec.runs(func); -152 } -153 -154 return spec; -155 }; -156 -157 jasmine.Env.prototype.xit = function(desc, func) { -158 return { -159 id: this.nextSpecId(), -160 runs: function() { -161 } -162 }; -163 }; -164 -165 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { -166 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { -167 return true; -168 } -169 -170 a.__Jasmine_been_here_before__ = b; -171 b.__Jasmine_been_here_before__ = a; -172 -173 var hasKey = function(obj, keyName) { -174 return obj != null && obj[keyName] !== jasmine.undefined; -175 }; -176 -177 for (var property in b) { -178 if (!hasKey(a, property) && hasKey(b, property)) { -179 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); -180 } -181 } -182 for (property in a) { -183 if (!hasKey(b, property) && hasKey(a, property)) { -184 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); -185 } -186 } -187 for (property in b) { -188 if (property == '__Jasmine_been_here_before__') continue; -189 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { -190 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); -191 } -192 } -193 -194 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { -195 mismatchValues.push("arrays were not the same length"); -196 } -197 -198 delete a.__Jasmine_been_here_before__; -199 delete b.__Jasmine_been_here_before__; -200 return (mismatchKeys.length == 0 && mismatchValues.length == 0); -201 }; -202 -203 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { -204 mismatchKeys = mismatchKeys || []; -205 mismatchValues = mismatchValues || []; -206 -207 for (var i = 0; i < this.equalityTesters_.length; i++) { -208 var equalityTester = this.equalityTesters_[i]; -209 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); -210 if (result !== jasmine.undefined) return result; -211 } -212 -213 if (a === b) return true; -214 -215 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { -216 return (a == jasmine.undefined && b == jasmine.undefined); -217 } -218 -219 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { -220 return a === b; -221 } -222 -223 if (a instanceof Date && b instanceof Date) { -224 return a.getTime() == b.getTime(); -225 } -226 -227 if (a instanceof jasmine.Matchers.Any) { -228 return a.matches(b); -229 } -230 -231 if (b instanceof jasmine.Matchers.Any) { -232 return b.matches(a); -233 } -234 -235 if (jasmine.isString_(a) && jasmine.isString_(b)) { -236 return (a == b); -237 } -238 -239 if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { -240 return (a == b); -241 } -242 -243 if (typeof a === "object" && typeof b === "object") { -244 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); -245 } -246 -247 //Straight check -248 return (a === b); -249 }; -250 -251 jasmine.Env.prototype.contains_ = function(haystack, needle) { -252 if (jasmine.isArray_(haystack)) { -253 for (var i = 0; i < haystack.length; i++) { -254 if (this.equals_(haystack[i], needle)) return true; -255 } -256 return false; -257 } -258 return haystack.indexOf(needle) >= 0; -259 }; -260 -261 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { -262 this.equalityTesters_.push(equalityTester); -263 }; -264 \ No newline at end of file + 33 + 34 jasmine.Env.prototype.setTimeout = jasmine.setTimeout; + 35 jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; + 36 jasmine.Env.prototype.setInterval = jasmine.setInterval; + 37 jasmine.Env.prototype.clearInterval = jasmine.clearInterval; + 38 + 39 /** + 40 * @returns an object containing jasmine version build info, if set. + 41 */ + 42 jasmine.Env.prototype.version = function () { + 43 if (jasmine.version_) { + 44 return jasmine.version_; + 45 } else { + 46 throw new Error('Version not set'); + 47 } + 48 }; + 49 + 50 /** + 51 * @returns string containing jasmine version build info, if set. + 52 */ + 53 jasmine.Env.prototype.versionString = function() { + 54 if (jasmine.version_) { + 55 var version = this.version(); + 56 return version.major + "." + version.minor + "." + version.build + " revision " + version.revision; + 57 } else { + 58 return "version unknown"; + 59 } + 60 }; + 61 + 62 /** + 63 * @returns a sequential integer starting at 0 + 64 */ + 65 jasmine.Env.prototype.nextSpecId = function () { + 66 return this.nextSpecId_++; + 67 }; + 68 + 69 /** + 70 * @returns a sequential integer starting at 0 + 71 */ + 72 jasmine.Env.prototype.nextSuiteId = function () { + 73 return this.nextSuiteId_++; + 74 }; + 75 + 76 /** + 77 * Register a reporter to receive status updates from Jasmine. + 78 * @param {jasmine.Reporter} reporter An object which will receive status updates. + 79 */ + 80 jasmine.Env.prototype.addReporter = function(reporter) { + 81 this.reporter.addReporter(reporter); + 82 }; + 83 + 84 jasmine.Env.prototype.execute = function() { + 85 this.currentRunner_.execute(); + 86 }; + 87 + 88 jasmine.Env.prototype.describe = function(description, specDefinitions) { + 89 var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); + 90 + 91 var parentSuite = this.currentSuite; + 92 if (parentSuite) { + 93 parentSuite.add(suite); + 94 } else { + 95 this.currentRunner_.add(suite); + 96 } + 97 + 98 this.currentSuite = suite; + 99 +100 var declarationError = null; +101 try { +102 specDefinitions.call(suite); +103 } catch(e) { +104 declarationError = e; +105 } +106 +107 this.currentSuite = parentSuite; +108 +109 if (declarationError) { +110 this.it("encountered a declaration exception", function() { +111 throw declarationError; +112 }); +113 } +114 +115 return suite; +116 }; +117 +118 jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { +119 if (this.currentSuite) { +120 this.currentSuite.beforeEach(beforeEachFunction); +121 } else { +122 this.currentRunner_.beforeEach(beforeEachFunction); +123 } +124 }; +125 +126 jasmine.Env.prototype.currentRunner = function () { +127 return this.currentRunner_; +128 }; +129 +130 jasmine.Env.prototype.afterEach = function(afterEachFunction) { +131 if (this.currentSuite) { +132 this.currentSuite.afterEach(afterEachFunction); +133 } else { +134 this.currentRunner_.afterEach(afterEachFunction); +135 } +136 +137 }; +138 +139 jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +140 return { +141 execute: function() { +142 } +143 }; +144 }; +145 +146 jasmine.Env.prototype.it = function(description, func) { +147 var spec = new jasmine.Spec(this, this.currentSuite, description); +148 this.currentSuite.add(spec); +149 this.currentSpec = spec; +150 +151 if (func) { +152 spec.runs(func); +153 } +154 +155 return spec; +156 }; +157 +158 jasmine.Env.prototype.xit = function(desc, func) { +159 return { +160 id: this.nextSpecId(), +161 runs: function() { +162 } +163 }; +164 }; +165 +166 jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { +167 if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { +168 return true; +169 } +170 +171 a.__Jasmine_been_here_before__ = b; +172 b.__Jasmine_been_here_before__ = a; +173 +174 var hasKey = function(obj, keyName) { +175 return obj != null && obj[keyName] !== jasmine.undefined; +176 }; +177 +178 for (var property in b) { +179 if (!hasKey(a, property) && hasKey(b, property)) { +180 mismatchKeys.push("expected has key '" + property + "', but missing from actual."); +181 } +182 } +183 for (property in a) { +184 if (!hasKey(b, property) && hasKey(a, property)) { +185 mismatchKeys.push("expected missing key '" + property + "', but present in actual."); +186 } +187 } +188 for (property in b) { +189 if (property == '__Jasmine_been_here_before__') continue; +190 if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { +191 mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); +192 } +193 } +194 +195 if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { +196 mismatchValues.push("arrays were not the same length"); +197 } +198 +199 delete a.__Jasmine_been_here_before__; +200 delete b.__Jasmine_been_here_before__; +201 return (mismatchKeys.length == 0 && mismatchValues.length == 0); +202 }; +203 +204 jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +205 mismatchKeys = mismatchKeys || []; +206 mismatchValues = mismatchValues || []; +207 +208 for (var i = 0; i < this.equalityTesters_.length; i++) { +209 var equalityTester = this.equalityTesters_[i]; +210 var result = equalityTester(a, b, this, mismatchKeys, mismatchValues); +211 if (result !== jasmine.undefined) return result; +212 } +213 +214 if (a === b) return true; +215 +216 if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { +217 return (a == jasmine.undefined && b == jasmine.undefined); +218 } +219 +220 if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { +221 return a === b; +222 } +223 +224 if (a instanceof Date && b instanceof Date) { +225 return a.getTime() == b.getTime(); +226 } +227 +228 if (a instanceof jasmine.Matchers.Any) { +229 return a.matches(b); +230 } +231 +232 if (b instanceof jasmine.Matchers.Any) { +233 return b.matches(a); +234 } +235 +236 if (jasmine.isString_(a) && jasmine.isString_(b)) { +237 return (a == b); +238 } +239 +240 if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { +241 return (a == b); +242 } +243 +244 if (typeof a === "object" && typeof b === "object") { +245 return this.compareObjects_(a, b, mismatchKeys, mismatchValues); +246 } +247 +248 //Straight check +249 return (a === b); +250 }; +251 +252 jasmine.Env.prototype.contains_ = function(haystack, needle) { +253 if (jasmine.isArray_(haystack)) { +254 for (var i = 0; i < haystack.length; i++) { +255 if (this.equals_(haystack[i], needle)) return true; +256 } +257 return false; +258 } +259 return haystack.indexOf(needle) >= 0; +260 }; +261 +262 jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +263 this.equalityTesters_.push(equalityTester); +264 }; +265 \ No newline at end of file diff --git a/jsdoc/symbols/src/src_Matchers.js.html b/jsdoc/symbols/src/src_Matchers.js.html index 62d2fd7..ab3d5fb 100644 --- a/jsdoc/symbols/src/src_Matchers.js.html +++ b/jsdoc/symbols/src/src_Matchers.js.html @@ -75,7 +75,7 @@ 68 message: message 69 }); 70 this.spec.addMatcherResult(expectationResult); - 71 return result; + 71 return jasmine.undefined; 72 }; 73 }; 74 @@ -93,252 +93,270 @@ 86 /** 87 * toNotBe: compares the actual to the expected using !== 88 * @param expected - 89 */ - 90 jasmine.Matchers.prototype.toNotBe = function(expected) { - 91 return this.actual !== expected; - 92 }; - 93 - 94 /** - 95 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. - 96 * - 97 * @param expected - 98 */ - 99 jasmine.Matchers.prototype.toEqual = function(expected) { -100 return this.env.equals_(this.actual, expected); -101 }; -102 -103 /** -104 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual -105 * @param expected -106 */ -107 jasmine.Matchers.prototype.toNotEqual = function(expected) { -108 return !this.env.equals_(this.actual, expected); -109 }; -110 -111 /** -112 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes -113 * a pattern or a String. -114 * -115 * @param expected -116 */ -117 jasmine.Matchers.prototype.toMatch = function(expected) { -118 return new RegExp(expected).test(this.actual); -119 }; -120 -121 /** -122 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch -123 * @param expected -124 */ -125 jasmine.Matchers.prototype.toNotMatch = function(expected) { -126 return !(new RegExp(expected).test(this.actual)); -127 }; -128 -129 /** -130 * Matcher that compares the actual to jasmine.undefined. -131 */ -132 jasmine.Matchers.prototype.toBeDefined = function() { -133 return (this.actual !== jasmine.undefined); -134 }; -135 -136 /** -137 * Matcher that compares the actual to jasmine.undefined. -138 */ -139 jasmine.Matchers.prototype.toBeUndefined = function() { -140 return (this.actual === jasmine.undefined); -141 }; -142 -143 /** -144 * Matcher that compares the actual to null. -145 */ -146 jasmine.Matchers.prototype.toBeNull = function() { -147 return (this.actual === null); -148 }; -149 -150 /** -151 * Matcher that boolean not-nots the actual. -152 */ -153 jasmine.Matchers.prototype.toBeTruthy = function() { -154 return !!this.actual; -155 }; -156 -157 -158 /** -159 * Matcher that boolean nots the actual. -160 */ -161 jasmine.Matchers.prototype.toBeFalsy = function() { -162 return !this.actual; -163 }; -164 -165 -166 /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */ -167 jasmine.Matchers.prototype.wasCalled = function() { -168 return this.toHaveBeenCalled(); -169 }; -170 -171 /** -172 * Matcher that checks to see if the actual, a Jasmine spy, was called. -173 */ -174 jasmine.Matchers.prototype.toHaveBeenCalled = function() { -175 if (arguments.length > 0) { -176 throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); -177 } -178 -179 if (!jasmine.isSpy(this.actual)) { -180 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -181 } -182 -183 this.message = function() { -184 return "Expected spy " + this.actual.identity + " to have been called."; -185 }; -186 -187 return this.actual.wasCalled; -188 }; -189 -190 /** -191 * Matcher that checks to see if the actual, a Jasmine spy, was not called. -192 * -193 * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead -194 */ -195 jasmine.Matchers.prototype.wasNotCalled = function() { -196 if (arguments.length > 0) { -197 throw new Error('wasNotCalled does not take arguments'); -198 } -199 -200 if (!jasmine.isSpy(this.actual)) { -201 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); + 89 * @deprecated as of 1.0. Use not.toBe() instead. + 90 */ + 91 jasmine.Matchers.prototype.toNotBe = function(expected) { + 92 return this.actual !== expected; + 93 }; + 94 + 95 /** + 96 * toEqual: compares the actual to the expected using common sense equality. Handles Objects, Arrays, etc. + 97 * + 98 * @param expected + 99 */ +100 jasmine.Matchers.prototype.toEqual = function(expected) { +101 return this.env.equals_(this.actual, expected); +102 }; +103 +104 /** +105 * toNotEqual: compares the actual to the expected using the ! of jasmine.Matchers.toEqual +106 * @param expected +107 * @deprecated as of 1.0. Use not.toNotEqual() instead. +108 */ +109 jasmine.Matchers.prototype.toNotEqual = function(expected) { +110 return !this.env.equals_(this.actual, expected); +111 }; +112 +113 /** +114 * Matcher that compares the actual to the expected using a regular expression. Constructs a RegExp, so takes +115 * a pattern or a String. +116 * +117 * @param expected +118 */ +119 jasmine.Matchers.prototype.toMatch = function(expected) { +120 return new RegExp(expected).test(this.actual); +121 }; +122 +123 /** +124 * Matcher that compares the actual to the expected using the boolean inverse of jasmine.Matchers.toMatch +125 * @param expected +126 * @deprecated as of 1.0. Use not.toMatch() instead. +127 */ +128 jasmine.Matchers.prototype.toNotMatch = function(expected) { +129 return !(new RegExp(expected).test(this.actual)); +130 }; +131 +132 /** +133 * Matcher that compares the actual to jasmine.undefined. +134 */ +135 jasmine.Matchers.prototype.toBeDefined = function() { +136 return (this.actual !== jasmine.undefined); +137 }; +138 +139 /** +140 * Matcher that compares the actual to jasmine.undefined. +141 */ +142 jasmine.Matchers.prototype.toBeUndefined = function() { +143 return (this.actual === jasmine.undefined); +144 }; +145 +146 /** +147 * Matcher that compares the actual to null. +148 */ +149 jasmine.Matchers.prototype.toBeNull = function() { +150 return (this.actual === null); +151 }; +152 +153 /** +154 * Matcher that boolean not-nots the actual. +155 */ +156 jasmine.Matchers.prototype.toBeTruthy = function() { +157 return !!this.actual; +158 }; +159 +160 +161 /** +162 * Matcher that boolean nots the actual. +163 */ +164 jasmine.Matchers.prototype.toBeFalsy = function() { +165 return !this.actual; +166 }; +167 +168 +169 /** +170 * Matcher that checks to see if the actual, a Jasmine spy, was called. +171 */ +172 jasmine.Matchers.prototype.toHaveBeenCalled = function() { +173 if (arguments.length > 0) { +174 throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); +175 } +176 +177 if (!jasmine.isSpy(this.actual)) { +178 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +179 } +180 +181 this.message = function() { +182 return [ +183 "Expected spy " + this.actual.identity + " to have been called.", +184 "Expected spy " + this.actual.identity + " not to have been called." +185 ]; +186 }; +187 +188 return this.actual.wasCalled; +189 }; +190 +191 /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */ +192 jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled; +193 +194 /** +195 * Matcher that checks to see if the actual, a Jasmine spy, was not called. +196 * +197 * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead +198 */ +199 jasmine.Matchers.prototype.wasNotCalled = function() { +200 if (arguments.length > 0) { +201 throw new Error('wasNotCalled does not take arguments'); 202 } 203 -204 this.message = function() { -205 return "Expected spy " + this.actual.identity + " to not have been called."; -206 }; +204 if (!jasmine.isSpy(this.actual)) { +205 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +206 } 207 -208 return !this.actual.wasCalled; -209 }; -210 -211 /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */ -212 jasmine.Matchers.prototype.wasCalledWith = function() { -213 return this.toHaveBeenCalledWith.apply(this, arguments); -214 }; -215 -216 /** -217 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. -218 * -219 * @example +208 this.message = function() { +209 return [ +210 "Expected spy " + this.actual.identity + " to not have been called.", +211 "Expected spy " + this.actual.identity + " to have been called." +212 ]; +213 }; +214 +215 return !this.actual.wasCalled; +216 }; +217 +218 /** +219 * Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters. 220 * -221 */ -222 jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { -223 var expectedArgs = jasmine.util.argsToArray(arguments); -224 if (!jasmine.isSpy(this.actual)) { -225 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -226 } -227 this.message = function() { -228 if (this.actual.callCount == 0) { -229 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; -230 } else { -231 return "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall); -232 } -233 }; -234 -235 return this.env.contains_(this.actual.argsForCall, expectedArgs); -236 }; -237 -238 /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */ -239 jasmine.Matchers.prototype.wasNotCalledWith = function() { -240 var expectedArgs = jasmine.util.argsToArray(arguments); -241 if (!jasmine.isSpy(this.actual)) { -242 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); -243 } -244 -245 this.message = function() { -246 return "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was"; -247 }; -248 -249 return !this.env.contains_(this.actual.argsForCall, expectedArgs); -250 }; -251 -252 /** -253 * Matcher that checks that the expected item is an element in the actual Array. -254 * -255 * @param {Object} expected -256 */ -257 jasmine.Matchers.prototype.toContain = function(expected) { -258 return this.env.contains_(this.actual, expected); -259 }; -260 -261 /** -262 * Matcher that checks that the expected item is NOT an element in the actual Array. -263 * -264 * @param {Object} expected -265 */ -266 jasmine.Matchers.prototype.toNotContain = function(expected) { -267 return !this.env.contains_(this.actual, expected); -268 }; -269 -270 jasmine.Matchers.prototype.toBeLessThan = function(expected) { -271 return this.actual < expected; -272 }; -273 -274 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { -275 return this.actual > expected; -276 }; -277 -278 /** -279 * Matcher that checks that the expected exception was thrown by the actual. -280 * -281 * @param {String} expected -282 */ -283 jasmine.Matchers.prototype.toThrow = function(expected) { -284 var result = false; -285 var exception; -286 if (typeof this.actual != 'function') { -287 throw new Error('Actual is not a function'); -288 } -289 try { -290 this.actual(); -291 } catch (e) { -292 exception = e; -293 } -294 if (exception) { -295 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); -296 } -297 -298 this.message = function() { -299 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { -300 return ["Expected function to throw", expected.message || expected, ", but it threw", exception.message || exception].join(' '); -301 } else { -302 return "Expected function to throw an exception."; -303 } -304 }; -305 -306 return result; -307 }; -308 -309 jasmine.Matchers.Any = function(expectedClass) { -310 this.expectedClass = expectedClass; -311 }; -312 -313 jasmine.Matchers.Any.prototype.matches = function(other) { -314 if (this.expectedClass == String) { -315 return typeof other == 'string' || other instanceof String; -316 } -317 -318 if (this.expectedClass == Number) { -319 return typeof other == 'number' || other instanceof Number; -320 } -321 -322 if (this.expectedClass == Function) { -323 return typeof other == 'function' || other instanceof Function; -324 } -325 -326 if (this.expectedClass == Object) { -327 return typeof other == 'object'; -328 } -329 -330 return other instanceof this.expectedClass; -331 }; -332 -333 jasmine.Matchers.Any.prototype.toString = function() { -334 return '<jasmine.any(' + this.expectedClass + ')>'; -335 }; -336 -337 \ No newline at end of file +221 * @example +222 * +223 */ +224 jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { +225 var expectedArgs = jasmine.util.argsToArray(arguments); +226 if (!jasmine.isSpy(this.actual)) { +227 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +228 } +229 this.message = function() { +230 if (this.actual.callCount == 0) { +231 // todo: what should the failure message for .not.toHaveBeenCalledWith() be? is this right? test better. [xw] +232 return [ +233 "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was never called.", +234 "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was." +235 ]; +236 } else { +237 return [ +238 "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall), +239 "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but was called with " + jasmine.pp(this.actual.argsForCall) +240 ]; +241 } +242 }; +243 +244 return this.env.contains_(this.actual.argsForCall, expectedArgs); +245 }; +246 +247 /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */ +248 jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith; +249 +250 /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */ +251 jasmine.Matchers.prototype.wasNotCalledWith = function() { +252 var expectedArgs = jasmine.util.argsToArray(arguments); +253 if (!jasmine.isSpy(this.actual)) { +254 throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +255 } +256 +257 this.message = function() { +258 return [ +259 "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was", +260 "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was" +261 ] +262 }; +263 +264 return !this.env.contains_(this.actual.argsForCall, expectedArgs); +265 }; +266 +267 /** +268 * Matcher that checks that the expected item is an element in the actual Array. +269 * +270 * @param {Object} expected +271 */ +272 jasmine.Matchers.prototype.toContain = function(expected) { +273 return this.env.contains_(this.actual, expected); +274 }; +275 +276 /** +277 * Matcher that checks that the expected item is NOT an element in the actual Array. +278 * +279 * @param {Object} expected +280 * @deprecated as of 1.0. Use not.toNotContain() instead. +281 */ +282 jasmine.Matchers.prototype.toNotContain = function(expected) { +283 return !this.env.contains_(this.actual, expected); +284 }; +285 +286 jasmine.Matchers.prototype.toBeLessThan = function(expected) { +287 return this.actual < expected; +288 }; +289 +290 jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +291 return this.actual > expected; +292 }; +293 +294 /** +295 * Matcher that checks that the expected exception was thrown by the actual. +296 * +297 * @param {String} expected +298 */ +299 jasmine.Matchers.prototype.toThrow = function(expected) { +300 var result = false; +301 var exception; +302 if (typeof this.actual != 'function') { +303 throw new Error('Actual is not a function'); +304 } +305 try { +306 this.actual(); +307 } catch (e) { +308 exception = e; +309 } +310 if (exception) { +311 result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); +312 } +313 +314 var not = this.isNot ? "not " : ""; +315 +316 this.message = function() { +317 if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { +318 return ["Expected function " + not + "to throw", expected ? expected.message || expected : " an exception", ", but it threw", exception.message || exception].join(' '); +319 } else { +320 return "Expected function to throw an exception."; +321 } +322 }; +323 +324 return result; +325 }; +326 +327 jasmine.Matchers.Any = function(expectedClass) { +328 this.expectedClass = expectedClass; +329 }; +330 +331 jasmine.Matchers.Any.prototype.matches = function(other) { +332 if (this.expectedClass == String) { +333 return typeof other == 'string' || other instanceof String; +334 } +335 +336 if (this.expectedClass == Number) { +337 return typeof other == 'number' || other instanceof Number; +338 } +339 +340 if (this.expectedClass == Function) { +341 return typeof other == 'function' || other instanceof Function; +342 } +343 +344 if (this.expectedClass == Object) { +345 return typeof other == 'object'; +346 } +347 +348 return other instanceof this.expectedClass; +349 }; +350 +351 jasmine.Matchers.Any.prototype.toString = function() { +352 return '<jasmine.any(' + this.expectedClass + ')>'; +353 }; +354 +355 \ No newline at end of file diff --git a/jsdoc/symbols/src/src_Queue.js.html b/jsdoc/symbols/src/src_Queue.js.html index fc81c10..3e798fc 100644 --- a/jsdoc/symbols/src/src_Queue.js.html +++ b/jsdoc/symbols/src/src_Queue.js.html @@ -11,92 +11,97 @@ 4 this.running = false; 5 this.index = 0; 6 this.offset = 0; - 7 }; - 8 - 9 jasmine.Queue.prototype.addBefore = function(block) { - 10 this.blocks.unshift(block); - 11 }; - 12 - 13 jasmine.Queue.prototype.add = function(block) { - 14 this.blocks.push(block); - 15 }; - 16 - 17 jasmine.Queue.prototype.insertNext = function(block) { - 18 this.blocks.splice((this.index + this.offset + 1), 0, block); - 19 this.offset++; - 20 }; - 21 - 22 jasmine.Queue.prototype.start = function(onComplete) { - 23 this.running = true; - 24 this.onComplete = onComplete; - 25 this.next_(); - 26 }; - 27 - 28 jasmine.Queue.prototype.isRunning = function() { - 29 return this.running; - 30 }; - 31 - 32 jasmine.Queue.LOOP_DONT_RECURSE = true; - 33 - 34 jasmine.Queue.prototype.next_ = function() { - 35 var self = this; - 36 var goAgain = true; - 37 - 38 while (goAgain) { - 39 goAgain = false; - 40 - 41 if (self.index < self.blocks.length) { - 42 var calledSynchronously = true; - 43 var completedSynchronously = false; - 44 - 45 var onComplete = function () { - 46 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { - 47 completedSynchronously = true; - 48 return; - 49 } - 50 - 51 self.offset = 0; - 52 self.index++; - 53 - 54 var now = new Date().getTime(); - 55 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { - 56 self.env.lastUpdate = now; - 57 self.env.setTimeout(function() { - 58 self.next_(); - 59 }, 0); - 60 } else { - 61 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { - 62 goAgain = true; - 63 } else { - 64 self.next_(); - 65 } - 66 } - 67 }; - 68 self.blocks[self.index].execute(onComplete); - 69 - 70 calledSynchronously = false; - 71 if (completedSynchronously) { - 72 onComplete(); - 73 } - 74 - 75 } else { - 76 self.running = false; - 77 if (self.onComplete) { - 78 self.onComplete(); - 79 } - 80 } - 81 } - 82 }; - 83 - 84 jasmine.Queue.prototype.results = function() { - 85 var results = new jasmine.NestedResults(); - 86 for (var i = 0; i < this.blocks.length; i++) { - 87 if (this.blocks[i].results) { - 88 results.addResult(this.blocks[i].results()); - 89 } - 90 } - 91 return results; - 92 }; - 93 - 94 - 95 \ No newline at end of file + 7 this.abort = false; + 8 }; + 9 + 10 jasmine.Queue.prototype.addBefore = function(block) { + 11 this.blocks.unshift(block); + 12 }; + 13 + 14 jasmine.Queue.prototype.add = function(block) { + 15 this.blocks.push(block); + 16 }; + 17 + 18 jasmine.Queue.prototype.insertNext = function(block) { + 19 this.blocks.splice((this.index + this.offset + 1), 0, block); + 20 this.offset++; + 21 }; + 22 + 23 jasmine.Queue.prototype.start = function(onComplete) { + 24 this.running = true; + 25 this.onComplete = onComplete; + 26 this.next_(); + 27 }; + 28 + 29 jasmine.Queue.prototype.isRunning = function() { + 30 return this.running; + 31 }; + 32 + 33 jasmine.Queue.LOOP_DONT_RECURSE = true; + 34 + 35 jasmine.Queue.prototype.next_ = function() { + 36 var self = this; + 37 var goAgain = true; + 38 + 39 while (goAgain) { + 40 goAgain = false; + 41 + 42 if (self.index < self.blocks.length && !this.abort) { + 43 var calledSynchronously = true; + 44 var completedSynchronously = false; + 45 + 46 var onComplete = function () { + 47 if (jasmine.Queue.LOOP_DONT_RECURSE && calledSynchronously) { + 48 completedSynchronously = true; + 49 return; + 50 } + 51 + 52 if (self.blocks[self.index].abort) { + 53 self.abort = true; + 54 } + 55 + 56 self.offset = 0; + 57 self.index++; + 58 + 59 var now = new Date().getTime(); + 60 if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { + 61 self.env.lastUpdate = now; + 62 self.env.setTimeout(function() { + 63 self.next_(); + 64 }, 0); + 65 } else { + 66 if (jasmine.Queue.LOOP_DONT_RECURSE && completedSynchronously) { + 67 goAgain = true; + 68 } else { + 69 self.next_(); + 70 } + 71 } + 72 }; + 73 self.blocks[self.index].execute(onComplete); + 74 + 75 calledSynchronously = false; + 76 if (completedSynchronously) { + 77 onComplete(); + 78 } + 79 + 80 } else { + 81 self.running = false; + 82 if (self.onComplete) { + 83 self.onComplete(); + 84 } + 85 } + 86 } + 87 }; + 88 + 89 jasmine.Queue.prototype.results = function() { + 90 var results = new jasmine.NestedResults(); + 91 for (var i = 0; i < this.blocks.length; i++) { + 92 if (this.blocks[i].results) { + 93 results.addResult(this.blocks[i].results()); + 94 } + 95 } + 96 return results; + 97 }; + 98 + 99 +100 \ No newline at end of file diff --git a/jsdoc/symbols/src/src_Spec.js.html b/jsdoc/symbols/src/src_Spec.js.html index bc8ef25..8d7ef7f 100644 --- a/jsdoc/symbols/src/src_Spec.js.html +++ b/jsdoc/symbols/src/src_Spec.js.html @@ -80,139 +80,171 @@ 73 return positive; 74 }; 75 - 76 jasmine.Spec.prototype.waits = function(timeout) { - 77 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); - 78 this.addToQueue(waitsFunc); - 79 return this; - 80 }; - 81 - 82 jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessage) { - 83 var waitsForFunc = new jasmine.WaitsForBlock(this.env, timeout, latchFunction, timeoutMessage, this); - 84 this.addToQueue(waitsForFunc); + 76 /** + 77 * Waits a fixed time period before moving to the next block. + 78 * + 79 * @deprecated Use waitsFor() instead + 80 * @param {Number} timeout milliseconds to wait + 81 */ + 82 jasmine.Spec.prototype.waits = function(timeout) { + 83 var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); + 84 this.addToQueue(waitsFunc); 85 return this; 86 }; 87 - 88 jasmine.Spec.prototype.fail = function (e) { - 89 var expectationResult = new jasmine.ExpectationResult({ - 90 passed: false, - 91 message: e ? jasmine.util.formatException(e) : 'Exception' - 92 }); - 93 this.results_.addResult(expectationResult); - 94 }; - 95 - 96 jasmine.Spec.prototype.getMatchersClass_ = function() { - 97 return this.matchersClass || this.env.matchersClass; - 98 }; + 88 /** + 89 * Waits for the latchFunction to return true before proceeding to the next block. + 90 * + 91 * @param {Function} latchFunction + 92 * @param {String} optional_timeoutMessage + 93 * @param {Number} optional_timeout + 94 */ + 95 jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { + 96 var latchFunction_ = null; + 97 var optional_timeoutMessage_ = null; + 98 var optional_timeout_ = null; 99 -100 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { -101 var parent = this.getMatchersClass_(); -102 var newMatchersClass = function() { -103 parent.apply(this, arguments); -104 }; -105 jasmine.util.inherit(newMatchersClass, parent); -106 jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); -107 this.matchersClass = newMatchersClass; -108 }; -109 -110 jasmine.Spec.prototype.finishCallback = function() { -111 this.env.reporter.reportSpecResults(this); -112 }; -113 -114 jasmine.Spec.prototype.finish = function(onComplete) { -115 this.removeAllSpies(); -116 this.finishCallback(); -117 if (onComplete) { -118 onComplete(); -119 } -120 }; -121 -122 jasmine.Spec.prototype.after = function(doAfter) { -123 if (this.queue.isRunning()) { -124 this.queue.add(new jasmine.Block(this.env, doAfter, this)); -125 } else { -126 this.afterCallbacks.unshift(doAfter); -127 } -128 }; -129 -130 jasmine.Spec.prototype.execute = function(onComplete) { -131 var spec = this; -132 if (!spec.env.specFilter(spec)) { -133 spec.results_.skipped = true; -134 spec.finish(onComplete); -135 return; -136 } -137 -138 this.env.reporter.reportSpecStarting(this); -139 -140 spec.env.currentSpec = spec; +100 for (var i = 0; i < arguments.length; i++) { +101 var arg = arguments[i]; +102 switch (typeof arg) { +103 case 'function': +104 latchFunction_ = arg; +105 break; +106 case 'string': +107 optional_timeoutMessage_ = arg; +108 break; +109 case 'number': +110 optional_timeout_ = arg; +111 break; +112 } +113 } +114 +115 var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this); +116 this.addToQueue(waitsForFunc); +117 return this; +118 }; +119 +120 jasmine.Spec.prototype.fail = function (e) { +121 var expectationResult = new jasmine.ExpectationResult({ +122 passed: false, +123 message: e ? jasmine.util.formatException(e) : 'Exception' +124 }); +125 this.results_.addResult(expectationResult); +126 }; +127 +128 jasmine.Spec.prototype.getMatchersClass_ = function() { +129 return this.matchersClass || this.env.matchersClass; +130 }; +131 +132 jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +133 var parent = this.getMatchersClass_(); +134 var newMatchersClass = function() { +135 parent.apply(this, arguments); +136 }; +137 jasmine.util.inherit(newMatchersClass, parent); +138 jasmine.Matchers.wrapInto_(matchersPrototype, newMatchersClass); +139 this.matchersClass = newMatchersClass; +140 }; 141 -142 spec.addBeforesAndAftersToQueue(); -143 -144 spec.queue.start(function () { -145 spec.finish(onComplete); -146 }); -147 }; -148 -149 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { -150 var runner = this.env.currentRunner(); -151 var i; -152 -153 for (var suite = this.suite; suite; suite = suite.parentSuite) { -154 for (i = 0; i < suite.before_.length; i++) { -155 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); -156 } -157 } -158 for (i = 0; i < runner.before_.length; i++) { -159 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); -160 } -161 for (i = 0; i < this.afterCallbacks.length; i++) { -162 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); -163 } -164 for (suite = this.suite; suite; suite = suite.parentSuite) { -165 for (i = 0; i < suite.after_.length; i++) { -166 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); -167 } +142 jasmine.Spec.prototype.finishCallback = function() { +143 this.env.reporter.reportSpecResults(this); +144 }; +145 +146 jasmine.Spec.prototype.finish = function(onComplete) { +147 this.removeAllSpies(); +148 this.finishCallback(); +149 if (onComplete) { +150 onComplete(); +151 } +152 }; +153 +154 jasmine.Spec.prototype.after = function(doAfter) { +155 if (this.queue.isRunning()) { +156 this.queue.add(new jasmine.Block(this.env, doAfter, this)); +157 } else { +158 this.afterCallbacks.unshift(doAfter); +159 } +160 }; +161 +162 jasmine.Spec.prototype.execute = function(onComplete) { +163 var spec = this; +164 if (!spec.env.specFilter(spec)) { +165 spec.results_.skipped = true; +166 spec.finish(onComplete); +167 return; 168 } -169 for (i = 0; i < runner.after_.length; i++) { -170 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); -171 } -172 }; +169 +170 this.env.reporter.reportSpecStarting(this); +171 +172 spec.env.currentSpec = spec; 173 -174 jasmine.Spec.prototype.explodes = function() { -175 throw 'explodes function should not have been called'; -176 }; -177 -178 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { -179 if (obj == jasmine.undefined) { -180 throw "spyOn could not find an object to spy upon for " + methodName + "()"; -181 } -182 -183 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { -184 throw methodName + '() method does not exist'; -185 } -186 -187 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { -188 throw new Error(methodName + ' has already been spied upon'); +174 spec.addBeforesAndAftersToQueue(); +175 +176 spec.queue.start(function () { +177 spec.finish(onComplete); +178 }); +179 }; +180 +181 jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +182 var runner = this.env.currentRunner(); +183 var i; +184 +185 for (var suite = this.suite; suite; suite = suite.parentSuite) { +186 for (i = 0; i < suite.before_.length; i++) { +187 this.queue.addBefore(new jasmine.Block(this.env, suite.before_[i], this)); +188 } 189 } -190 -191 var spyObj = jasmine.createSpy(methodName); -192 -193 this.spies_.push(spyObj); -194 spyObj.baseObj = obj; -195 spyObj.methodName = methodName; -196 spyObj.originalValue = obj[methodName]; -197 -198 obj[methodName] = spyObj; -199 -200 return spyObj; -201 }; -202 -203 jasmine.Spec.prototype.removeAllSpies = function() { -204 for (var i = 0; i < this.spies_.length; i++) { -205 var spy = this.spies_[i]; -206 spy.baseObj[spy.methodName] = spy.originalValue; -207 } -208 this.spies_ = []; -209 }; -210 -211 \ No newline at end of file +190 for (i = 0; i < runner.before_.length; i++) { +191 this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); +192 } +193 for (i = 0; i < this.afterCallbacks.length; i++) { +194 this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this)); +195 } +196 for (suite = this.suite; suite; suite = suite.parentSuite) { +197 for (i = 0; i < suite.after_.length; i++) { +198 this.queue.add(new jasmine.Block(this.env, suite.after_[i], this)); +199 } +200 } +201 for (i = 0; i < runner.after_.length; i++) { +202 this.queue.add(new jasmine.Block(this.env, runner.after_[i], this)); +203 } +204 }; +205 +206 jasmine.Spec.prototype.explodes = function() { +207 throw 'explodes function should not have been called'; +208 }; +209 +210 jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +211 if (obj == jasmine.undefined) { +212 throw "spyOn could not find an object to spy upon for " + methodName + "()"; +213 } +214 +215 if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { +216 throw methodName + '() method does not exist'; +217 } +218 +219 if (!ignoreMethodDoesntExist && obj[methodName] && obj[methodName].isSpy) { +220 throw new Error(methodName + ' has already been spied upon'); +221 } +222 +223 var spyObj = jasmine.createSpy(methodName); +224 +225 this.spies_.push(spyObj); +226 spyObj.baseObj = obj; +227 spyObj.methodName = methodName; +228 spyObj.originalValue = obj[methodName]; +229 +230 obj[methodName] = spyObj; +231 +232 return spyObj; +233 }; +234 +235 jasmine.Spec.prototype.removeAllSpies = function() { +236 for (var i = 0; i < this.spies_.length; i++) { +237 var spy = this.spies_[i]; +238 spy.baseObj[spy.methodName] = spy.originalValue; +239 } +240 this.spies_ = []; +241 }; +242 +243 \ No newline at end of file diff --git a/jsdoc/symbols/src/src_WaitsForBlock.js.html b/jsdoc/symbols/src/src_WaitsForBlock.js.html index 18c2bda..5466ab4 100644 --- a/jsdoc/symbols/src/src_WaitsForBlock.js.html +++ b/jsdoc/symbols/src/src_WaitsForBlock.js.html @@ -5,40 +5,55 @@ .STRN {color: #393;} .REGX {color: #339;} .line {border-right: 1px dotted #666; color: #666; font-style: normal;} -
      1 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
    -  2   this.timeout = timeout;
    -  3   this.latchFunction = latchFunction;
    -  4   this.message = message;
    -  5   this.totalTimeSpentWaitingForLatch = 0;
    -  6   jasmine.Block.call(this, env, null, spec);
    -  7 };
    -  8 
    -  9 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
    - 10 
    - 11 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 100;
    - 12 
    - 13 jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
    - 14   var self = this;
    - 15   self.env.reporter.log('>> Jasmine waiting for ' + (self.message || 'something to happen'));
    - 16   var latchFunctionResult;
    - 17   try {
    - 18     latchFunctionResult = self.latchFunction.apply(self.spec);
    - 19   } catch (e) {
    - 20     self.spec.fail(e);
    - 21     onComplete();
    - 22     return;
    - 23   }
    - 24 
    - 25   if (latchFunctionResult) {
    - 26     onComplete();
    - 27   } else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
    - 28     var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
    - 29     self.spec.fail({
    - 30       name: 'timeout',
    - 31       message: message
    - 32     });
    - 33   } else {
    - 34     self.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
    - 35     self.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
    - 36   }
    - 37 };
    \ No newline at end of file +
      1 /**
    +  2  * A block which waits for some condition to become true, with timeout.
    +  3  *
    +  4  * @constructor
    +  5  * @extends jasmine.Block
    +  6  * @param {jasmine.Env} env The Jasmine environment.
    +  7  * @param {Number} timeout The maximum time in milliseconds to wait for the condition to become true.
    +  8  * @param {Function} latchFunction A function which returns true when the desired condition has been met.
    +  9  * @param {String} message The message to display if the desired condition hasn't been met within the given time period.
    + 10  * @param {jasmine.Spec} spec The Jasmine spec.
    + 11  */
    + 12 jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) {
    + 13   this.timeout = timeout || env.defaultTimeoutInterval;
    + 14   this.latchFunction = latchFunction;
    + 15   this.message = message;
    + 16   this.totalTimeSpentWaitingForLatch = 0;
    + 17   jasmine.Block.call(this, env, null, spec);
    + 18 };
    + 19 jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block);
    + 20 
    + 21 jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10;
    + 22 
    + 23 jasmine.WaitsForBlock.prototype.execute = function(onComplete) {
    + 24   this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen'));
    + 25   var latchFunctionResult;
    + 26   try {
    + 27     latchFunctionResult = this.latchFunction.apply(this.spec);
    + 28   } catch (e) {
    + 29     this.spec.fail(e);
    + 30     onComplete();
    + 31     return;
    + 32   }
    + 33 
    + 34   if (latchFunctionResult) {
    + 35     onComplete();
    + 36   } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) {
    + 37     var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen');
    + 38     this.spec.fail({
    + 39       name: 'timeout',
    + 40       message: message
    + 41     });
    + 42 
    + 43     this.abort = true;
    + 44     onComplete();
    + 45   } else {
    + 46     this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT;
    + 47     var self = this;
    + 48     this.env.setTimeout(function() {
    + 49       self.execute(onComplete);
    + 50     }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT);
    + 51   }
    + 52 };
    \ No newline at end of file diff --git a/jsdoc/symbols/src/src_base.js.html b/jsdoc/symbols/src/src_base.js.html index 83bd46b..33add32 100644 --- a/jsdoc/symbols/src/src_base.js.html +++ b/jsdoc/symbols/src/src_base.js.html @@ -28,563 +28,570 @@ 21 jasmine.undefined = jasmine.___undefined___; 22 23 /** - 24 * Default interval for event loop yields. Small values here may result in slow test running. Zero means no updates until all tests have completed. + 24 * 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. 25 * 26 */ 27 jasmine.DEFAULT_UPDATE_INTERVAL = 250; 28 - 29 jasmine.getGlobal = function() { - 30 function getGlobal() { - 31 return this; - 32 } + 29 /** + 30 * Default timeout interval in milliseconds for waitsFor() blocks. + 31 */ + 32 jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; 33 - 34 return getGlobal(); - 35 }; - 36 - 37 /** - 38 * Allows for bound functions to be compared. Internal use only. - 39 * - 40 * @ignore - 41 * @private - 42 * @param base {Object} bound 'this' for the function - 43 * @param name {Function} function to find - 44 */ - 45 jasmine.bindOriginal_ = function(base, name) { - 46 var original = base[name]; - 47 if (original.apply) { - 48 return function() { - 49 return original.apply(base, arguments); - 50 }; - 51 } else { - 52 // IE support - 53 return jasmine.getGlobal()[name]; - 54 } - 55 }; - 56 - 57 jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout'); - 58 jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout'); - 59 jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval'); - 60 jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval'); + 34 jasmine.getGlobal = function() { + 35 function getGlobal() { + 36 return this; + 37 } + 38 + 39 return getGlobal(); + 40 }; + 41 + 42 /** + 43 * Allows for bound functions to be compared. Internal use only. + 44 * + 45 * @ignore + 46 * @private + 47 * @param base {Object} bound 'this' for the function + 48 * @param name {Function} function to find + 49 */ + 50 jasmine.bindOriginal_ = function(base, name) { + 51 var original = base[name]; + 52 if (original.apply) { + 53 return function() { + 54 return original.apply(base, arguments); + 55 }; + 56 } else { + 57 // IE support + 58 return jasmine.getGlobal()[name]; + 59 } + 60 }; 61 - 62 jasmine.MessageResult = function(values) { - 63 this.type = 'log'; - 64 this.values = values; - 65 this.trace = new Error(); // todo: test better - 66 }; - 67 - 68 jasmine.MessageResult.prototype.toString = function() { - 69 var text = ""; - 70 for(var i = 0; i < this.values.length; i++) { - 71 if (i > 0) text += " "; - 72 if (jasmine.isString_(this.values[i])) { - 73 text += this.values[i]; - 74 } else { - 75 text += jasmine.pp(this.values[i]); - 76 } - 77 } - 78 return text; - 79 }; - 80 - 81 jasmine.ExpectationResult = function(params) { - 82 this.type = 'expect'; - 83 this.matcherName = params.matcherName; - 84 this.passed_ = params.passed; - 85 this.expected = params.expected; - 86 this.actual = params.actual; - 87 - 88 this.message = this.passed_ ? 'Passed.' : params.message; - 89 this.trace = this.passed_ ? '' : new Error(this.message); - 90 }; - 91 - 92 jasmine.ExpectationResult.prototype.toString = function () { - 93 return this.message; - 94 }; - 95 - 96 jasmine.ExpectationResult.prototype.passed = function () { - 97 return this.passed_; - 98 }; - 99 -100 /** -101 * Getter for the Jasmine environment. Ensures one gets created -102 */ -103 jasmine.getEnv = function() { -104 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); -105 }; -106 -107 /** -108 * @ignore -109 * @private -110 * @param value -111 * @returns {Boolean} -112 */ -113 jasmine.isArray_ = function(value) { -114 return jasmine.isA_("Array", value); -115 }; -116 -117 /** -118 * @ignore -119 * @private -120 * @param value -121 * @returns {Boolean} -122 */ -123 jasmine.isString_ = function(value) { -124 return jasmine.isA_("String", value); -125 }; -126 -127 /** -128 * @ignore -129 * @private -130 * @param value -131 * @returns {Boolean} -132 */ -133 jasmine.isNumber_ = function(value) { -134 return jasmine.isA_("Number", value); -135 }; -136 -137 /** -138 * @ignore -139 * @private -140 * @param {String} typeName -141 * @param value -142 * @returns {Boolean} -143 */ -144 jasmine.isA_ = function(typeName, value) { -145 return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; -146 }; -147 -148 /** -149 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. -150 * -151 * @param value {Object} an object to be outputted -152 * @returns {String} -153 */ -154 jasmine.pp = function(value) { -155 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); -156 stringPrettyPrinter.format(value); -157 return stringPrettyPrinter.string; -158 }; -159 -160 /** -161 * Returns true if the object is a DOM Node. -162 * -163 * @param {Object} obj object to check -164 * @returns {Boolean} -165 */ -166 jasmine.isDomNode = function(obj) { -167 return obj['nodeType'] > 0; -168 }; -169 -170 /** -171 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. -172 * -173 * @example -174 * // don't care about which function is passed in, as long as it's a function -175 * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); -176 * -177 * @param {Class} clazz -178 * @returns matchable object of the type clazz -179 */ -180 jasmine.any = function(clazz) { -181 return new jasmine.Matchers.Any(clazz); -182 }; -183 -184 /** -185 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. -186 * -187 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine -188 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. -189 * -190 * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). + 62 jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout'); + 63 jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout'); + 64 jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval'); + 65 jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval'); + 66 + 67 jasmine.MessageResult = function(values) { + 68 this.type = 'log'; + 69 this.values = values; + 70 this.trace = new Error(); // todo: test better + 71 }; + 72 + 73 jasmine.MessageResult.prototype.toString = function() { + 74 var text = ""; + 75 for(var i = 0; i < this.values.length; i++) { + 76 if (i > 0) text += " "; + 77 if (jasmine.isString_(this.values[i])) { + 78 text += this.values[i]; + 79 } else { + 80 text += jasmine.pp(this.values[i]); + 81 } + 82 } + 83 return text; + 84 }; + 85 + 86 jasmine.ExpectationResult = function(params) { + 87 this.type = 'expect'; + 88 this.matcherName = params.matcherName; + 89 this.passed_ = params.passed; + 90 this.expected = params.expected; + 91 this.actual = params.actual; + 92 + 93 this.message = this.passed_ ? 'Passed.' : params.message; + 94 this.trace = this.passed_ ? '' : new Error(this.message); + 95 }; + 96 + 97 jasmine.ExpectationResult.prototype.toString = function () { + 98 return this.message; + 99 }; +100 +101 jasmine.ExpectationResult.prototype.passed = function () { +102 return this.passed_; +103 }; +104 +105 /** +106 * Getter for the Jasmine environment. Ensures one gets created +107 */ +108 jasmine.getEnv = function() { +109 return jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); +110 }; +111 +112 /** +113 * @ignore +114 * @private +115 * @param value +116 * @returns {Boolean} +117 */ +118 jasmine.isArray_ = function(value) { +119 return jasmine.isA_("Array", value); +120 }; +121 +122 /** +123 * @ignore +124 * @private +125 * @param value +126 * @returns {Boolean} +127 */ +128 jasmine.isString_ = function(value) { +129 return jasmine.isA_("String", value); +130 }; +131 +132 /** +133 * @ignore +134 * @private +135 * @param value +136 * @returns {Boolean} +137 */ +138 jasmine.isNumber_ = function(value) { +139 return jasmine.isA_("Number", value); +140 }; +141 +142 /** +143 * @ignore +144 * @private +145 * @param {String} typeName +146 * @param value +147 * @returns {Boolean} +148 */ +149 jasmine.isA_ = function(typeName, value) { +150 return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; +151 }; +152 +153 /** +154 * Pretty printer for expecations. Takes any object and turns it into a human-readable string. +155 * +156 * @param value {Object} an object to be outputted +157 * @returns {String} +158 */ +159 jasmine.pp = function(value) { +160 var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); +161 stringPrettyPrinter.format(value); +162 return stringPrettyPrinter.string; +163 }; +164 +165 /** +166 * Returns true if the object is a DOM Node. +167 * +168 * @param {Object} obj object to check +169 * @returns {Boolean} +170 */ +171 jasmine.isDomNode = function(obj) { +172 return obj['nodeType'] > 0; +173 }; +174 +175 /** +176 * Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter. +177 * +178 * @example +179 * // don't care about which function is passed in, as long as it's a function +180 * expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function)); +181 * +182 * @param {Class} clazz +183 * @returns matchable object of the type clazz +184 */ +185 jasmine.any = function(clazz) { +186 return new jasmine.Matchers.Any(clazz); +187 }; +188 +189 /** +190 * Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks. 191 * -192 * Spies are torn down at the end of every spec. -193 * -194 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. -195 * -196 * @example -197 * // a stub -198 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere -199 * -200 * // spy example -201 * var foo = { -202 * not: function(bool) { return !bool; } -203 * } +192 * Spies should be created in test setup, before expectations. They can then be checked, using the standard Jasmine +193 * expectation syntax. Spies can be checked if they were called or not and what the calling params were. +194 * +195 * A Spy has the following fields: wasCalled, callCount, mostRecentCall, and argsForCall (see docs). +196 * +197 * Spies are torn down at the end of every spec. +198 * +199 * Note: Do <b>not</b> call new jasmine.Spy() directly - a spy must be created using spyOn, jasmine.createSpy or jasmine.createSpyObj. +200 * +201 * @example +202 * // a stub +203 * var myStub = jasmine.createSpy('myStub'); // can be used anywhere 204 * -205 * // actual foo.not will not be called, execution stops -206 * spyOn(foo, 'not'); -207 -208 // foo.not spied upon, execution will continue to implementation -209 * spyOn(foo, 'not').andCallThrough(); -210 * -211 * // fake example -212 * var foo = { -213 * not: function(bool) { return !bool; } -214 * } +205 * // spy example +206 * var foo = { +207 * not: function(bool) { return !bool; } +208 * } +209 * +210 * // actual foo.not will not be called, execution stops +211 * spyOn(foo, 'not'); +212 +213 // foo.not spied upon, execution will continue to implementation +214 * spyOn(foo, 'not').andCallThrough(); 215 * -216 * // foo.not(val) will return val -217 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); -218 * -219 * // mock example -220 * foo.not(7 == 7); -221 * expect(foo.not).toHaveBeenCalled(); -222 * expect(foo.not).toHaveBeenCalledWith(true); +216 * // fake example +217 * var foo = { +218 * not: function(bool) { return !bool; } +219 * } +220 * +221 * // foo.not(val) will return val +222 * spyOn(foo, 'not').andCallFake(function(value) {return value;}); 223 * -224 * @constructor -225 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj -226 * @param {String} name -227 */ -228 jasmine.Spy = function(name) { -229 /** -230 * The name of the spy, if provided. -231 */ -232 this.identity = name || 'unknown'; -233 /** -234 * Is this Object a spy? -235 */ -236 this.isSpy = true; -237 /** -238 * The actual function this spy stubs. -239 */ -240 this.plan = function() { -241 }; +224 * // mock example +225 * foo.not(7 == 7); +226 * expect(foo.not).toHaveBeenCalled(); +227 * expect(foo.not).toHaveBeenCalledWith(true); +228 * +229 * @constructor +230 * @see spyOn, jasmine.createSpy, jasmine.createSpyObj +231 * @param {String} name +232 */ +233 jasmine.Spy = function(name) { +234 /** +235 * The name of the spy, if provided. +236 */ +237 this.identity = name || 'unknown'; +238 /** +239 * Is this Object a spy? +240 */ +241 this.isSpy = true; 242 /** -243 * Tracking of the most recent call to the spy. -244 * @example -245 * var mySpy = jasmine.createSpy('foo'); -246 * mySpy(1, 2); -247 * mySpy.mostRecentCall.args = [1, 2]; -248 */ -249 this.mostRecentCall = {}; -250 -251 /** -252 * Holds arguments for each call to the spy, indexed by call count -253 * @example -254 * var mySpy = jasmine.createSpy('foo'); -255 * mySpy(1, 2); -256 * mySpy(7, 8); -257 * mySpy.mostRecentCall.args = [7, 8]; -258 * mySpy.argsForCall[0] = [1, 2]; -259 * mySpy.argsForCall[1] = [7, 8]; -260 */ -261 this.argsForCall = []; -262 this.calls = []; -263 }; -264 -265 /** -266 * Tells a spy to call through to the actual implemenatation. -267 * -268 * @example -269 * var foo = { -270 * bar: function() { // do some stuff } -271 * } +243 * The actual function this spy stubs. +244 */ +245 this.plan = function() { +246 }; +247 /** +248 * Tracking of the most recent call to the spy. +249 * @example +250 * var mySpy = jasmine.createSpy('foo'); +251 * mySpy(1, 2); +252 * mySpy.mostRecentCall.args = [1, 2]; +253 */ +254 this.mostRecentCall = {}; +255 +256 /** +257 * Holds arguments for each call to the spy, indexed by call count +258 * @example +259 * var mySpy = jasmine.createSpy('foo'); +260 * mySpy(1, 2); +261 * mySpy(7, 8); +262 * mySpy.mostRecentCall.args = [7, 8]; +263 * mySpy.argsForCall[0] = [1, 2]; +264 * mySpy.argsForCall[1] = [7, 8]; +265 */ +266 this.argsForCall = []; +267 this.calls = []; +268 }; +269 +270 /** +271 * Tells a spy to call through to the actual implemenatation. 272 * -273 * // defining a spy on an existing property: foo.bar -274 * spyOn(foo, 'bar').andCallThrough(); -275 */ -276 jasmine.Spy.prototype.andCallThrough = function() { -277 this.plan = this.originalValue; -278 return this; -279 }; -280 -281 /** -282 * For setting the return value of a spy. -283 * -284 * @example -285 * // defining a spy from scratch: foo() returns 'baz' -286 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); -287 * -288 * // defining a spy on an existing property: foo.bar() returns 'baz' -289 * spyOn(foo, 'bar').andReturn('baz'); -290 * -291 * @param {Object} value -292 */ -293 jasmine.Spy.prototype.andReturn = function(value) { -294 this.plan = function() { -295 return value; -296 }; -297 return this; -298 }; -299 -300 /** -301 * For throwing an exception when a spy is called. -302 * -303 * @example -304 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' -305 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); -306 * -307 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' -308 * spyOn(foo, 'bar').andThrow('baz'); -309 * -310 * @param {String} exceptionMsg -311 */ -312 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { -313 this.plan = function() { -314 throw exceptionMsg; -315 }; -316 return this; -317 }; -318 -319 /** -320 * Calls an alternate implementation when a spy is called. -321 * -322 * @example -323 * var baz = function() { -324 * // do some stuff, return something -325 * } -326 * // defining a spy from scratch: foo() calls the function baz -327 * var foo = jasmine.createSpy('spy on foo').andCall(baz); -328 * -329 * // defining a spy on an existing property: foo.bar() calls an anonymnous function -330 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); -331 * -332 * @param {Function} fakeFunc -333 */ -334 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { -335 this.plan = fakeFunc; -336 return this; -337 }; -338 -339 /** -340 * Resets all of a spy's the tracking variables so that it can be used again. -341 * -342 * @example -343 * spyOn(foo, 'bar'); -344 * -345 * foo.bar(); +273 * @example +274 * var foo = { +275 * bar: function() { // do some stuff } +276 * } +277 * +278 * // defining a spy on an existing property: foo.bar +279 * spyOn(foo, 'bar').andCallThrough(); +280 */ +281 jasmine.Spy.prototype.andCallThrough = function() { +282 this.plan = this.originalValue; +283 return this; +284 }; +285 +286 /** +287 * For setting the return value of a spy. +288 * +289 * @example +290 * // defining a spy from scratch: foo() returns 'baz' +291 * var foo = jasmine.createSpy('spy on foo').andReturn('baz'); +292 * +293 * // defining a spy on an existing property: foo.bar() returns 'baz' +294 * spyOn(foo, 'bar').andReturn('baz'); +295 * +296 * @param {Object} value +297 */ +298 jasmine.Spy.prototype.andReturn = function(value) { +299 this.plan = function() { +300 return value; +301 }; +302 return this; +303 }; +304 +305 /** +306 * For throwing an exception when a spy is called. +307 * +308 * @example +309 * // defining a spy from scratch: foo() throws an exception w/ message 'ouch' +310 * var foo = jasmine.createSpy('spy on foo').andThrow('baz'); +311 * +312 * // defining a spy on an existing property: foo.bar() throws an exception w/ message 'ouch' +313 * spyOn(foo, 'bar').andThrow('baz'); +314 * +315 * @param {String} exceptionMsg +316 */ +317 jasmine.Spy.prototype.andThrow = function(exceptionMsg) { +318 this.plan = function() { +319 throw exceptionMsg; +320 }; +321 return this; +322 }; +323 +324 /** +325 * Calls an alternate implementation when a spy is called. +326 * +327 * @example +328 * var baz = function() { +329 * // do some stuff, return something +330 * } +331 * // defining a spy from scratch: foo() calls the function baz +332 * var foo = jasmine.createSpy('spy on foo').andCall(baz); +333 * +334 * // defining a spy on an existing property: foo.bar() calls an anonymnous function +335 * spyOn(foo, 'bar').andCall(function() { return 'baz';} ); +336 * +337 * @param {Function} fakeFunc +338 */ +339 jasmine.Spy.prototype.andCallFake = function(fakeFunc) { +340 this.plan = fakeFunc; +341 return this; +342 }; +343 +344 /** +345 * Resets all of a spy's the tracking variables so that it can be used again. 346 * -347 * expect(foo.bar.callCount).toEqual(1); -348 * -349 * foo.bar.reset(); -350 * -351 * expect(foo.bar.callCount).toEqual(0); -352 */ -353 jasmine.Spy.prototype.reset = function() { -354 this.wasCalled = false; -355 this.callCount = 0; -356 this.argsForCall = []; -357 this.calls = []; -358 this.mostRecentCall = {}; -359 }; -360 -361 jasmine.createSpy = function(name) { -362 -363 var spyObj = function() { -364 spyObj.wasCalled = true; -365 spyObj.callCount++; -366 var args = jasmine.util.argsToArray(arguments); -367 spyObj.mostRecentCall.object = this; -368 spyObj.mostRecentCall.args = args; -369 spyObj.argsForCall.push(args); -370 spyObj.calls.push({object: this, args: args}); -371 return spyObj.plan.apply(this, arguments); -372 }; -373 -374 var spy = new jasmine.Spy(name); -375 -376 for (var prop in spy) { -377 spyObj[prop] = spy[prop]; -378 } -379 -380 spyObj.reset(); -381 -382 return spyObj; -383 }; +347 * @example +348 * spyOn(foo, 'bar'); +349 * +350 * foo.bar(); +351 * +352 * expect(foo.bar.callCount).toEqual(1); +353 * +354 * foo.bar.reset(); +355 * +356 * expect(foo.bar.callCount).toEqual(0); +357 */ +358 jasmine.Spy.prototype.reset = function() { +359 this.wasCalled = false; +360 this.callCount = 0; +361 this.argsForCall = []; +362 this.calls = []; +363 this.mostRecentCall = {}; +364 }; +365 +366 jasmine.createSpy = function(name) { +367 +368 var spyObj = function() { +369 spyObj.wasCalled = true; +370 spyObj.callCount++; +371 var args = jasmine.util.argsToArray(arguments); +372 spyObj.mostRecentCall.object = this; +373 spyObj.mostRecentCall.args = args; +374 spyObj.argsForCall.push(args); +375 spyObj.calls.push({object: this, args: args}); +376 return spyObj.plan.apply(this, arguments); +377 }; +378 +379 var spy = new jasmine.Spy(name); +380 +381 for (var prop in spy) { +382 spyObj[prop] = spy[prop]; +383 } 384 -385 /** -386 * Determines whether an object is a spy. -387 * -388 * @param {jasmine.Spy|Object} putativeSpy -389 * @returns {Boolean} -390 */ -391 jasmine.isSpy = function(putativeSpy) { -392 return putativeSpy && putativeSpy.isSpy; -393 }; -394 -395 /** -396 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something -397 * large in one call. -398 * -399 * @param {String} baseName name of spy class -400 * @param {Array} methodNames array of names of methods to make spies -401 */ -402 jasmine.createSpyObj = function(baseName, methodNames) { -403 if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { -404 throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); -405 } -406 var obj = {}; -407 for (var i = 0; i < methodNames.length; i++) { -408 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); -409 } -410 return obj; -411 }; -412 -413 /** -414 * All parameters are pretty-printed and concatenated together, then written to the current spec's output. -415 * -416 * Be careful not to leave calls to <code>jasmine.log</code> in production code. -417 */ -418 jasmine.log = function() { -419 var spec = jasmine.getEnv().currentSpec; -420 spec.log.apply(spec, arguments); -421 }; -422 -423 /** -424 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. -425 * -426 * @example -427 * // spy example -428 * var foo = { -429 * not: function(bool) { return !bool; } -430 * } -431 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops -432 * -433 * @see jasmine.createSpy -434 * @param obj -435 * @param methodName -436 * @returns a Jasmine spy that can be chained with all spy methods -437 */ -438 var spyOn = function(obj, methodName) { -439 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); -440 }; -441 -442 /** -443 * Creates a Jasmine spec that will be added to the current suite. -444 * -445 * // TODO: pending tests -446 * -447 * @example -448 * it('should be true', function() { -449 * expect(true).toEqual(true); -450 * }); +385 spyObj.reset(); +386 +387 return spyObj; +388 }; +389 +390 /** +391 * Determines whether an object is a spy. +392 * +393 * @param {jasmine.Spy|Object} putativeSpy +394 * @returns {Boolean} +395 */ +396 jasmine.isSpy = function(putativeSpy) { +397 return putativeSpy && putativeSpy.isSpy; +398 }; +399 +400 /** +401 * Creates a more complicated spy: an Object that has every property a function that is a spy. Used for stubbing something +402 * large in one call. +403 * +404 * @param {String} baseName name of spy class +405 * @param {Array} methodNames array of names of methods to make spies +406 */ +407 jasmine.createSpyObj = function(baseName, methodNames) { +408 if (!jasmine.isArray_(methodNames) || methodNames.length == 0) { +409 throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); +410 } +411 var obj = {}; +412 for (var i = 0; i < methodNames.length; i++) { +413 obj[methodNames[i]] = jasmine.createSpy(baseName + '.' + methodNames[i]); +414 } +415 return obj; +416 }; +417 +418 /** +419 * All parameters are pretty-printed and concatenated together, then written to the current spec's output. +420 * +421 * Be careful not to leave calls to <code>jasmine.log</code> in production code. +422 */ +423 jasmine.log = function() { +424 var spec = jasmine.getEnv().currentSpec; +425 spec.log.apply(spec, arguments); +426 }; +427 +428 /** +429 * Function that installs a spy on an existing object's method name. Used within a Spec to create a spy. +430 * +431 * @example +432 * // spy example +433 * var foo = { +434 * not: function(bool) { return !bool; } +435 * } +436 * spyOn(foo, 'not'); // actual foo.not will not be called, execution stops +437 * +438 * @see jasmine.createSpy +439 * @param obj +440 * @param methodName +441 * @returns a Jasmine spy that can be chained with all spy methods +442 */ +443 var spyOn = function(obj, methodName) { +444 return jasmine.getEnv().currentSpec.spyOn(obj, methodName); +445 }; +446 +447 /** +448 * Creates a Jasmine spec that will be added to the current suite. +449 * +450 * // TODO: pending tests 451 * -452 * @param {String} desc description of this specification -453 * @param {Function} func defines the preconditions and expectations of the spec -454 */ -455 var it = function(desc, func) { -456 return jasmine.getEnv().it(desc, func); -457 }; -458 -459 /** -460 * Creates a <em>disabled</em> Jasmine spec. -461 * -462 * A convenience method that allows existing specs to be disabled temporarily during development. -463 * -464 * @param {String} desc description of this specification -465 * @param {Function} func defines the preconditions and expectations of the spec -466 */ -467 var xit = function(desc, func) { -468 return jasmine.getEnv().xit(desc, func); -469 }; -470 -471 /** -472 * Starts a chain for a Jasmine expectation. -473 * -474 * It is passed an Object that is the actual value and should chain to one of the many -475 * jasmine.Matchers functions. -476 * -477 * @param {Object} actual Actual value to test against and expected value -478 */ -479 var expect = function(actual) { -480 return jasmine.getEnv().currentSpec.expect(actual); -481 }; -482 -483 /** -484 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. -485 * -486 * @param {Function} func Function that defines part of a jasmine spec. -487 */ -488 var runs = function(func) { -489 jasmine.getEnv().currentSpec.runs(func); -490 }; -491 -492 /** -493 * Waits for a timeout before moving to the next runs()-defined block. -494 * @param {Number} timeout -495 */ -496 var waits = function(timeout) { -497 jasmine.getEnv().currentSpec.waits(timeout); -498 }; -499 -500 /** -501 * Waits for the latchFunction to return true before proceeding to the next runs()-defined block. -502 * -503 * @param {Number} timeout -504 * @param {Function} latchFunction -505 * @param {String} message -506 */ -507 var waitsFor = function(timeout, latchFunction, message) { -508 jasmine.getEnv().currentSpec.waitsFor(timeout, latchFunction, message); -509 }; -510 -511 /** -512 * A function that is called before each spec in a suite. -513 * -514 * Used for spec setup, including validating assumptions. -515 * -516 * @param {Function} beforeEachFunction -517 */ -518 var beforeEach = function(beforeEachFunction) { -519 jasmine.getEnv().beforeEach(beforeEachFunction); -520 }; -521 -522 /** -523 * A function that is called after each spec in a suite. -524 * -525 * Used for restoring any state that is hijacked during spec execution. -526 * -527 * @param {Function} afterEachFunction -528 */ -529 var afterEach = function(afterEachFunction) { -530 jasmine.getEnv().afterEach(afterEachFunction); -531 }; -532 -533 /** -534 * Defines a suite of specifications. -535 * -536 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared -537 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization -538 * of setup in some tests. -539 * -540 * @example -541 * // TODO: a simple suite +452 * @example +453 * it('should be true', function() { +454 * expect(true).toEqual(true); +455 * }); +456 * +457 * @param {String} desc description of this specification +458 * @param {Function} func defines the preconditions and expectations of the spec +459 */ +460 var it = function(desc, func) { +461 return jasmine.getEnv().it(desc, func); +462 }; +463 +464 /** +465 * Creates a <em>disabled</em> Jasmine spec. +466 * +467 * A convenience method that allows existing specs to be disabled temporarily during development. +468 * +469 * @param {String} desc description of this specification +470 * @param {Function} func defines the preconditions and expectations of the spec +471 */ +472 var xit = function(desc, func) { +473 return jasmine.getEnv().xit(desc, func); +474 }; +475 +476 /** +477 * Starts a chain for a Jasmine expectation. +478 * +479 * It is passed an Object that is the actual value and should chain to one of the many +480 * jasmine.Matchers functions. +481 * +482 * @param {Object} actual Actual value to test against and expected value +483 */ +484 var expect = function(actual) { +485 return jasmine.getEnv().currentSpec.expect(actual); +486 }; +487 +488 /** +489 * Defines part of a jasmine spec. Used in cominbination with waits or waitsFor in asynchrnous specs. +490 * +491 * @param {Function} func Function that defines part of a jasmine spec. +492 */ +493 var runs = function(func) { +494 jasmine.getEnv().currentSpec.runs(func); +495 }; +496 +497 /** +498 * Waits a fixed time period before moving to the next block. +499 * +500 * @deprecated Use waitsFor() instead +501 * @param {Number} timeout milliseconds to wait +502 */ +503 var waits = function(timeout) { +504 jasmine.getEnv().currentSpec.waits(timeout); +505 }; +506 +507 /** +508 * Waits for the latchFunction to return true before proceeding to the next block. +509 * +510 * @param {Function} latchFunction +511 * @param {String} optional_timeoutMessage +512 * @param {Number} optional_timeout +513 */ +514 var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { +515 jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments); +516 }; +517 +518 /** +519 * A function that is called before each spec in a suite. +520 * +521 * Used for spec setup, including validating assumptions. +522 * +523 * @param {Function} beforeEachFunction +524 */ +525 var beforeEach = function(beforeEachFunction) { +526 jasmine.getEnv().beforeEach(beforeEachFunction); +527 }; +528 +529 /** +530 * A function that is called after each spec in a suite. +531 * +532 * Used for restoring any state that is hijacked during spec execution. +533 * +534 * @param {Function} afterEachFunction +535 */ +536 var afterEach = function(afterEachFunction) { +537 jasmine.getEnv().afterEach(afterEachFunction); +538 }; +539 +540 /** +541 * Defines a suite of specifications. 542 * -543 * // TODO: a simple suite with a nested describe block -544 * -545 * @param {String} description A string, usually the class under test. -546 * @param {Function} specDefinitions function that defines several specs. -547 */ -548 var describe = function(description, specDefinitions) { -549 return jasmine.getEnv().describe(description, specDefinitions); -550 }; -551 -552 /** -553 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. -554 * -555 * @param {String} description A string, usually the class under test. -556 * @param {Function} specDefinitions function that defines several specs. -557 */ -558 var xdescribe = function(description, specDefinitions) { -559 return jasmine.getEnv().xdescribe(description, specDefinitions); -560 }; -561 -562 -563 // Provide the XMLHttpRequest class for IE 5.x-6.x: -564 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { -565 try { -566 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); -567 } catch(e) { -568 } -569 try { -570 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); -571 } catch(e) { -572 } -573 try { -574 return new ActiveXObject("Msxml2.XMLHTTP"); -575 } catch(e) { -576 } -577 try { -578 return new ActiveXObject("Microsoft.XMLHTTP"); -579 } catch(e) { -580 } -581 throw new Error("This browser does not support XMLHttpRequest."); -582 } : XMLHttpRequest; -583 \ No newline at end of file +543 * Stores the description and all defined specs in the Jasmine environment as one suite of specs. Variables declared +544 * are accessible by calls to beforeEach, it, and afterEach. Describe blocks can be nested, allowing for specialization +545 * of setup in some tests. +546 * +547 * @example +548 * // TODO: a simple suite +549 * +550 * // TODO: a simple suite with a nested describe block +551 * +552 * @param {String} description A string, usually the class under test. +553 * @param {Function} specDefinitions function that defines several specs. +554 */ +555 var describe = function(description, specDefinitions) { +556 return jasmine.getEnv().describe(description, specDefinitions); +557 }; +558 +559 /** +560 * Disables a suite of specifications. Used to disable some suites in a file, or files, temporarily during development. +561 * +562 * @param {String} description A string, usually the class under test. +563 * @param {Function} specDefinitions function that defines several specs. +564 */ +565 var xdescribe = function(description, specDefinitions) { +566 return jasmine.getEnv().xdescribe(description, specDefinitions); +567 }; +568 +569 +570 // Provide the XMLHttpRequest class for IE 5.x-6.x: +571 jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { +572 try { +573 return new ActiveXObject("Msxml2.XMLHTTP.6.0"); +574 } catch(e) { +575 } +576 try { +577 return new ActiveXObject("Msxml2.XMLHTTP.3.0"); +578 } catch(e) { +579 } +580 try { +581 return new ActiveXObject("Msxml2.XMLHTTP"); +582 } catch(e) { +583 } +584 try { +585 return new ActiveXObject("Microsoft.XMLHTTP"); +586 } catch(e) { +587 } +588 throw new Error("This browser does not support XMLHttpRequest."); +589 } : XMLHttpRequest; +590 \ No newline at end of file