mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-23 09:50:24 +00:00
initial concept
This commit is contained in:
parent
fdc0bb232a
commit
e664186f93
1 changed files with 57 additions and 0 deletions
57
src/scenario/Future.js
Normal file
57
src/scenario/Future.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
function Future(name, behavior) {
|
||||
this.value = undefined;
|
||||
this.name = name;
|
||||
this.behavior = behavior;
|
||||
this.fulfilled = false;
|
||||
}
|
||||
|
||||
Future.prototype = {
|
||||
fulfill: function(value){
|
||||
this.fulfilled = true;
|
||||
this.value = value;
|
||||
}
|
||||
};
|
||||
|
||||
function future(name, behavior) {
|
||||
return new Future(name, behavior);
|
||||
};
|
||||
|
||||
function repeater(selector) {
|
||||
var repeaterFuture = future('repeater ' + selector, function(done) {
|
||||
done($(selector));
|
||||
});
|
||||
|
||||
repeaterFuture.count = function(){
|
||||
return future(repeaterFuture.name + ' count', function(done) {
|
||||
done(repeaterFuture.value.size());
|
||||
});
|
||||
};
|
||||
|
||||
return repeaterFuture;
|
||||
}
|
||||
|
||||
function Matcher(future, logger) {
|
||||
var self = this;
|
||||
this.logger = logger;
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
Matcher.addMatcher = function(name, matcher){
|
||||
Matcher.prototype[name] = function(expected) {
|
||||
var future = this.future;
|
||||
$scenario.addFuture(
|
||||
'expect ' + future.name + ' ' + name + ' ' + expected,
|
||||
function(done){
|
||||
if (matcher(future.value, expected))
|
||||
throw "Expected " + expected + ' but was ' + future.value;
|
||||
done();
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
Matcher.addMatcher('toEqual', function(a,b){ return a == b; });
|
||||
|
||||
function expect(future) {
|
||||
return new Matcher(future, window.alert);
|
||||
}
|
||||
Loading…
Reference in a new issue