add some moment helpers for Jasmine testing

This commit is contained in:
Adam Shaw
2014-02-02 14:14:29 -08:00
parent 1f5b6490a3
commit a3119fc3d1
3 changed files with 21 additions and 5 deletions
+1
View File
@@ -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',
+5 -5
View File
@@ -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();
});
});
});
+15
View File
@@ -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
}
});
});