title: karma Test : TypeError: Cannot read property 'map' of undefined
body: <p>I'm trying to test a ReactiveFormsControle with a separate formControle file dependency that contain the control form function. I need to use an observable to pass the form controls and returning messages errors after that. But when I tried to test that I have this error: <strong>TypeError: Cannot read property 'map' of undefined</strong></p>
  
  <p>Can any one help me please.</p>
  
  <p>this is my code : </p>
  
  <p><strong><em>This is how can I call the Form control function(process Message) :</em></strong></p>
  
  <pre><code>ngAfterViewInit(): void {
  // Watch for the blur event from any input element on the form.
  let controlBlurs: Observable&lt;any&gt;[] = this.formInputElements
    .map((formControl: ElementRef) =&gt; Observable.fromEvent(formControl.nativeElement, 'blur'));
  // Merge the blur event observable with the valueChanges observable
  Observable.merge(this.signUpForm.valueChanges, ...controlBlurs).debounceTime(1000).subscribe(value =&gt; {
    this.displayeErrorMessage = this.formValidator.processMessages(this.signUpForm);
  });
  </code></pre>
  
  <p>}</p>
  
  <p><strong><em>processMessage function:</em></strong></p>
  
  <pre><code>  processMessages(container : FormGroup) : {[key : string]: string}{
  
  let messages = {};
  
  for(let controlKey in container.controls){
    if(container.controls.hasOwnProperty(controlKey)){
      let c = container.controls[controlKey];
  
      if(c instanceof FormGroup){
        let childMessages = this.processMessages(c);
        Object.assign(messages, childMessages);
      }else {
  
        if(this.validationErrorMessages[controlKey]){
          messages[controlKey]='';
          if((c.dirty || c.touched) &amp;&amp; c.errors){
            Object.keys(c.errors).map(messageKey =&gt;{
              if(this.validationErrorMessages[controlKey][messageKey]){
                messages[controlKey] += this.validationErrorMessages[controlKey][messageKey] + ' '
              }
            })
          }
        }
      }
    }
  }
  return messages;
  </code></pre>
  
  <p>}</p>
  
  <p><strong>* this the test code that handle the error *</strong></p>
  
  <pre><code> beforeEach(() =&gt; {
  fixture = TestBed.createComponent(SignUpComponent);
  component = fixture.componentInstance;
  debugHelpblck = fixture.debugElement.queryAll(By.css('.help-block'));
  component.ngOnInit();
  component.ngAfterViewInit(); // this handle the error
  fixture.detectChanges();
  </code></pre>
  
  <p>});</p>