From a3119fc3d174df58a273d56110412e068eb19731 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Sun, 2 Feb 2014 14:14:29 -0800 Subject: [PATCH] add some moment helpers for Jasmine testing --- karma.conf.js | 1 + tests/automated/complex-headerDateClick.js | 10 +++++----- tests/lib/jasmine-ext.js | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 tests/lib/jasmine-ext.js diff --git a/karma.conf.js b/karma.conf.js index 49e04c8..e72f0cc 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -16,6 +16,7 @@ module.exports = function(config) { { pattern: 'lib/jquery-simulate/jquery.simulate.js', watched: false }, { pattern: 'lib/jasmine-jquery/lib/jasmine-jquery.js', watched: false }, { pattern: 'lib/jasmine-fixture/dist/jasmine-fixture.js', watched: false }, + 'tests/lib/jasmine-ext.js', 'build/out/fullcalendar.js', 'build/out/fullcalendar.css', 'tests/base.css', diff --git a/tests/automated/complex-headerDateClick.js b/tests/automated/complex-headerDateClick.js index ae0a0f7..3f9f789 100644 --- a/tests/automated/complex-headerDateClick.js +++ b/tests/automated/complex-headerDateClick.js @@ -18,7 +18,7 @@ describe('when header options set with next|prev|prevYear|nextYear|today', funct $('#calendar').fullCalendar('gotoDate', '2010-02-01'); $('.fc-button-next').simulate('click'); var newDate = $('#calendar').fullCalendar('getDate'); - expect(newDate.format()).toEqual('2010-03-01'); + expect(newDate).toEqualMoment('2010-03-01'); }); }); @@ -27,7 +27,7 @@ describe('when header options set with next|prev|prevYear|nextYear|today', funct $('#calendar').fullCalendar('gotoDate', '2010-02-01'); $('.fc-button-prev').simulate('click'); var newDate = $('#calendar').fullCalendar('getDate'); - expect(newDate.format()).toEqual('2010-01-01'); + expect(newDate).toEqualMoment('2010-01-01'); }); }); @@ -36,7 +36,7 @@ describe('when header options set with next|prev|prevYear|nextYear|today', funct $('#calendar').fullCalendar('gotoDate', '2010-02-01'); $('.fc-button-prevYear').simulate('click'); var newDate = $('#calendar').fullCalendar('getDate'); - expect(newDate.format()).toEqual('2009-02-01'); + expect(newDate).toEqualMoment('2009-02-01'); }); }); @@ -45,7 +45,7 @@ describe('when header options set with next|prev|prevYear|nextYear|today', funct $('#calendar').fullCalendar('gotoDate', '2010-02-01'); $('.fc-button-nextYear').simulate('click'); var newDate = $('#calendar').fullCalendar('getDate'); - expect(newDate.format()).toEqual('2011-02-01'); + expect(newDate).toEqualMoment('2011-02-01'); }); }); @@ -54,7 +54,7 @@ describe('when header options set with next|prev|prevYear|nextYear|today', funct $('#calendar').fullCalendar('gotoDate', '2010-02-01'); $('.fc-button-today').simulate('click'); var newDate = $('#calendar').fullCalendar('getDate'); - expect(newDate.format()).toEqual(moment().format()); + expect(newDate).toEqualNow(); }); }); }); \ No newline at end of file diff --git a/tests/lib/jasmine-ext.js b/tests/lib/jasmine-ext.js new file mode 100644 index 0000000..3219e38 --- /dev/null +++ b/tests/lib/jasmine-ext.js @@ -0,0 +1,15 @@ + +beforeEach(function() { + this.addMatchers({ + toEqualMoment: function(expected) { + return $.fullCalendar.moment(this.actual).format() === + $.fullCalendar.moment(expected).format(); + }, + toEqualNow: function() { + return Math.abs( + $.fullCalendar.moment(this.actual) - + new Date() + ) < 1000; // within a second of current datetime + } + }); +}); \ No newline at end of file