Created
October 18, 2013 14:17
-
-
Save ojacquemart/7042210 to your computer and use it in GitHub Desktop.
Unit test to test afterDate directive from http://frangular.com/2013/10/validateur-date-posterieure.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
describe('Directive: afterDate', function () { | |
beforeEach(module('yoApp')); | |
var scope, | |
compile, | |
element | |
; | |
beforeEach(inject(function ($rootScope, $compile) { | |
scope = $rootScope; | |
compile = $compile; | |
element = angular.element( | |
'<div>' + | |
'<form name="simple-form">' + | |
'<input name="fromDate" ng-model="data.fromDate" />' + | |
'<input name="todate" ng-model="data.toDate" date-after="data.fromDate" />' + | |
'</form>' + | |
'</div>'); | |
})); | |
var setDates = function(from, to) { | |
scope.data = { "fromDate": from, "toDate": to }; | |
compileAndDigest(); | |
} | |
var compileAndDigest = function() { | |
compile(element)(scope); | |
scope.$digest(); | |
} | |
it('should get valid form when toDate is after fromDate', function () { | |
setDates("2010-10-10", "2010-10-11"); | |
expect(element.find('form').hasClass("ng-valid")).toBe(true); | |
}); | |
it('should get valid form when toDate is equal to fromDate', function () { | |
setDates("2010-10-10", "2010-10-10"); | |
expect(element.find('form').hasClass("ng-valid")).toBe(true); | |
}); | |
it('should get unvalid form when toDate is before fromDate', function () { | |
setDates("2010-10-10", "2010-10-09"); | |
expect(element.find('form').hasClass("ng-valid")).toBe(false); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bonjour,
J'ai réussi à faire marcher en local la directivbe de frangular, et à la lecture de ce que vous avez mis là en place, je crois deviner que ce script va tester différentes entrées posssibles...
Mais concrètement, comment exécuter ce code ?