aboutsummaryrefslogtreecommitdiffstats
path: root/test/scenario/dslSpec.js
diff options
context:
space:
mode:
authorElliott Sprehn2010-10-24 14:14:45 -0700
committerIgor Minar2010-10-26 15:17:57 -0700
commit40d7e66f408eaaa66efd8d7934ab2eb3324236a1 (patch)
treedaf88d70df9037416598307784eb83df93df4fed /test/scenario/dslSpec.js
parent1d52349440d40de527b5d7f3849070f525c1b79b (diff)
downloadangular.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/dslSpec.js')
-rw-r--r--test/scenario/dslSpec.js82
1 files changed, 40 insertions, 42 deletions
diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js
index 14ca8b2c..bbba0b7d 100644
--- a/test/scenario/dslSpec.js
+++ b/test/scenario/dslSpec.js
@@ -1,41 +1,21 @@
-/**
- * Very basic Mock of angular.
- */
-function AngularMock() {
- this.reset();
- this.service = this;
-}
-
-AngularMock.prototype.reset = function() {
- this.log = [];
-};
-
-AngularMock.prototype.$browser = function() {
- this.log.push('$brower()');
- return this;
-};
-
-AngularMock.prototype.poll = function() {
- this.log.push('$brower.poll()');
- return this;
-};
-
-AngularMock.prototype.notifyWhenNoOutstandingRequests = function(fn) {
- this.log.push('$brower.notifyWhenNoOutstandingRequests()');
- fn();
-};
-
describe("angular.scenario.dsl", function() {
- var $window;
- var $root;
- var application;
+ var $window, $root;
+ var application, eventLog;
beforeEach(function() {
+ eventLog = [];
$window = {
document: _jQuery("<div></div>"),
- angular: new AngularMock()
+ angular: new angular.scenario.testing.MockAngular()
};
- $root = angular.scope();
+ $root = angular.scope({
+ emit: function(eventName) {
+ eventLog.push(eventName);
+ },
+ on: function(eventName) {
+ eventLog.push('Listener Added for ' + eventName);
+ }
+ });
$root.futures = [];
$root.futureLog = [];
$root.$window = $window;
@@ -54,7 +34,7 @@ describe("angular.scenario.dsl", function() {
};
});
$root.application = new angular.scenario.Application($window.document);
- $root.application.getWindow = function() {
+ $root.application.getWindow_ = function() {
return $window;
};
$root.application.navigateTo = function(url, callback) {
@@ -74,13 +54,14 @@ describe("angular.scenario.dsl", function() {
expect($root.futureLog).toEqual([]);
$window.resume();
expect($root.futureLog).
- toEqual(['waiting for you to call resume() in the console']);
+ toEqual(['waiting for you to resume']);
+ expect(eventLog).toContain('InteractiveWait');
});
});
describe('Pause', function() {
beforeEach(function() {
- $root.setTimeout = function(fn, value) {
+ $root.$window.setTimeout = function(fn, value) {
$root.timerValue = value;
fn();
};
@@ -127,13 +108,6 @@ describe("angular.scenario.dsl", function() {
expect($window.location).toEqual('http://myurl');
expect($root.futureResult).toEqual('http://myurl');
});
-
- it('should wait for angular notify when no requests pending', function() {
- $root.dsl.navigateTo('url');
- expect($window.angular.log).toContain('$brower.poll()');
- expect($window.angular.log).
- toContain('$brower.notifyWhenNoOutstandingRequests()');
- });
});
describe('Element Finding', function() {
@@ -199,6 +173,24 @@ describe("angular.scenario.dsl", function() {
$root.dsl.element('a').click();
});
+ it('should navigate page if click on anchor', function() {
+ expect($window.location).not.toEqual('#foo');
+ doc.append('<a href="#foo"></a>');
+ $root.dsl.element('a').click();
+ expect($window.location).toEqual('#foo');
+ });
+
+ it('should count matching elements', function() {
+ doc.append('<span></span><span></span>');
+ $root.dsl.element('span').count();
+ expect($root.futureResult).toEqual(2);
+ });
+
+ it('should return count of 0 if no matching elements', function() {
+ $root.dsl.element('span').count();
+ expect($root.futureResult).toEqual(0);
+ });
+
it('should get attribute', function() {
doc.append('<div id="test" class="foo"></div>');
$root.dsl.element('#test').attr('class');
@@ -249,6 +241,12 @@ describe("angular.scenario.dsl", function() {
expect($root.futureResult).toEqual(2);
});
+ it('should return 0 if repeater doesnt match', function() {
+ doc.find('ul').html('');
+ chain.count();
+ expect($root.futureResult).toEqual(0);
+ });
+
it('should get a row of bindings', function() {
chain.row(1);
expect($root.futureResult).toEqual(['felisa', 'female']);