title: Testing Angular Filter That Returns An Array with Jasmine
body: <p>So, I'm having issues testing an angular filter that takes an array that has previously been sorted by a group property. It uses a flag property to indicate that the item is the first observation of that group, and then false for subsequent observations. </p>
  
  <p>I'm doing this to have a category header in the UI with an ng-repeat directive. </p>
  
  <p>When I test the filter, the output does not return the array with the flags unless I create new objects for the return array. This is a problem, because it causes an infinite loop when running in a webpage. The code works in the webpage when it just adds a flag property to the input object.</p>
  
  <p>Is there some additional step I should be taking to simulate how angular handles filters so that it outputs the proper array?</p>
  
  <p>This is what my test looks like right now.</p>
  
  <pre><code>describe('IsDifferentGroup', function() {
     var list, itemOne, itemTwo, itemThree;
  
     beforeEach(module("App.Filters"));
  
     beforeEach(function () {
      list = [];
  
      itemOne = new ListItem();
      itemTwo = new ListItem();
      itemThree = new ListItem();
      itemOne.group = "A";
      itemTwo.group = "B";
      itemThree.group = "C";
  
      list.push(itemOne);
      list.push(itemOne);
      list.push(itemOne);
      list.push(itemOne);
      list.push(itemTwo);
      list.push(itemThree);
      list.push(itemThree);
      list.push(itemThree);
      list.push(itemThree);
      list.push(itemThree);
  });
  
  it('should flag the items true that appear first on the list.', (inject(function (isDifferentGroupFilter) {
      expect(list.length).toBe(10);
  
      var result = isDifferentGroupFilter(list);
  
      expect(result[0].isDifferentGroup).toBeTruthy();
      expect(result[1].isDifferentGroup).toBeFalsy();
      expect(result[4].isDifferentGroup).toBeTruthy();
      expect(result[5].isDifferentGroup).toBeTruthy();
      expect(result[6].isDifferentGroup).toBeFalsy();
      expect(result[9].isDifferentGroup).toBeFalsy();
  
  })));
  
  });
  </code></pre>
  
  <p>And here is something like the code with the filter:</p>
  
  <pre><code>var IsDifferentGroup = (function () {
  function IsDifferentGroup() {
      return (function (list) {
          var arrayToReturn = [];
          var lastGroup = null;
  
          for (var i = 0; i &lt; list.length; i++) {
              if (list[i].group != lastGroup) {
                  list[i].isDifferentGroup = true;
                  lastAisle = list[i].group;
              } else {
                  list[i].isDifferentGroup = false;
              }
              arrayToReturn.push(list[i]);
          }
  
          return arrayToReturn;
      });
  }
  return IsDifferentGroup;
  })();
  </code></pre>
  
  <p>Thanks!</p>