mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-20 12:21:52 +00:00
added error handling on scenario definition
This commit is contained in:
parent
f6c67e28c9
commit
3fab5d9879
10 changed files with 67 additions and 27 deletions
|
|
@ -7,6 +7,7 @@ load:
|
||||||
- test/jquery_alias.js
|
- test/jquery_alias.js
|
||||||
- src/Angular.js
|
- src/Angular.js
|
||||||
- src/*.js
|
- src/*.js
|
||||||
|
- src/scenario/Runner.js
|
||||||
- src/scenario/*.js
|
- src/scenario/*.js
|
||||||
- test/testabilityPatch.js
|
- test/testabilityPatch.js
|
||||||
- test/angular-mocks.js
|
- test/angular-mocks.js
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ load:
|
||||||
- test/jquery_remove.js
|
- test/jquery_remove.js
|
||||||
- src/Angular.js
|
- src/Angular.js
|
||||||
- src/*.js
|
- src/*.js
|
||||||
|
- src/scenario/Runner.js
|
||||||
- src/scenario/*.js
|
- src/scenario/*.js
|
||||||
- test/testabilityPatch.js
|
- test/testabilityPatch.js
|
||||||
- test/angular-mocks.js
|
- test/angular-mocks.js
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
<head>
|
<head>
|
||||||
<script type="text/javascript" src="../src/scenario/bootstrap.js"></script>
|
<script type="text/javascript" src="../src/scenario/bootstrap.js"></script>
|
||||||
<script type="text/javascript" src="widgets-scenario2.js"></script>
|
<script type="text/javascript" src="widgets-scenario.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
20
scenario/widgets-scenario.js
Normal file
20
scenario/widgets-scenario.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
describe('widgets', function(){
|
||||||
|
it('should verify that basic widgets work', function(){
|
||||||
|
browser.navigateTo('widgets.html');
|
||||||
|
|
||||||
|
expect('{{text.basic}}').toEqual('');
|
||||||
|
input('text.basic').enter('John');
|
||||||
|
expect('{{text.basic}}').toEqual('John');
|
||||||
|
|
||||||
|
expect('{{text.password}}').toEqual('');
|
||||||
|
input('text.password').enter('secret');
|
||||||
|
expect('{{text.password}}').toEqual('secret');
|
||||||
|
|
||||||
|
expect('{{text.hidden}}').toEqual('hiddenValue');
|
||||||
|
|
||||||
|
expect('{{gender}}').toEqual('male');
|
||||||
|
input('gender').select('female');
|
||||||
|
expect('{{gender}}').toEqual('female');
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -26,8 +26,8 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>hidden</td>
|
<td>hidden</td>
|
||||||
<td><input type="hidden" name="hidden" value="hiddenValue" /></td>
|
<td><input type="hidden" name="text.hidden" value="hiddenValue" /></td>
|
||||||
<td>hidden={{hidden}}</td>
|
<td>text.hidden={{text.hidden}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><th colspan="3">Input selection field</th></tr>
|
<tr><th colspan="3">Input selection field</th></tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
browser = {
|
angular.scenario.dsl.browser = {
|
||||||
navigateTo: function(url){
|
navigateTo: function(url){
|
||||||
$scenario.addStep('Navigate to: ' + url, function(done){
|
$scenario.addStep('Navigate to: ' + url, function(done){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
@ -16,21 +16,22 @@ browser = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function input(selector) {
|
angular.scenario.dsl.input = function(selector) {
|
||||||
return {
|
return {
|
||||||
enter: function(value){
|
enter: function(value){
|
||||||
$scenario.addStep("Set input text of '" + selector + "' to value '" + value + "'", function(done){
|
$scenario.addStep("Set input text of '" + selector + "' to value '" +
|
||||||
var input = this.testDocument.find('input[name=' + selector + ']');
|
value + "'", function(done){
|
||||||
input.val(value);
|
var input = this.testDocument.find('input[name=' + selector + ']');
|
||||||
input.trigger('change');
|
input.val(value);
|
||||||
this.testWindow.angular.element(input[0]).trigger('change');
|
input.trigger('change');
|
||||||
done();
|
this.testWindow.angular.element(input[0]).trigger('change');
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
function expect(selector) {
|
angular.scenario.dsl.expect = function(selector) {
|
||||||
return {
|
return {
|
||||||
toEqual: function(expected) {
|
toEqual: function(expected) {
|
||||||
$scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){
|
$scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){
|
||||||
|
|
@ -43,13 +44,4 @@ function expect(selector) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
describe('widgets', function(){
|
|
||||||
it('should verify that basic widgets work', function(){
|
|
||||||
browser.navigateTo('widgets.html');
|
|
||||||
expect('{{text.basic}}').toEqual('');
|
|
||||||
input('text.basic').enter('John');
|
|
||||||
expect('{{text.basic}}').toEqual('John');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
angular['scenario'] = (angular['scenario'] = {});
|
angular['scenario'] = (angular['scenario'] = {});
|
||||||
|
angular.scenario['dsl'] = (angular.scenario['dsl'] = {});
|
||||||
|
|
||||||
angular.scenario.Runner = function(scope, jQuery){
|
angular.scenario.Runner = function(scope, jQuery){
|
||||||
var self = scope.$scenario = this;
|
var self = scope.$scenario = this;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.jQuery = jQuery;
|
this.jQuery = jQuery;
|
||||||
|
angular.extend(scope, angular.scenario.dsl);
|
||||||
|
|
||||||
var specs = this.specs = {};
|
var specs = this.specs = {};
|
||||||
var path = [];
|
var path = [];
|
||||||
|
|
@ -18,7 +20,13 @@ angular.scenario.Runner = function(scope, jQuery){
|
||||||
name: specName,
|
name: specName,
|
||||||
steps:[]
|
steps:[]
|
||||||
};
|
};
|
||||||
body();
|
try {
|
||||||
|
body();
|
||||||
|
} catch(err) {
|
||||||
|
self.addStep(err.message || 'ERROR', function(){
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
}
|
||||||
self.currentSpec = null;
|
self.currentSpec = null;
|
||||||
};
|
};
|
||||||
this.logger = function returnNoop(){
|
this.logger = function returnNoop(){
|
||||||
|
|
@ -55,6 +63,7 @@ angular.scenario.Runner.prototype = {
|
||||||
return angular.extend(logger(element), {
|
return angular.extend(logger(element), {
|
||||||
close: function(){
|
close: function(){
|
||||||
element.removeClass('running');
|
element.removeClass('running');
|
||||||
|
console.scrollTop(console[0].scrollHeight);
|
||||||
},
|
},
|
||||||
fail: function(){
|
fail: function(){
|
||||||
element.removeClass('running');
|
element.removeClass('running');
|
||||||
|
|
@ -66,7 +75,7 @@ angular.scenario.Runner.prototype = {
|
||||||
current = current.parent();
|
current = current.parent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});;
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
this.logger = logger(console);
|
this.logger = logger(console);
|
||||||
|
|
|
||||||
1
src/scenario/bootstrap.js
vendored
1
src/scenario/bootstrap.js
vendored
|
|
@ -29,6 +29,7 @@
|
||||||
addScript("../../lib/jquery/jquery-1.4.2.js");
|
addScript("../../lib/jquery/jquery-1.4.2.js");
|
||||||
addScript("../angular-bootstrap.js");
|
addScript("../angular-bootstrap.js");
|
||||||
addScript("Runner.js");
|
addScript("Runner.js");
|
||||||
|
addScript("DSL.js");
|
||||||
document.write('<script type="text/javascript">' +
|
document.write('<script type="text/javascript">' +
|
||||||
'$scenarioRunner = new angular.scenario.Runner(window, jQuery);' +
|
'$scenarioRunner = new angular.scenario.Runner(window, jQuery);' +
|
||||||
'</script>');
|
'</script>');
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,23 @@ describe('Runner', function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should camplain on duplicate it', angular.noop);
|
it('should camplain on duplicate it', angular.noop);
|
||||||
|
it('should create a failing step if there is a javascript error', function(){
|
||||||
|
var spec;
|
||||||
|
Describe('D1', function(){
|
||||||
|
It('I1', function(){
|
||||||
|
spec = $scenario.currentSpec;
|
||||||
|
throw {message: 'blah'};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var step = spec.steps[0];
|
||||||
|
expect(step.name).toEqual('blah');
|
||||||
|
try {
|
||||||
|
step.fn();
|
||||||
|
fail();
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toEqual('blah');
|
||||||
|
};
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue