Procházet zdrojové kódy

adjust to destroy actions sometimes being async if already within the destroy flow

Adam Shaw před 9 roky
rodič
revize
506d117400
2 změnil soubory, kde provedl 38 přidání a 27 odebrání
  1. 18 11
      tests/automated/destroy.js
  2. 20 16
      tests/automated/removeEvents.js

+ 18 - 11
tests/automated/destroy.js

@@ -42,24 +42,26 @@ describe('destroy', function() {
 			});
 
 			it('leaves no handlers attached to DOM', function(done) {
-				var origDocCnt = countHandlers(document);
-				var origElCnt = countHandlers('#cal');
+				setTimeout(function() { // in case there are delayed attached handlers
 
-				$('#cal').fullCalendar(options);
+					var origDocCnt = countHandlers(document);
+					var origElCnt = countHandlers('#cal');
 
-				setTimeout(function() { // in case there are delayed attached handlers
+					$('#cal').fullCalendar(options);
 
 					$('#cal').fullCalendar('destroy');
+					setTimeout(function() { // might not have detached handlers synchronously
 
-					expect(countHandlers(document)).toBe(origDocCnt);
-					expect(countHandlers('#cal')).toBe(origElCnt);
+						expect(countHandlers(document)).toBe(origDocCnt);
+						expect(countHandlers('#cal')).toBe(origElCnt);
 
-					done();
-				}, 0);
+						done();
+					}, 100);
+				}, 100);
 			});
 
 			// Issue 2432
-			it('preserves existing window handlers when handleWindowResize is off', function() {
+			it('preserves existing window handlers when handleWindowResize is off', function(done) {
 				var resizeHandler = function() { };
 				var handlerCnt0 = countHandlers(window);
 				var handlerCnt1;
@@ -74,8 +76,13 @@ describe('destroy', function() {
 				});
 
 				$('#cal').fullCalendar('destroy');
-				handlerCnt2 = countHandlers(window);
-				expect(handlerCnt2).toBe(handlerCnt1);
+				setTimeout(function() { // might not have detached handlers synchronously
+
+					handlerCnt2 = countHandlers(window);
+					expect(handlerCnt2).toBe(handlerCnt1);
+
+					done();
+				}, 100);
 			});
 		});
 	});

+ 20 - 16
tests/automated/removeEvents.js

@@ -117,23 +117,27 @@ describe('removeEvents', function() {
 				called = true;
 
 				checkAllEvents(); // make sure all events initially rendered correctly
+
 				removeFunc(); // remove the events
-				checkFunc(); // check correctness
-
-				// move the calendar back out of view, then back in
-				$('#cal').fullCalendar('next');
-				$('#cal').fullCalendar('prev');
-
-				// array event sources should maintain the same state
-				// whereas "dynamic" event sources should refetch and reset the state
-				if ($.isArray(events)) {
-					checkFunc(); // for issue 2187
-				}
-				else {
-					checkAllEvents();
-				}
-
-				doneFunc();
+				setTimeout(function() { // because the event rerender will be queued because we're a level deep
+
+					checkFunc(); // check correctness
+
+					// move the calendar back out of view, then back in
+					$('#cal').fullCalendar('next');
+					$('#cal').fullCalendar('prev');
+
+					// array event sources should maintain the same state
+					// whereas "dynamic" event sources should refetch and reset the state
+					if ($.isArray(events)) {
+						checkFunc(); // for issue 2187
+					}
+					else {
+						checkAllEvents();
+					}
+
+					doneFunc();
+				}, 0);
 			}
 		};
 		$('#cal').fullCalendar(options);