Skip to content

Commit f6c67e2

Browse files
author
Andres Ornelas Mesta
committed
happy
1 parent d485421 commit f6c67e2

9 files changed

Lines changed: 75 additions & 24 deletions

File tree

jsTestDriver-jquery.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load:
44
- lib/jasmine/jasmine-0.10.3.js
55
- lib/jasmine-jstd-adapter/JasmineAdapter.js
66
- lib/jquery/jquery-1.4.2.js
7+
- test/jquery_alias.js
78
- src/Angular.js
89
- src/*.js
910
- src/scenario/*.js
@@ -17,3 +18,5 @@ exclude:
1718
- src/angular.suffix
1819
- src/angular-bootstrap.js
1920
- src/AngularPublic.js
21+
- test/jquery_remove.js
22+

jsTestDriver.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ server: http://localhost:9876
33
load:
44
- lib/jasmine/jasmine-0.10.3.js
55
- lib/jasmine-jstd-adapter/JasmineAdapter.js
6-
# - lib/jquery/jquery-1.4.2.js
6+
- lib/jquery/jquery-1.4.2.js
7+
- test/jquery_remove.js
78
- src/Angular.js
89
- src/*.js
910
- src/scenario/*.js
@@ -13,6 +14,7 @@ load:
1314
- test/*.js
1415

1516
exclude:
17+
- test/jquery_alias.js
1618
- src/angular.prefix
1719
- src/angular.suffix
1820
- src/angular-bootstrap.js

scenario/widgets-scenario2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ browser = {
44
var self = this;
55
self.testFrame.load(function(){
66
self.testFrame.unbind();
7-
self.testDocument = self.testWindow.angular.element(self.testWindow.document);
7+
self.testDocument = jQuery(self.testWindow.document);
88
done();
99
});
1010
if (this.testFrame.attr('src') == url) {
@@ -23,6 +23,7 @@ function input(selector) {
2323
var input = this.testDocument.find('input[name=' + selector + ']');
2424
input.val(value);
2525
input.trigger('change');
26+
this.testWindow.angular.element(input[0]).trigger('change');
2627
done();
2728
});
2829
}
@@ -49,6 +50,6 @@ describe('widgets', function(){
4950
browser.navigateTo('widgets.html');
5051
expect('{{text.basic}}').toEqual('');
5152
input('text.basic').enter('John');
52-
expect('{{text.basic}}').toEqual('JohnXX');
53+
expect('{{text.basic}}').toEqual('John');
5354
});
5455
});

scenario/widgets.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
33
<head>
44
<link rel="stylesheet" type="text/css" href="style.css"/>
5-
<script type="text/javascript" src="../lib/jquery/jquery-1.4.2.js"></script>
65
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
76
</head>
87
<body ng:init="$window.$scope = this">

src/scenario/Runner.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
angular['scenario'] = (angular['scenario'] = {});
22

3-
angular.scenario.Runner = function(scope){
3+
angular.scenario.Runner = function(scope, jQuery){
44
var self = scope.$scenario = this;
55
this.scope = scope;
6+
this.jQuery = jQuery;
67

78
var specs = this.specs = {};
89
var path = [];
@@ -27,6 +28,7 @@ angular.scenario.Runner = function(scope){
2728

2829
angular.scenario.Runner.prototype = {
2930
run: function(body){
31+
var jQuery = this.jQuery;
3032
body.append(
3133
'<div id="runner">' +
3234
'<div class="console"></div>' +
@@ -68,7 +70,19 @@ angular.scenario.Runner.prototype = {
6870
};
6971
}
7072
this.logger = logger(console);
71-
this.execute("widgets: it should verify that basic widgets work");
73+
var specNames = [];
74+
angular.foreach(this.specs, function(spec, name){
75+
specNames.push(name);
76+
}, this);
77+
specNames.sort();
78+
var self = this;
79+
function callback(){
80+
var next = specNames.shift();
81+
if(next) {
82+
self.execute(next, callback);
83+
}
84+
};
85+
callback();
7286
},
7387

7488
addStep: function(name, step) {
@@ -102,21 +116,21 @@ angular.scenario.Runner.prototype = {
102116
}
103117
function next(){
104118
var step = spec.steps[spec.nextStepIndex];
105-
(result.log || {close:angular.noop}).close();
106-
result.log = null;
107-
if (step) {
108-
spec.nextStepIndex ++;
109-
result.log = stepLogger('step', step.name);
110-
try {
111-
step.fn.call(specThis, next);
112-
} catch (e) {
113-
result.fail(e);
114-
done();
115-
}
116-
} else {
117-
result.passed = !result.failed;
119+
(result.log || {close:angular.noop}).close();
120+
result.log = null;
121+
if (step) {
122+
spec.nextStepIndex ++;
123+
result.log = stepLogger('step', step.name);
124+
try {
125+
step.fn.call(specThis, next);
126+
} catch (e) {
127+
result.fail(e);
118128
done();
119129
}
130+
} else {
131+
result.passed = !result.failed;
132+
done();
133+
}
120134
};
121135
next();
122136
return specThis;

src/scenario/bootstrap.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
window.onload = function(){
2222
_.defer(function(){
23-
$scenarioRunner.run(jQuery(document.body));
23+
$scenarioRunner.run(jQuery(window.document.body));
2424
});
2525
(onLoadDelegate||function(){})();
2626
};
@@ -29,6 +29,8 @@
2929
addScript("../../lib/jquery/jquery-1.4.2.js");
3030
addScript("../angular-bootstrap.js");
3131
addScript("Runner.js");
32-
document.write('<script type="text/javascript">$scenarioRunner = new angular.scenario.Runner(window);</script>');
32+
document.write('<script type="text/javascript">' +
33+
'$scenarioRunner = new angular.scenario.Runner(window, jQuery);' +
34+
'</script>');
3335
})(window.onload);
3436

test/jquery_alias.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var _jQuery = jQuery;

test/jquery_remove.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var _jQuery = jQuery.noConflict(true);

test/scenario/RunnerSpec.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
describe('Runner', function(){
2-
var scenario, runner, log, Describe, It, $scenario;
2+
var scenario, runner, log, Describe, It, $scenario, body;
33

44
function logger(text) {
5-
return function(){log += text;};
5+
return function(done){
6+
log += text;
7+
(done||noop)();
8+
};
69
}
710

811
beforeEach(function(){
912
log = '';
1013
scenario = {};
11-
runner = new angular.scenario.Runner(scenario);
14+
body = _jQuery('<div></div>');
15+
runner = new angular.scenario.Runner(scenario, _jQuery);
1216
Describe = scenario.describe;
1317
It = scenario.it;
1418
$scenario = scenario.$scenario;
@@ -105,4 +109,28 @@ describe('Runner', function(){
105109
});
106110
});
107111

112+
describe('run', function(){
113+
var next;
114+
it('should execute all specs', function(){
115+
Describe('d1', function(){
116+
It('it1', function(){ $scenario.addStep('s1', logger('s1,')); });
117+
It('it2', function(){
118+
$scenario.addStep('s2', logger('s2,'));
119+
$scenario.addStep('s2.2', function(done){ next = done; });
120+
});
121+
});
122+
Describe('d2', function(){
123+
It('it3', function(){ $scenario.addStep('s3', logger('s3,')); });
124+
It('it4', function(){ $scenario.addStep('s4', logger('s4,')); });
125+
});
126+
127+
$scenario.run(body);
128+
129+
expect(log).toEqual('s1,s2,');
130+
next();
131+
expect(log).toEqual('s1,s2,s3,s4,');
132+
133+
});
134+
});
135+
108136
});

0 commit comments

Comments
 (0)