-
-
Save bbraithwaite/5feb72963a83f2566d49 to your computer and use it in GitHub Desktop.
This file contains 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
<html> | |
<head> | |
<title>TzDate Examples</title> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine-html.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/boot.min.js"></script> | |
<script type="text/javascript" src="https://code.angularjs.org/1.4.0-rc.2/angular.js"></script> | |
<script type="text/javascript" src="https://code.angularjs.org/1.4.0-rc.2/angular-mocks.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
var app = angular.module('countdownApp', []); | |
app.controller('CountdownController', function countdownController($scope) { | |
if ($scope.nowTime.getFullYear() === $scope.nextYear) { | |
$scope.message = 'Happy new Year!'; | |
} else { | |
$scope.message = 'Keep on counting down...!'; | |
} | |
}); | |
describe('countdown tests', function () { | |
beforeEach(module('countdownApp')); | |
var $controller; | |
var $scope; | |
var $rootScope; | |
beforeEach(inject(function(_$controller_, _$rootScope_) { | |
$controller = _$controller_; | |
$rootScope = _$rootScope_; | |
$scope = _$rootScope_.$new(); | |
})); | |
it('should display happy new year messsage', function () { | |
$scope.nowTime = new angular.mock.TzDate(0, '2015-01-01T00:00:00Z'); | |
$scope.nextYear = 2015; | |
var countdownController = $controller('CountdownController', { $scope: $scope }); | |
expect($scope.message).toBe('Happy new Year!'); | |
}); | |
it('should display almost new year message', function () { | |
$scope.nowTime = new angular.mock.TzDate(+1, '2014-12-31T23:00:00Z'); | |
$scope.nextYear = 2015; | |
var countdownController = $controller('CountdownController', { $scope: $scope }); | |
expect($scope.message).toBe('Keep on counting down...!'); | |
}); | |
it('should increment the time by the given hours', function () { | |
var addHours = function(d, h) { | |
d.setTime(d.getTime() + (h*60*60*1000)); | |
} | |
var base = new angular.mock.TzDate(+1, '2014-12-31T23:00:00Z'); | |
spyOn(base, 'setTime'); | |
addHours(base, 1); | |
expect(base.setTime).toHaveBeenCalledWith(1420070400000); | |
}); | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment