소스 검색

add some moment helpers for Jasmine testing

Adam Shaw 12 년 전
부모
커밋
a3119fc3d1
3개의 변경된 파일21개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 0
      karma.conf.js
  2. 5 5
      tests/automated/complex-headerDateClick.js
  3. 15 0
      tests/lib/jasmine-ext.js

+ 1 - 0
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',

+ 5 - 5
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();
 		});
 	});
 });

+ 15 - 0
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
+		}
+	});
+});