Преглед изворни кода

automated tests to ensure passed-in options object is not modified

Adam Shaw пре 11 година
родитељ
комит
edfdaf0428
2 измењених фајлова са 49 додато и 0 уклоњено
  1. 1 0
      src/EventManager.js
  2. 48 0
      tests/automated/constructor.js

+ 1 - 0
src/EventManager.js

@@ -45,6 +45,7 @@ function EventManager(options) { // assumed to be a calendar
 
 
 	var _sources = options.eventSources || [];
+	// TODO: don't mutate eventSources (see issue 954 and automated tests for constructor.js)
 
 	if (options.events) {
 		_sources.push(options.events);

+ 48 - 0
tests/automated/constructor.js

@@ -10,6 +10,54 @@ describe('constructor', function() {
 		expect(res instanceof jQuery).toBe(true);
 	});
 
+	it('should not modify the options object', function() {
+		var options = {
+			defaultView: 'agendaWeek',
+			scrollTime: '09:00:00',
+			slotDuration: { minutes: 45 }
+		};
+		var optionsCopy = $.extend({}, options, true);
+		$('#calendar').fullCalendar(options);
+		expect(options).toEqual(optionsCopy);
+	});
+
+	it('should not modify the events array', function() {
+		var options = {
+			defaultView: 'month',
+			defaultDate: '2014-05-27',
+			events: [
+				{
+					title: 'mytitle',
+					start: '2014-05-27'
+				}
+			]
+		};
+		var optionsCopy = $.extend(true, {}, options); // recursive copy
+		$('#calendar').fullCalendar(options);
+		expect(options).toEqual(optionsCopy);
+	});
+
+	/*
+	TODO: implement this behavior
+	it('should not modify the eventSources array', function() {
+		var options = {
+			defaultView: 'month',
+			defaultDate: '2014-05-27',
+			eventSources: [
+				{ events: [
+					{
+						title: 'mytitle',
+						start: '2014-05-27'
+					}
+				] }
+			]
+		};
+		var optionsCopy = $.extend(true, {}, options); // recursive copy
+		$('#calendar').fullCalendar(options);
+		expect(options).toEqual(optionsCopy);
+	});
+	*/
+
 	describe('when called on a div', function() {
 
 		beforeEach(function() {