2

I'm unit testing my directive and doing it like this:

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');
  })

This works, but I can't figure out how to get the value of the validity of model.birthDate, and I would like to know if my setting of element.val is the right way f doing this

Maarten
  • 4,643
  • 7
  • 37
  • 51
  • 1
    This might be useful: http://stackoverflow.com/questions/15219717/to-test-a-custom-validation-angular-directive – Bill Odom Jun 28 '13 at 07:44

0 Answers0