title: Uncaught TypeError: Cannot read property 'coSearchCriteria' of undefined thrown - Angular Karma/Jasmine
body: <p>I have tried to test Angular component by using Karma/Jasmine. To be frank I don't have much idea about karma/jasmine and while testing getting error like "Uncaught TypeError: Cannot read property 'coSearchCriteria' of undefined thrown". But normal component functionality is working fine. If any idea please help me.</p>
  
  <p>This is my Testing code, Here basic 'should create' test case is working but 2nd one giving error. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>describe('SearchPanelComponent', () =&gt; {
    let component: SearchPanelComponent;
    let fixture: ComponentFixture&lt;SearchPanelComponent&gt;;
    
  
    beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
        imports: [ReactiveFormsModule, FormsModule, HttpModule, CarbonDatepickerModule, CarbonModalModule,CarbonIconModule, StoreModule.forRoot({})],
        declarations: [ SearchPanelComponent, UploadsearchcriteriaComponent ],
        providers: [ Store, StoreModule, CustomerorderService,ConnectionBackend, ApiConnectorService, HttpClient, HttpHandler,Http, CarbonModalService]    })
      .compileComponents();
    }));
  
    beforeEach(() =&gt; {
      fixture = TestBed.createComponent(SearchPanelComponent);
      component = fixture.componentInstance;
      fixture.detectChanges();
    });
  
    it('should create', () =&gt; {
      expect(component).toBeTruthy();
    });
  
  it('RSSD To should be invalid', async( () =&gt; {
    const dateValue = component.orderUnitForm.controls['rssddateto'];
    dateValue.setValue('12-02/2012');
    fixture.detectChanges();
    expect(component.orderUnitForm.valid).toEqual(false);
  }));</code></pre>
  </div>
  </div>
  </p>
  
  <p>And 'coSearchCriteria' I have used at .ts file only like this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>this.store.select(selectorCOCriteriaState)
      .subscribe((coSearchCriteria: SearchCriteriaState) =&gt; {   
         this.searchState = coSearchCriteria.lastUsedCriteria;     
      });   
      if(this.searchState){
          this.fillSearchStateData();  
      }</code></pre>
  </div>
  </div>
  </p>