title: Unit Test - ag-grid API onFilterChanged of undefined in Angular 9
body: <p>I am writing the unit test case for Ag-grid in Angular where I have Angular Grid: External Filter which is toggling filter checkbox.
  I'm getting <strong>&quot;TypeError: Cannot read property 'onFilterChanged' of undefined&quot;</strong></p>
  <p>I'm testing this method:</p>
  <pre><code>toggleCheckboxMethod({ checked }): void {
      isChecked = checked;
      this.gridApi.onFilterChanged(); //when this method initiates it causes for test to fail
    }
  </code></pre>
  <pre><code> beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
        imports: [
          RouterTestingModule.withRoutes([]),
          HttpClientModule,
          HttpClientTestingModule,
          AgGridModule.withComponents([]),
          MatDialogModule,
          BrowserAnimationsModule
        ],
        declarations: [ TestComponent ],
        providers: []
  
      })
      .compileComponents();
    }));
  
  beforeEach(() =&gt; {
      fixture = TestBed.createComponent(TestComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
  });
  
    it('should toggle checkbox', () =&gt; {
      let isChecked = false;
      spyOn(component, 'toggleCheckboxMethod').and.callThrough();
      component.toggleCheckboxMethod({ checked: true });
      expect(component.toggleCheckboxMethod).toHaveBeenCalled();
      expect(isChecked).toEqual(true);
    });
  </code></pre>