AngularJS + Jasmine: Comparing objects

前端 未结 6 1644
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 03:18

I\'m just starting out writing tests for my AngularJS app and am doing so in Jasmine.

Here are the relevant code snippets

ClientController:

\         


        
6条回答
  •  天涯浪人
    2020-12-15 03:50

    Long story short: add angular.equals as a jasmine matcher.

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

    So, then you can use it as follows:

    it('should preselect first client in array', function() {
        //this passes:
        expect(scope.selected.client).toEqualData(RESPONSE[0]);
    
        //this fails:
        expect(scope.selected.client).toEqual(RESPONSE[0]);
    });
    

提交回复
热议问题