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/RunnerSpec.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/RunnerSpec.js')
| -rw-r--r-- | test/scenario/RunnerSpec.js | 302 |
1 files changed, 80 insertions, 222 deletions
diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 2986add6..43d97257 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -1,238 +1,96 @@ -describe('Runner', function() { - - var Describe, It, BeforeEach, AfterEach, body; - +/** + * Mock spec runner. + */ +function MockSpecRunner() {} +MockSpecRunner.prototype.run = function(ui, spec, specDone) { + spec.fn.call(this); + specDone(); +}; + +describe('angular.scenario.Runner', function() { + var $window; + var runner; + beforeEach(function() { - setUpContext(); - Describe = _window.describe; - It = _window.it; - BeforeEach = _window.beforeEach; - AfterEach = _window.afterEach; - body = _jQuery('<div></div>'); - }); - - describe('describe', function() { - it('should consume the describe functions', function() { - Describe('describe name', logger('body')); - expect(log).toEqual('body'); + // Trick to get the scope out of a DSL statement + angular.scenario.dsl('dslScope', function() { + var scope = this; + return function() { return scope; }; }); - - describe('it', function() { - it('should consume it', function() { - Describe('describe name', function() { - It('should text', logger('body')); - }); - expect(log).toEqual('body'); - var spec = $scenario.specs['describe name: it should text']; - expect(spec.futures).toEqual([]); - expect(spec.name).toEqual('describe name: it should text'); - }); - - it('should complain on duplicate it', function() { - // WRITE ME!!!! - }); - - it('should create a failing future if there is a javascript error', function() { - var spec; - Describe('D1', function() { - It('I1', function() { - spec = $scenario.currentSpec; - throw {message: 'blah'}; - }); - }); - var future = spec.futures[0]; - expect(future.name).toEqual('blah'); - try { - future.behavior(); - fail(); - } catch (e) { - expect(e.message).toEqual('blah'); - } - }); - }); - - describe('beforeEach', function() { - it('should execute beforeEach before every it', function() { - Describe('describe name', function() { - BeforeEach(logger('before;')); - It('should text', logger('body;')); - It('should text2', logger('body2;')); - }); - expect(log).toEqual('before;body;before;body2;'); - }); + // Trick to get the scope out of a DSL statement + angular.scenario.dsl('dslChain', function() { + return function() { + this.chained = 0; + this.chain = function() { this.chained++; return this; }; + return this; + }; }); - describe('afterEach', function() { - it('should execute afterEach after every it', function() { - Describe('describe name', function() { - AfterEach(logger('after;')); - It('should text1', logger('body1;')); - It('should text2', logger('body2;')); - }); - expect(log).toEqual('body1;after;body2;after;'); - }); - - it('should always execute afterEach after every it', function() { - Describe('describe name', function() { - AfterEach(logger('after;')); - It('should text', function() { - logger('body1;')(); - throw "MyError"; - }); - It('should text2', logger('body2;')); - }); - expect(log).toEqual('body1;after;body2;after;'); - }); - - it('should report an error if afterEach fails', function() { - var next; - Describe('describe name', function() { - AfterEach(function() { - $scenario.addFuture('afterEachLog', logger('after;')); - $scenario.addFuture('afterEachThrow', function() { - throw "AfterError"; - }); - }); - It('should text1', function() { - $scenario.addFuture('future1', logger('future1;')); - }); - It('should text2', function() { - $scenario.addFuture('future2', logger('future2;')); - }); - }); - $scenario.run(body); - expect(log).toEqual('future1;after;future2;after;'); - expect(_window.$testrun.results).toEqual([ - { name : 'describe name: it should text1', - passed : false, - error : 'AfterError', - steps : [ 'future1', 'afterEachLog', 'afterEachThrow' ] }, - { name : 'describe name: it should text2', - passed : false, - error : 'AfterError', - steps : [ 'future2', 'afterEachLog', 'afterEachThrow' ] }]); - }); + $window = {}; + runner = new angular.scenario.Runner($window); + }); + + afterEach(function() { + delete angular.scenario.dsl.dslScope; + delete angular.scenario.dsl.dslChain; + }); + + it('should publish the functions in the public API', function() { + angular.foreach(runner.api, function(fn, name) { + var func; + if (name in $window) { + func = $window[name]; + } + expect(angular.isFunction(func)).toBeTruthy(); }); }); - - describe('future building', function() { - it('should queue futures', function() { - function behavior(){} - Describe('name', function() { - It('should', function() { - $scenario.addFuture('futureName', behavior); + + it('should construct valid describe trees with public API', function() { + var before = []; + var after = []; + $window.describe('A', function() { + $window.beforeEach(function() { before.push('A'); }); + $window.afterEach(function() { after.push('A'); }); + $window.it('1', angular.noop); + $window.describe('B', function() { + $window.beforeEach(function() { before.push('B'); }); + $window.afterEach(function() { after.push('B'); }); + $window.it('2', angular.noop); + $window.describe('C', function() { + $window.beforeEach(function() { before.push('C'); }); + $window.afterEach(function() { after.push('C'); }); + $window.it('3', angular.noop); }); }); - expect($scenario.specs['name: it should'].futures[0].name). - toEqual('futureName'); }); + var specs = runner.rootDescribe.getSpecs(); + specs[0].fn(); + expect(before).toEqual(['A', 'B', 'C']); + expect(after).toEqual(['C', 'B', 'A']); + expect(specs[2].definition.parent).toEqual(runner.rootDescribe); + expect(specs[0].definition.parent).toEqual(specs[2].definition.children[0]); }); - - describe('execution', function() { - it('should execute the queued futures', function() { - var next, firstThis, secondThis, doneThis, spec; - $scenario.specs['spec'] = { - futures: [ - new Future('future1', function(done) { - next = done; - log += 'first;'; - firstThis = this; - }), - new Future('future2', function(done) { - next = done; - log += 'second;'; - secondThis = this; - }) - ] - }; - - spec = $scenario.execute('spec', function(done){ - log += 'done;'; - doneThis = this; + + it('should publish the DSL statements to the $window', function() { + $window.describe('describe', function() { + $window.it('1', function() { + expect($window.dslScope).toBeDefined(); }); - expect(log).toEqual('first;'); - next(); - expect(log).toEqual('first;second;'); - next(); - expect(log).toEqual('first;second;done;'); - expect(spec === window).toEqual(false); - expect(spec).toEqual(firstThis); - expect(spec).toEqual(secondThis); - expect(spec).toEqual(doneThis); - - expect(spec.result.failed).toEqual(false); - expect(spec.result.finished).toEqual(true); - expect(spec.result.error).toBeUndefined(); - expect(spec.result.passed).toEqual(true); - }); - - it('should handle exceptions in a future', function() { - $scenario.specs['spec'] = { - futures: [ - new Future('first future', function(done) { - done(); - }), - new Future('error', function(done) { - throw "MyError"; - }), - new Future('should not execute', function(done) { - done(); - }) - ] - }; - - var spec = $scenario.execute('spec'); - - expect(spec.result.passed).toEqual(false); - expect(spec.result.failed).toEqual(true); - expect(spec.result.finished).toEqual(true); - expect(spec.result.error).toEqual("MyError"); - expect(_window.$testrun.results).toEqual([{ - name: 'spec', - passed: false, - error: 'MyError', - steps: ['first future', 'error']}]); }); + runner.run(null/*ui*/, null/*application*/, MockSpecRunner, rethrow); }); - - describe('run', function() { - var next; - beforeEach(function() { - Describe('d1', function() { - It('it1', function() { $scenario.addFuture('s1', logger('s1,')); }); - It('it2', function() { - $scenario.addFuture('s2', logger('s2,')); - $scenario.addFuture('s2.2', function(done){ next = done; }); - }); + + it('should create a new scope for each DSL chain', function() { + $window.describe('describe', function() { + $window.it('1', function() { + var scope = $window.dslScope(); + scope.test = "foo"; + expect($window.dslScope().test).toBeUndefined(); }); - Describe('d2', function() { - It('it3', function() { $scenario.addFuture('s3', logger('s3,')); }); - It('it4', function() { $scenario.addFuture('s4', logger('s4,')); }); + $window.it('2', function() { + var scope = $window.dslChain().chain().chain(); + expect(scope.chained).toEqual(2); }); }); - it('should execute all specs', function() { - $scenario.run(body); - - expect(log).toEqual('s1,s2,'); - next(); - expect(log).toEqual('s1,s2,s3,s4,'); - }); - it('should publish done state and results as tests are run', function() { - expect(_window.$testrun.done).toBeFalsy(); - expect(_window.$testrun.results).toEqual([]); - $scenario.run(body); - expect(_window.$testrun.done).toBeFalsy(); - expect(_window.$testrun.results).toEqual([ - {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']} - ]); - next(); - expect(_window.$testrun.done).toBeTruthy(); - expect(_window.$testrun.results).toEqual([ - {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}, - {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']}, - {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']}, - {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']} - ]); - }); + runner.run(null/*ui*/, null/*application*/, MockSpecRunner, rethrow); }); - -});
\ No newline at end of file +}); |
