This commit is contained in:
Andres Ornelas Mesta 2010-05-24 13:54:32 -07:00
parent d485421e0e
commit f6c67e28c9
9 changed files with 75 additions and 24 deletions

View file

@ -4,6 +4,7 @@ load:
- lib/jasmine/jasmine-0.10.3.js
- lib/jasmine-jstd-adapter/JasmineAdapter.js
- lib/jquery/jquery-1.4.2.js
- test/jquery_alias.js
- src/Angular.js
- src/*.js
- src/scenario/*.js
@ -17,3 +18,5 @@ exclude:
- src/angular.suffix
- src/angular-bootstrap.js
- src/AngularPublic.js
- test/jquery_remove.js

View file

@ -3,7 +3,8 @@ server: http://localhost:9876
load:
- lib/jasmine/jasmine-0.10.3.js
- lib/jasmine-jstd-adapter/JasmineAdapter.js
# - lib/jquery/jquery-1.4.2.js
- lib/jquery/jquery-1.4.2.js
- test/jquery_remove.js
- src/Angular.js
- src/*.js
- src/scenario/*.js
@ -13,6 +14,7 @@ load:
- test/*.js
exclude:
- test/jquery_alias.js
- src/angular.prefix
- src/angular.suffix
- src/angular-bootstrap.js

View file

@ -4,7 +4,7 @@ browser = {
var self = this;
self.testFrame.load(function(){
self.testFrame.unbind();
self.testDocument = self.testWindow.angular.element(self.testWindow.document);
self.testDocument = jQuery(self.testWindow.document);
done();
});
if (this.testFrame.attr('src') == url) {
@ -23,6 +23,7 @@ function input(selector) {
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
input.trigger('change');
this.testWindow.angular.element(input[0]).trigger('change');
done();
});
}
@ -49,6 +50,6 @@ describe('widgets', function(){
browser.navigateTo('widgets.html');
expect('{{text.basic}}').toEqual('');
input('text.basic').enter('John');
expect('{{text.basic}}').toEqual('JohnXX');
expect('{{text.basic}}').toEqual('John');
});
});

View file

@ -2,7 +2,6 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="../lib/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
</head>
<body ng:init="$window.$scope = this">

View file

@ -1,8 +1,9 @@
angular['scenario'] = (angular['scenario'] = {});
angular.scenario.Runner = function(scope){
angular.scenario.Runner = function(scope, jQuery){
var self = scope.$scenario = this;
this.scope = scope;
this.jQuery = jQuery;
var specs = this.specs = {};
var path = [];
@ -27,6 +28,7 @@ angular.scenario.Runner = function(scope){
angular.scenario.Runner.prototype = {
run: function(body){
var jQuery = this.jQuery;
body.append(
'<div id="runner">' +
'<div class="console"></div>' +
@ -68,7 +70,19 @@ angular.scenario.Runner.prototype = {
};
}
this.logger = logger(console);
this.execute("widgets: it should verify that basic widgets work");
var specNames = [];
angular.foreach(this.specs, function(spec, name){
specNames.push(name);
}, this);
specNames.sort();
var self = this;
function callback(){
var next = specNames.shift();
if(next) {
self.execute(next, callback);
}
};
callback();
},
addStep: function(name, step) {
@ -102,21 +116,21 @@ angular.scenario.Runner.prototype = {
}
function next(){
var step = spec.steps[spec.nextStepIndex];
(result.log || {close:angular.noop}).close();
result.log = null;
if (step) {
spec.nextStepIndex ++;
result.log = stepLogger('step', step.name);
try {
step.fn.call(specThis, next);
} catch (e) {
result.fail(e);
done();
}
} else {
result.passed = !result.failed;
(result.log || {close:angular.noop}).close();
result.log = null;
if (step) {
spec.nextStepIndex ++;
result.log = stepLogger('step', step.name);
try {
step.fn.call(specThis, next);
} catch (e) {
result.fail(e);
done();
}
} else {
result.passed = !result.failed;
done();
}
};
next();
return specThis;

View file

@ -20,7 +20,7 @@
window.onload = function(){
_.defer(function(){
$scenarioRunner.run(jQuery(document.body));
$scenarioRunner.run(jQuery(window.document.body));
});
(onLoadDelegate||function(){})();
};
@ -29,6 +29,8 @@
addScript("../../lib/jquery/jquery-1.4.2.js");
addScript("../angular-bootstrap.js");
addScript("Runner.js");
document.write('<script type="text/javascript">$scenarioRunner = new angular.scenario.Runner(window);</script>');
document.write('<script type="text/javascript">' +
'$scenarioRunner = new angular.scenario.Runner(window, jQuery);' +
'</script>');
})(window.onload);

1
test/jquery_alias.js vendored Normal file
View file

@ -0,0 +1 @@
var _jQuery = jQuery;

1
test/jquery_remove.js vendored Normal file
View file

@ -0,0 +1 @@
var _jQuery = jQuery.noConflict(true);

View file

@ -1,14 +1,18 @@
describe('Runner', function(){
var scenario, runner, log, Describe, It, $scenario;
var scenario, runner, log, Describe, It, $scenario, body;
function logger(text) {
return function(){log += text;};
return function(done){
log += text;
(done||noop)();
};
}
beforeEach(function(){
log = '';
scenario = {};
runner = new angular.scenario.Runner(scenario);
body = _jQuery('<div></div>');
runner = new angular.scenario.Runner(scenario, _jQuery);
Describe = scenario.describe;
It = scenario.it;
$scenario = scenario.$scenario;
@ -105,4 +109,28 @@ describe('Runner', function(){
});
});
describe('run', function(){
var next;
it('should execute all specs', function(){
Describe('d1', function(){
It('it1', function(){ $scenario.addStep('s1', logger('s1,')); });
It('it2', function(){
$scenario.addStep('s2', logger('s2,'));
$scenario.addStep('s2.2', function(done){ next = done; });
});
});
Describe('d2', function(){
It('it3', function(){ $scenario.addStep('s3', logger('s3,')); });
It('it4', function(){ $scenario.addStep('s4', logger('s4,')); });
});
$scenario.run(body);
expect(log).toEqual('s1,s2,');
next();
expect(log).toEqual('s1,s2,s3,s4,');
});
});
});