diff options
| author | Elliott Sprehn | 2010-10-08 16:43:40 -0700 |
|---|---|---|
| committer | Elliott Sprehn | 2010-10-14 09:47:39 -0700 |
| commit | 03df6cbddbb80186caf571e29957370b2ef9881c (patch) | |
| tree | d5a321c8b207b464a5c8a300c422186e20e8ae31 /test/scenario/SpecRunnerSpec.js | |
| parent | 0f104317dff5628765e26cc68df7dd1175b2aa5e (diff) | |
| download | angular.js-03df6cbddbb80186caf571e29957370b2ef9881c.tar.bz2 | |
New Angular Scenario runner and DSL system with redesigned HTML UI.
Uses the Jasmine syntax for tests, ex:
describe('widgets', function() {
it('should verify that basic widgets work', function(){
navigateTo('widgets.html');
input('text.basic').enter('Carlos');
expect(binding('text.basic')).toEqual('Carlos');
input('text.basic').enter('Carlos Santana');
expect(binding('text.basic')).not().toEqual('Carlos Boozer');
input('text.password').enter('secret');
expect(binding('text.password')).toEqual('secret');
expect(binding('text.hidden')).toEqual('hiddenValue');
expect(binding('gender')).toEqual('male');
input('gender').select('female');
expect(binding('gender')).toEqual('female');
});
});
Note: To create new UI's implement the interface shown in angular.scenario.ui.Html.
Diffstat (limited to 'test/scenario/SpecRunnerSpec.js')
| -rw-r--r-- | test/scenario/SpecRunnerSpec.js | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/test/scenario/SpecRunnerSpec.js b/test/scenario/SpecRunnerSpec.js new file mode 100644 index 00000000..81b66956 --- /dev/null +++ b/test/scenario/SpecRunnerSpec.js @@ -0,0 +1,165 @@ +/** + * 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) { + this.$window = $window; +} +ApplicationMock.prototype = { + executeAction: function(callback) { + callback.call(this.$window); + } +}; + +describe('angular.scenario.SpecRunner', function() { + var $window; + var runner; + + beforeEach(function() { + $window = {}; + runner = angular.scope(); + runner.application = new ApplicationMock($window); + runner.$become(angular.scenario.SpecRunner); + }); + + it('should bind futures to the spec', function() { + runner.addFuture('test future', function(done) { + this.application.value = 10; + done(); + }); + runner.futures[0].execute(angular.noop); + expect(runner.application.value).toEqual(10); + }); + + it('should pass done to future action behavior', function() { + runner.addFutureAction('test future', function(done) { + expect(angular.isFunction(done)).toBeTruthy(); + done(10, 20); + }); + runner.futures[0].execute(function(error, result) { + expect(error).toEqual(10); + expect(result).toEqual(20); + }); + }); + + it('should pass execute future action on the $window', function() { + runner.addFutureAction('test future', function(done) { + this.test = 'test value'; + done(); + }); + runner.futures[0].execute(angular.noop); + expect($window.test).toEqual('test value'); + }); + + it('should execute spec function and notify UI', function() { + var finished = false; + var ui = new UIMock(); + var spec = {name: 'test spec', fn: function() { + this.test = 'some value'; + }}; + runner.addFuture('test future', function(done) { + done(); + }); + runner.run(ui, 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:' + ]); + }); + + it('should execute notify UI on spec setup error', function() { + var finished = false; + var ui = new UIMock(); + var spec = {name: 'test spec', fn: function() { + throw 'message'; + }}; + runner.run(ui, spec, function() { + finished = true; + }); + expect(finished).toBeTruthy(); + expect(ui.log).toEqual([ + 'addSpec:test spec', + 'spec error:message' + ]); + }); + + it('should execute notify UI on step failure', function() { + var finished = false; + var ui = new UIMock(); + var spec = {name: 'test spec', fn: angular.noop}; + runner.addFuture('test future', function(done) { + done('failure message'); + }); + runner.run(ui, spec, function() { + finished = true; + }); + expect(finished).toBeTruthy(); + expect(ui.log).toEqual([ + 'addSpec:test spec', + 'addStep:test future', + 'step finish:failure message', + 'spec finish:failure message' + ]); + }); + + it('should execute notify UI on step error', function() { + var finished = false; + var ui = new UIMock(); + var spec = {name: 'test spec', fn: angular.noop}; + runner.addFuture('test future', function(done) { + throw 'error message'; + }); + runner.run(ui, spec, function() { + finished = true; + }); + expect(finished).toBeTruthy(); + expect(ui.log).toEqual([ + 'addSpec:test spec', + 'addStep:test future', + 'step error:error message', + 'spec finish:error message' + ]); + }); + +}); |
