AngularJS tutorial自定义匹配器无法在Jasmine starting from version 2.0中运行:
beforeEach(function(){
this.addMatchers({
toEqualData: function(expected) {
return angular.equals(this.actual, expected);
}
});
});
修改匹配器的尝试失败,错误:
TypeError: undefined is not an object (evaluating 'matcherCompare.apply')
我的匹配器定义:
beforeEach(function(){
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters, actual, expected) {
return angular.equals(actual, expected);
}
});
});
Jasmine 2.0 custom matcher docs
如何让它发挥作用?
答案 0 :(得分:1)
beforeEach(function () {
jasmine.addMatchers({
toEqualData: function () {
return {
compare: function (actual, expected) {
return {pass: angular.equals(actual, expected)};
}
};
}
});
});