title: Custom filter pipe failing Karma/Jasmine test
body: <p>I have a custom filter pipe that works perfectly fine for filtering data in my table, however when I run tests on this pipe, the tests all fail. I get the error "TypeError: Cannot read property 'file' of null." File is the data property I pass in as parameter in transform. How do get this pipe to pass my test? </p>
  
  <p>table.component.spec</p>
  
  <pre class="lang-js prettyprint-override"><code>import { async, ComponentFixture, TestBed } from "@angular/core/testing";
  import { FormsModule } from "@angular/forms";
  import { FiltersPipe } from "./filter.pipe";
  
  import { DataTableComponent } from "./data-table.component";
  
  describe("DataTableComponent", () =&gt; {
    let component: DataTableComponent;
    let fixture: ComponentFixture&lt;DataTableComponent&gt;;
    let filter: FiltersPipe;
  
    beforeEach(
      async(() =&gt; {
        TestBed.configureTestingModule({
          imports: [FormsModule],
          declarations: [DataTableComponent, FiltersPipe]
        }).compileComponents();
  
        filter = new FiltersPipe();
      })
    );
  
    beforeEach(() =&gt; {
      fixture = TestBed.createComponent(DataTableComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
  
    it("should create", () =&gt; {
      expect(component).toBeTruthy();
    });
  
    it("filter pipe should be instanciated", () =&gt; {
      expect(FiltersPipe).toBeDefined();
    });
  
    it("filter pipe should return items if no field is given", () =&gt; {
      let items = [];
      items.push({ id: 1, file: "xxxx.zip" });
  
      let filtered = filter.transform(items, null, "file");
      expect(filtered).toEqual(items);
    });
  
    it("filter pipe should filter", () =&gt; {
      let items = [];
  
      items.push({ id: 1, file: "xxxx.zip" });
      items.push({ id: 2, file: "xxxx.zip" });
      items.push({ id: 2, file: "xxxx.zip" });
      items.push({ id: 3, file: "xxxx.zip" });
  
      let filtered = filter.transform(items, 2, "id");
  
      expect(filtered.length).toBe(2);
    });
  });
  </code></pre>
  
  <p>filter.pipe.ts</p>
  
  <pre class="lang-js prettyprint-override"><code>import { Pipe, PipeTransform } from "@angular/core";
  
  @Pipe({
    name: "filters",
    pure: false
  })
  export class FiltersPipe implements PipeTransform {
    transform(data: any, fields: any, selectedInput: any): any {
      if (!data) return;
  
      return data.filter(row =&gt; {
        if (
          row[selectedInput] !== null &amp;&amp;
          row[selectedInput] &amp;&amp;
          fields[selectedInput]
        ) {
          return row[selectedInput]
            .toString()
            .toLowerCase()
            .includes(fields[selectedInput].toString().toLowerCase());
        }
        return true;
      });
  
    }
  }
  </code></pre>