J.Olufsen
J.Olufsen

Reputation: 13915

How to rewrite Jasmine 2.0 custom matcher to use with Angular 1.5?

AngularJS tutorial has custom matcher that is not working in Jasmine starting from version 2.0:

beforeEach(function(){
    this.addMatchers({
      toEqualData: function(expected) {
        return angular.equals(this.actual, expected);
      }
    });
  });

The attempt to modify matcher fails with error:

TypeError: undefined is not an object (evaluating 'matcherCompare.apply')

My matcher definition:

beforeEach(function(){
    jasmine.addMatchers({
      toEqualData: function(util, customEqualityTesters, actual, expected) {
        return angular.equals(actual, expected);
      }
    });
  });

Jasmine 2.0 custom matcher docs.

How to make it work?

Upvotes: 0

Views: 161

Answers (1)

J.Olufsen
J.Olufsen

Reputation: 13915

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

Upvotes: 1

Related Questions