我正在对我的指令进行单元测试并按照以下方式进行测试:
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设置是否是正确的方法。