summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorPaul Gascou-Vaillancourt <pgascouvaillancourt@gitlab.com>2019-05-28 07:53:44 +0000
committerPhil Hughes <me@iamphill.com>2019-05-28 07:53:44 +0000
commitdade5a44ec1ea8164c4363ba86f1806c70cd3642 (patch)
tree5536b7bda8038ef56af9d91ab4f1b455850a94f0 /spec
parentff7766b954984f448428cc153351db55029ccc8a (diff)
downloadgitlab-ce-dade5a44ec1ea8164c4363ba86f1806c70cd3642.tar.gz
Throw an error when formatDate's input is invalid
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/lib/utils/datetime_utility_spec.js (renamed from spec/javascripts/lib/utils/datetime_utility_spec.js)22
1 files changed, 21 insertions, 1 deletions
diff --git a/spec/javascripts/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js
index 5327ec9d2a0..9f49e68cfe8 100644
--- a/spec/javascripts/lib/utils/datetime_utility_spec.js
+++ b/spec/frontend/lib/utils/datetime_utility_spec.js
@@ -65,6 +65,26 @@ describe('Date time utils', () => {
});
});
+ describe('formatDate', () => {
+ it('should format date properly', () => {
+ const formattedDate = datetimeUtility.formatDate(new Date('07/23/2016'));
+
+ expect(formattedDate).toBe('Jul 23, 2016 12:00am GMT+0000');
+ });
+
+ it('should format ISO date properly', () => {
+ const formattedDate = datetimeUtility.formatDate('2016-07-23T00:00:00.559Z');
+
+ expect(formattedDate).toBe('Jul 23, 2016 12:00am GMT+0000');
+ });
+
+ it('should throw an error if date is invalid', () => {
+ expect(() => {
+ datetimeUtility.formatDate('2016-07-23 00:00:00 UTC');
+ }).toThrow(new Error('Invalid date'));
+ });
+ });
+
describe('get day difference', () => {
it('should return 7', () => {
const firstDay = new Date('07/01/2016');
@@ -380,7 +400,7 @@ describe('prettyTime methods', () => {
describe('calculateRemainingMilliseconds', () => {
beforeEach(() => {
- spyOn(Date, 'now').and.callFake(() => new Date('2063-04-04T00:42:00Z').getTime());
+ jest.spyOn(Date, 'now').mockImplementation(() => new Date('2063-04-04T00:42:00Z').getTime());
});
it('calculates the remaining time for a given end date', () => {