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 /test/scenario/SpecRunnerSpec.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 'test/scenario/SpecRunnerSpec.js')
| -rw-r--r-- | test/scenario/SpecRunnerSpec.js | 123 |
1 files changed, 47 insertions, 76 deletions
diff --git a/test/scenario/SpecRunnerSpec.js b/test/scenario/SpecRunnerSpec.js index 921d6853..7947a3ca 100644 --- a/test/scenario/SpecRunnerSpec.js +++ b/test/scenario/SpecRunnerSpec.js @@ -1,40 +1,4 @@ /** - * Mock of all required UI classes/methods. (UI, Spec, Step). - */ -function UIMock() { - this.log = []; -} -UIMock.prototype = { - addSpec: function(spec) { - var log = this.log; - log.push('addSpec:' + spec.name); - return { - addStep: function(name) { - log.push('addStep:' + name); - return { - finish: function(e) { - log.push('step finish:' + (e ? e : '')); - return this; - }, - error: function(e) { - log.push('step error:' + (e ? e : '')); - return this; - } - }; - }, - finish: function(e) { - log.push('spec finish:' + (e ? e : '')); - return this; - }, - error: function(e) { - log.push('spec error:' + (e ? e : '')); - return this; - } - }; - } -}; - -/** * Mock Application */ function ApplicationMock($window) { @@ -47,7 +11,7 @@ ApplicationMock.prototype = { }; describe('angular.scenario.SpecRunner', function() { - var $window; + var $window, $root, log; var runner; function createSpec(name, body) { @@ -60,14 +24,22 @@ describe('angular.scenario.SpecRunner', function() { } beforeEach(function() { + log = []; $window = {}; $window.setTimeout = function(fn, timeout) { fn(); }; - runner = angular.scope(); - runner.application = new ApplicationMock($window); - runner.$window = $window; - runner.$become(angular.scenario.SpecRunner); + $root = angular.scope({ + emit: function(eventName) { + log.push(eventName); + }, + on: function(eventName) { + log.push('Listener Added for ' + eventName); + } + }); + $root.application = new ApplicationMock($window); + $root.$window = $window; + runner = $root.$new(angular.scenario.SpecRunner); }); it('should bind futures to the spec', function() { @@ -92,84 +64,82 @@ describe('angular.scenario.SpecRunner', function() { it('should execute spec function and notify UI', function() { var finished; - var ui = new UIMock(); var spec = createSpec('test spec', function() { this.test = 'some value'; }); runner.addFuture('test future', function(done) { done(); }); - runner.run(ui, spec, function() { + runner.run(spec, function() { finished = true; }); expect(runner.test).toEqual('some value'); expect(finished).toBeTruthy(); - expect(ui.log).toEqual([ - 'addSpec:test spec', - 'addStep:test future', - 'step finish:', - 'spec finish:' + expect(log).toEqual([ + 'SpecBegin', + 'StepBegin', + 'StepEnd', + 'SpecEnd' ]); }); it('should execute notify UI on spec setup error', function() { var finished; - var ui = new UIMock(); var spec = createSpec('test spec', function() { throw 'message'; }); - runner.run(ui, spec, function() { + runner.run(spec, function() { finished = true; }); expect(finished).toBeTruthy(); - expect(ui.log).toEqual([ - 'addSpec:test spec', - 'spec error:message' + expect(log).toEqual([ + 'SpecBegin', + 'SpecError', + 'SpecEnd' ]); }); it('should execute notify UI on step failure', function() { var finished; - var ui = new UIMock(); var spec = createSpec('test spec'); runner.addFuture('test future', function(done) { done('failure message'); }); - runner.run(ui, spec, function() { + runner.run(spec, function() { finished = true; }); expect(finished).toBeTruthy(); - expect(ui.log).toEqual([ - 'addSpec:test spec', - 'addStep:test future', - 'step finish:failure message', - 'spec finish:' + expect(log).toEqual([ + 'SpecBegin', + 'StepBegin', + 'StepFailure', + 'StepEnd', + 'SpecEnd' ]); }); it('should execute notify UI on step error', function() { var finished; - var ui = new UIMock(); var spec = createSpec('test spec', function() { this.addFuture('test future', function(done) { throw 'error message'; }); }); - runner.run(ui, spec, function() { + runner.run(spec, function() { finished = true; }); expect(finished).toBeTruthy(); - expect(ui.log).toEqual([ - 'addSpec:test spec', - 'addStep:test future', - 'step error:error message', - 'spec finish:' + expect(log).toEqual([ + 'SpecBegin', + 'StepBegin', + 'StepError', + 'StepEnd', + 'SpecEnd' ]); }); it('should run after handlers even if error in body of spec', function() { var finished, after; - var ui = new UIMock(); var spec = createSpec('test spec', function() { this.addFuture('body', function(done) { throw 'error message'; @@ -181,18 +151,19 @@ describe('angular.scenario.SpecRunner', function() { done(); }); }; - runner.run(ui, spec, function() { + runner.run(spec, function() { finished = true; }); expect(finished).toBeTruthy(); expect(after).toBeTruthy(); - expect(ui.log).toEqual([ - 'addSpec:test spec', - 'addStep:body', - 'step error:error message', - 'addStep:after', - 'step finish:', - 'spec finish:' + expect(log).toEqual([ + 'SpecBegin', + 'StepBegin', + 'StepError', + 'StepEnd', + 'StepBegin', + 'StepEnd', + 'SpecEnd' ]); }); |
