title: Protractor - Returning pending promise when functioned out
body: <p>I am trying to create a function that will comb through an array of elements and return the first instance of one that meets the criteria.</p>
  
  <p>This is what I have inside my test that <strong>does work</strong>:</p>
  
  <pre><code>element.all(by.css('_cssSelector_')).filter(function(elms, index) {
          return elms.getAttribute('height').then(function(height) {
              return parseInt(height) &gt; 0;
          });
      }).then(function(validElms) {
           browser.actions().mouseMove(validElms[0]).perform();
      }
  </code></pre>
  
  <p>...but if I function this out, it <strong>does NOT work</strong>:</p>
  
  <pre><code>getValidElm = function() {
      var validElm = element.all(by.css('_cssSelector_')).filter(function (elms, index) {
          return elms.getAttribute('height').then(function (height) {
              return parseInt(height) &gt; 0;
          });
      }).then(function (validElms) {
          return validElms[0];
          });
  
      return validElm;
  }
  </code></pre>
  
  <p>If I then run:</p>
  
  <pre><code>var validElmFromPage = getValidElm();
  console.log(validElmFromPage);
  </code></pre>
  
  <p>I get: <strong>Promise::2046 {[[PromiseStatus]]: "pending"}</strong></p>
  
  <p>Which points to an issue of something inside the function not resolving before the var outside the function is being used. After reading (extensively) through posts here, and even this wonderful blog post (<a href="http://spin.atomicobject.com/2014/12/17/asynchronous-testing-protractor-angular/" rel="nofollow">http://spin.atomicobject.com/2014/12/17/asynchronous-testing-protractor-angular/</a>), I still can't figure out what the deal is. I know it's something simple, most likely controlFlow related?</p>
  
  <p>Thanks for your help.</p>