2

我正在对我的指令进行单元测试并这样做:

describe("myDate", function() {
  var $compile, $rootScope;
  var validDate, invalidDate, invalidDateFormat, element;

  beforeEach(angular.mock.module('main'));

  beforeEach(inject(
      ['$compile','$rootScope', function(_$compile_,_$rootScope_) {
          $rootScope = _$rootScope_;
          $compile = _$compile_;
          elm = angular.element('<input name="birthDate" data-ng-model="model.birthDate" data-my-date placeholder="dd-mm-jjjj" type="text" maxlength="10" size="25" tabindex="3">');
          element = $compile(elm)($rootScope);
      }]
  ));

  it("should set the validity state to valid and the view value on blur if the value is correct", function() {
      expect($rootScope.model).toBeUndefined();
      element.val('20-05-1976');
      element.blur();
      expect($rootScope.model.birthDate).toBe('20-05-1976');
  })

这行得通,但我不知道如何获得model.birthDate的有效性值,我想知道我的element.val设置是否是这样做的正确方法

4

0 回答 0