diff options
| author | Elliott Sprehn | 2010-10-24 14:14:45 -0700 | 
|---|---|---|
| committer | Igor Minar | 2010-10-26 15:17:57 -0700 | 
| commit | 40d7e66f408eaaa66efd8d7934ab2eb3324236a1 (patch) | |
| tree | daf88d70df9037416598307784eb83df93df4fed /src/scenario/Describe.js | |
| parent | 1d52349440d40de527b5d7f3849070f525c1b79b (diff) | |
| download | angular.js-40d7e66f408eaaa66efd8d7934ab2eb3324236a1.tar.bz2 | |
Lots of bug fixes in the scenario runner and a bunch of new features.
- By default the runner now creates multiple output formats as it runs. Nodes are created in the DOM with ids: json, xml, and html.
ex. $('#json').html() => json output of the runner
ex. $('#xml').html() => json output of the runner
$result is also an object tree result.
The permitted formats are html,json,xml,object.
If you don't want certain formats you can select specific ones with the new ng:scenario-output attribute on the script tag.
<script src="angular-scenario.js" ng:scenario-output="xml,json">
- Added element(...).count() that returns the number of matching elements for the selector.
- repeater(...).count() now returns 0 if no elements matched which can be used to check if a repeater is empty.
- Added toBe() matcher that does strict equality with ===
- Implement iit and ddescribe. If iit() is used instead of it() then only that test will run. If ddescribe() is used instead of describe() them only it() statements inside of it will run. Several iit/ddescribe() blocks can be used to run isolated tests.
- Implement new event based model for SpecRunner. You can now listen for events in the runner. This is useful for writing your own UI or connecting a remote process (ex. WebDriver). Event callbacks execute on the Runner instance.
Events, if fired, will always be in the below order. All events always happen
except for Failure and Error events which only happen in error conditions.
Events:
  RunnerBegin
  SpecBegin(spec)
  StepBegin(spec, step)
  StepError(spec, step, error)
  StepFailure(spec, step, error)
  StepEnd(spec, step)
  SpecError(spec, step, error)
  SpecEnd(spec)
  RunnerEnd
- Only allow the browser to repaint every 10 steps. Cuts 700ms off Firefox in benchmark, 200ms off Chrome.
- Bug Fix: Manually navigate anchors on click since trigger wont work in Firefox.
Diffstat (limited to 'src/scenario/Describe.js')
| -rw-r--r-- | src/scenario/Describe.js | 65 | 
1 files changed, 54 insertions, 11 deletions
| diff --git a/src/scenario/Describe.js b/src/scenario/Describe.js index f6a52f1e..69ed8238 100644 --- a/src/scenario/Describe.js +++ b/src/scenario/Describe.js @@ -1,8 +1,12 @@  /**   * The representation of define blocks. Don't used directly, instead use   * define() in your tests. + * + * @param {string} descName Name of the block + * @param {Object} parent describe or undefined if the root.   */  angular.scenario.Describe = function(descName, parent) { +  this.only = parent && parent.only;    this.beforeEachFns = [];    this.afterEachFns = [];    this.its = []; @@ -10,7 +14,7 @@ angular.scenario.Describe = function(descName, parent) {    this.name = descName;    this.parent = parent;    this.id = angular.scenario.Describe.id++; -   +    /**     * Calls all before functions.     */ @@ -36,7 +40,7 @@ angular.scenario.Describe.id = 0;  /**   * Defines a block to execute before each it or nested describe.   * - * @param {Function} Body of the block. + * @param {Function} body Body of the block.   */  angular.scenario.Describe.prototype.beforeEach = function(body) {    this.beforeEachFns.push(body); @@ -45,7 +49,7 @@ angular.scenario.Describe.prototype.beforeEach = function(body) {  /**   * Defines a block to execute after each it or nested describe.   * - * @param {Function} Body of the block. + * @param {Function} body Body of the block.   */  angular.scenario.Describe.prototype.afterEach = function(body) {    this.afterEachFns.push(body); @@ -54,8 +58,8 @@ angular.scenario.Describe.prototype.afterEach = function(body) {  /**   * Creates a new describe block that's a child of this one.   * - * @param {String} Name of the block. Appended to the parent block's name. - * @param {Function} Body of the block. + * @param {string} name Name of the block. Appended to the parent block's name. + * @param {Function} body Body of the block.   */  angular.scenario.Describe.prototype.describe = function(name, body) {    var child = new angular.scenario.Describe(name, this); @@ -64,6 +68,19 @@ angular.scenario.Describe.prototype.describe = function(name, body) {  };  /** + * Same as describe() but makes ddescribe blocks the only to run. + * + * @param {string} name Name of the test. + * @param {Function} body Body of the block. + */ +angular.scenario.Describe.prototype.ddescribe = function(name, body) { +  var child = new angular.scenario.Describe(name, this); +  child.only = true; +  this.children.push(child); +  body.call(child); +}; + +/**   * Use to disable a describe block.   */  angular.scenario.Describe.prototype.xdescribe = angular.noop; @@ -71,21 +88,32 @@ angular.scenario.Describe.prototype.xdescribe = angular.noop;  /**   * Defines a test.   * - * @param {String} Name of the test. - * @param {Function} Body of the block. + * @param {string} name Name of the test. + * @param {Function} vody Body of the block.   */  angular.scenario.Describe.prototype.it = function(name, body) { -  var self = this;    this.its.push({      definition: this, +    only: this.only,      name: name, -    before: self.setupBefore, +    before: this.setupBefore,      body: body, -    after: self.setupAfter +    after: this.setupAfter    });  };  /** + * Same as it() but makes iit tests the only test to run. + * + * @param {string} name Name of the test. + * @param {Function} body Body of the block. + */ +angular.scenario.Describe.prototype.iit = function(name, body) { +  this.it.apply(this, arguments); +  this.its[this.its.length-1].only = true; +}; + +/**   * Use to disable a test block.   */  angular.scenario.Describe.prototype.xit = angular.noop; @@ -93,6 +121,15 @@ angular.scenario.Describe.prototype.xit = angular.noop;  /**   * Gets an array of functions representing all the tests (recursively).   * that can be executed with SpecRunner's. + * + * @return {Array<Object>} Array of it blocks { + *   definition : Object // parent Describe + *   only: boolean + *   name: string + *   before: Function + *   body: Function + *   after: Function + *  }   */  angular.scenario.Describe.prototype.getSpecs = function() {    var specs = arguments[0] || []; @@ -102,5 +139,11 @@ angular.scenario.Describe.prototype.getSpecs = function() {    angular.foreach(this.its, function(it) {      specs.push(it);    }); -  return specs; +  var only = []; +  angular.foreach(specs, function(it) { +    if (it.only) { +      only.push(it); +    } +  }); +  return (only.length && only) || specs;  }; | 
