title: How to expect dynamic count of elements in e2e tests using Protractor
body: <p>I'm currently writing some e2e tests for my humble Angular app with Protractor.</p>
  
  <p>My app works fine, unit tests passes all, e2e used too... until this one:</p>
  
  <p><strong>appE2ESpec.js</strong></p>
  
  <pre><code>describe('adding an item', function() {
    var items,
        addItemButton,
        startCount;
  
    beforeEach(function() {
      items = element.all(by.css('li.item'));
      addItemButton = element(by.id('addItemButton'));
      startCount = items.count();
    });
  
    it('should display a new item in list', function() {
      addItemButton.click();
  
      expect(items.count()).toEqual(startCount+1);
    });
  });
  </code></pre>
  
  <p>This is how I would have written my test but, </p>
  
  <p><strong>The problem is:</strong> that items.count() returns a promise, <em>I know that</em>, but I can't manage to force Protractor to resolve it. So I get this:</p>
  
  <pre><code>Failures:
  
  1) myApp adding an item should display a new item in list
    Message:
      Expected 6 to equal '[object Object]1'.
  </code></pre>
  
  <p><strong>What I've tried:</strong></p>
  
  <pre><code>items.count().then(function(count) {
    startCount = count;
    //console.log(startCount) --&gt; "6" Perfect!
  });
  </code></pre>
  
  <p>But got the same result at the end... I can't put the <code>expect</code> into the <code>then</code>, I thought about that too.</p>
  
  <ul>
  <li>I searched into Protractor GitHub repository issues, StackOverflow and Google AngularJs group.</li>
  </ul>
  
  <p><strong>Appendix:</strong></p>
  
  <p><code>console.log(startCount)</code> outputs this : </p>
  
  <pre><code>{ then: [Function: then],
    cancel: [Function: cancel],
    isPending: [Function: isPending] }
  </code></pre>
  
  <p>I could have written <code>.toEqual(6)</code> but I don't want to rewrite my test each time I need to change my app startup state.</p>
  
  <p>Any idea? Thanks in advance!!</p>