title: Javascript self invoking function issue (Behat/Mink/Sahi)
body: <p>I'm currently at a loss to why this is occurring, but I wouldn't be surprised if I was either way off, or missing one tiny little thing.</p>
  
  <p><strong>Here's my code:</strong></p>
  
  <pre><code>(function() { 
      if (jQuery('section.news-feed ul li').text().length &gt; 0) {
          var length1 = parseInt(jQuery('section.news-feed ul li').text().length); 
          var length2 = 0; 
  
          setTimeout(function() {
              length2 = parseInt(jQuery('section.news-feed ul li').text().length); 
  
              if (length1 !== length2) {
                  return true;
              } 
              else {
                  return false;
              }
  
          }, 3000);
      }
      else {
          return false;
      }
  })()
  </code></pre>
  
  <p><strong>I'm looking for a boolean return, although, I'm receiving 'undefined'.</strong> The jQuery specific selectors are correct and I find length1 and length2 correctly.</p>
  
  <p>To further add to the question encase there's someone with Behat/Mink/Sahi experience, this is what I'm looking to do:</p>
  
  <p><strong>Behat:</strong></p>
  
  <pre><code>@javascript
      Scenario: News ticker is moving
      Given I am on the homepage
      Then I should see the news ticker "section.news-feed ul li" move
  </code></pre>
  
  <p><strong>Context:</strong></p>
  
  <pre><code>/**
   * @Then /^I should see the news ticker "([^"]*)" move$/
   */
  public function iShouldSeeTheNewsTickerMove($element) {
      $result = $this
                  -&gt;getSession()
                  -&gt;evaluateScript("
                      (function() { 
                          if (jQuery('" . $element . "').text().length &gt; 0) {
                              var length1 = parseInt(jQuery('" . $element . "').text().length); 
                              var length2; 
  
                              setTimeout(function() {
                                  var length2 = parseInt(jQuery('" . $element . "').text().length); 
  
                                  if (length1 !== length2) {
                                      return true;
                                  } 
                                  else {
                                      return false;
                                  }
  
                              }, 3000);
                          }
                          else {
                              return false;
                          } 
                      })()
                  ");
  
      echo "Result: " . $result;
  
      if ($result === 'false') {
          throw new Exception (
              "The newws ticker doesn't seem to be ticking."
          );
      }
  
  }
  </code></pre>