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

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.