AngularJS tutorial有自定义匹配器在 Jasmine 中不起作用 starting from version 2.0 :
beforeEach(function(){
this.addMatchers({
toEqualData: function(expected) {
return angular.equals(this.actual, expected);
}
});
});
尝试修改匹配器失败并出现错误:
类型错误:未定义不是对象(正在评估“matcherCompare.apply”)
我的匹配器定义:
beforeEach(function(){
jasmine.addMatchers({
toEqualData: function(util, customEqualityTesters, actual, expected) {
return angular.equals(actual, expected);
}
});
});
Jasmine 2.0 custom matcher docs .
如何让它发挥作用?
最佳答案
beforeEach(function () {
jasmine.addMatchers({
toEqualData: function () {
return {
compare: function (actual, expected) {
return {pass: angular.equals(actual, expected)};
}
};
}
});
});
关于javascript - 如何重写 Jasmine 2.0 自定义匹配器以与 Angular 1.5 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36366608/