describe('Magellan', function() {
	var plugin;
	var $html, $content; 	

  var generateUl = function(count) {
  	var html = '';
  	html += '<ul class="vertical-menu">';
  	for (var c = 0; c < count; c++) {
  		html += '<li><a href="#target-' + c + '">Section ' + c + '</a></li>';
  	}
  	html += '</ul>';
  	return html;
  };
  var generateContent = function(count) {
  	var html = '';
  	html += '<div>';
  	for (var c = 0; c < count; c++) {
  		html += '<div id="target-' + c + '" style="height: 1000px";>Section ' + c + '</div>';
  	}
  	html += '</div>';
  	return html;
  };

  afterEach(function() {
    plugin.destroy();
    $html.remove();
    $content.remove();
  });

	// afterEach(function() {
	// 	plugin.destroy();
	// 	$html.remove();
	// });

	describe('constructor()', function() {
		// it('', function() {
		// 	$html = $('').appendTo('body');
		// 	plugin = new Foundation.Magellan($html, {});

		// 	plugin.$element.should.be.an('object');
		// 	plugin.options.should.be.an('object');
		// });
	});


	describe('scrollToLoc()', function() {
    it('scrolls the selected element into viewport', function(done) {
    	var count = 5, duration = 200;
      $html = $(generateUl(count)).appendTo('body');
      $content = $(generateContent(count)).appendTo('body');
      plugin = new Foundation.Magellan($html, {
      	animationDuration: duration
      });



      // Jump to last section
      var target = $html.find('a').eq(-1).attr('href');
      $html.one('load', function(){
        plugin.scrollToLoc(target);
			});

      // The `update` event doesn't work properly because it fires too often
      setTimeout(function() {
      	var isInViewport = false;
      	if ($content.find('div').eq(-1).offset().top > $('body').scrollTop() && $content.offset().top < $('body').scrollTop() + $('body').innerHeight()) {
      		isInViewport = true;
      	}
      	isInViewport.should.equal(true);
      	done();
      }, duration);

    });


    it('fails gracefully when target does not exist', function() {
    	var count = 5, duration = 200;
      $html = $(generateUl(count)).appendTo('body');
      $content = $(generateContent(count - 1)).appendTo('body');
      plugin = new Foundation.Magellan($html, {
      	animationDuration: duration
      });

      var hasError = false;
      try {
				var target = $html.find('a').eq(-1).attr('href');
        $html.one('load', function(){
          plugin.scrollToLoc(target);
        });
      } catch (err) {
      	hasError = true;
      }
      hasError.should.equal(false);
      
    });

  });

});
@@ -1366,18 +1366,16 @@
    %7D);%0A%0A
-%0A%0A
       //
@@ -1456,46 +1456,8 @@
 ');%0A
-      $html.one('load', function()%7B%0A  
     
@@ -1490,16 +1490,8 @@
 t);%0A
-%09%09%09%7D);%0A%0A
     
@@ -1595,25 +1595,26 @@
 n() %7B%0A      
-%09
+  
 var isInView
@@ -1633,17 +1633,18 @@
 ;%0A      
-%09
+  
 if ($con
@@ -1788,18 +1788,20 @@
 %7B%0A      
-%09%09
+    
 isInView
@@ -1823,17 +1823,18 @@
     
+  
-%09
 %7D%0A      
 %09isI
@@ -1829,17 +1829,18 @@
 %7D%0A      
-%09
+  
 isInView
@@ -1870,17 +1870,18 @@
 ;%0A      
-%09
+  
 done();%0A
@@ -1966,32 +1966,36 @@
 xist', function(
+done
 ) %7B%0A    %09var cou
@@ -2268,18 +2268,8 @@
     
-try %7B%0A%09%09%09%09
 var 
@@ -2266,32 +2266,33 @@
       var target
+s
  = $html.find('a
@@ -2297,137 +2297,188 @@
 'a')
-.eq(-1).attr('href');%0A        $html.one('load', function()%7B%0A          plugin.scrollToLoc(target);%0A        %7D);%0A      %7D catch (err)
+;%0A      if(targets.length)%7B%0A        var target = $(targets).eq(-1).attr('href');%0A        plugin.scrollToLoc(target);%0A        hasError.should.equal(false);%0A        done();%0A%09%09%09%7D else
  %7B%0A 
@@ -2482,17 +2482,18 @@
 %7B%0A      
-%09
+  
 hasError
@@ -2503,22 +2503,16 @@
 true;%0A  
-    %7D%0A
       ha
@@ -2535,24 +2535,45 @@
 ual(false);%0A
+        done();%0A%09%09%09%7D%0A
       %0A    %7D

make sure that the Magellan tests are properly running