Skip to content

Instantly share code, notes, and snippets.

@szmeku
Created August 7, 2014 14:19
Show Gist options
  • Save szmeku/9c84a54aad4fe54d90eb to your computer and use it in GitHub Desktop.
Save szmeku/9c84a54aad4fe54d90eb to your computer and use it in GitHub Desktop.
'use strict';
describe('Date Utils', function () {
var DateUtils;
beforeEach(module('providersApp'));
beforeEach(inject(function (_DateUtils_) {
DateUtils = _DateUtils_;
}));
it('should count days between two dates', function () {
var argsAndResults = [
[new Date(2014, 7, 2, 14, 20), new Date(2014, 7, 2, 14, 20), 1],
[new Date(2014, 7, 2, 14, 20), new Date(2014, 7, 2, 12, 20), 1],
[new Date(2014, 7, 2, 23, 59), new Date(2014, 7, 3, 0, 1), 2],
[new Date(2014, 7, 2, 20), new Date(2014, 7, 3, 23), 2]
];
angular.forEach(argsAndResults, function (argsAndResult) {
expect(DateUtils.countDaysBetween(argsAndResult[0], argsAndResult[1])).toBe(argsAndResult[2]);
});
});
it('should throw exception when counting days between non-dates', function () {
var argsAndResults = [
[1391778600000, new Date(), new Error("DateUtils->countDaysBetween() Both arguments should be dates")],
[new Date(), 1391778600000, new Error("DateUtils->countDaysBetween() Both arguments should be dates")],
[1391778600000, 1391778600000, new Error("DateUtils->countDaysBetween() Both arguments should be dates")]
];
angular.forEach(argsAndResults, function (argsAndResult) {
expect(function(){
DateUtils.countDaysBetween(argsAndResults[0], argsAndResults[1])
}).toThrow(argsAndResult[2]);
});
});
it('should convert number to date', function(){
expect(angular.isDate(DateUtils.numberToDate(1407416769343))).toBe(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment