2016-04-01 42 views
0

AngularJS tutorial有不茉莉花starting from version 2.0工作自定义匹配:如何重写Jasmine 2.0自定义匹配器与Angular 1.5一起使用?

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

如何使它工作?

回答

1
beforeEach(function() { 
    jasmine.addMatchers({ 
     toEqualData: function() { 
     return { 
      compare: function (actual, expected) { 
      return {pass: angular.equals(actual, expected)}; 
      } 
     }; 
     } 
    }); 
    }); 
相关问题