AngularJS : test uiDate directive 2
by sebmade
HTML
<script src="http://datejs.googlecode.com/files/date.js"></script>
CSS
</style>
<script src="http://code.angularjs.org/1.0.0rc10/angular-1.0.0rc10.js"></script>
<script src="http://cloud.github.com/downloads/digitalBush/jquery.maskedinput/jquery.maskedinput-1.3.js"></script>
<script src="https://raw.github.com/pivotal/jasmine/master/lib/jasmine-core/jasmine.js"></script>
<script src="https://raw.github.com/pivotal/jasmine/master/lib/jasmine-core/jasmine-html.js"></script>
<script src="http://code.angularjs.org/1.0.0rc10/angular-mocks-1.0.0rc10.js"></script>
<link rel="stylesheet" type="text/css" href="http://tryjasmine.com/js/vendor/jasmine-1.1.0/jasmine.css">
<style>
JavaScript
var myApp = angular.module('myApp', []);
myApp.directive('uiDate', function() {
return {
require: '?ngModel',
scope: {
uiDate: 'evaluate'
},
link: function($scope, element, attrs, controller) {
return element.mask("99/99/9999",{completed: function() {
controller.$setViewValue(Date.parse(this.val(),"dd/MM/yyyy"));
$scope.$apply();
}});
}
};
});
describe('uiDate', function() {
beforeEach(module("myApp"));
it('should be able to get the date from the model', function() {
return inject(function($compile, $rootScope) {
var aDate, element;
aDate = new Date(2012, 6, 10);
element = $compile("<input ui-date ng-model='x'></input>")($rootScope);
$rootScope.$apply(function() {
return $rootScope.x = aDate;
});
return expect(element.val()).toEqual(aDate.toString());
});
});
/* it('should put the date in the model', function() {
return inject(function($compile, $rootScope) {
var aDate, element;
aDate = new Date(2012, 12, 1);
element = $compile("<input ui-date ng-model='x'></input>")($rootScope);
element.text("01/12/201");
element.trigger(jQuery.Event("keydown.mask", { which: 50 }));
element.trigger(jQuery.Event("keypress.mask", { which: 50 }));
return expect($rootScope.x).toEqual(aDate);
});
});
*/
});
// KICK OFF JASMINE
var jasmineEnv = jasmine.getEnv();
var trivialReporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
};
jasmineEnv.execute();