angular.js/src/scenario/Matcher.js

22 lines
584 B
JavaScript
Raw Normal View History

function Matcher(scope, future, logger) {
var self = scope.$scenario = this;
2010-07-27 22:53:55 +00:00
this.logger = logger;
this.future = future;
}
Matcher.addMatcher = function(name, matcher) {
2010-07-27 22:53:55 +00:00
Matcher.prototype[name] = function(expected) {
var future = this.future;
$scenario.addFuture(
'expect ' + future.name + ' ' + name + ' ' + expected,
function(done){
2010-08-04 18:47:10 +00:00
if (!matcher(future.value, expected))
2010-07-27 22:53:55 +00:00
throw "Expected " + expected + ' but was ' + future.value;
done();
}
);
};
};
Matcher.addMatcher('toEqual', function(a,b) { return a == b; });