title: Angular2 Unit Tests - Test Subject ( watch on variable from service)
body: <p>I have a watch in one of my components which watches a variable in a service (so a Subject). (I got the implementation idea of this here: <a href="https://stackoverflow.com/questions/34714462/updating-variable-changes-in-components-from-a-service-with-angular2">updating variable changes in components from a service with angular2.</a>  However, now my whole tests in the component are failing because I need to mock this somehow but I don't know how and I could not find any answer to that. That's my code:</p>
  
  <p><strong>Component where I watch the change of the variable in the constructor:</strong></p>
  
  <pre><code>  constructor(private updateService: UpdateService) {
  
      // check if intents are updated in the updateService through upload component, if yes update training status
      this.intentsSubscription = updateService.intentsChange.subscribe((value) =&gt; this.initTrainingStatus());
    }
  </code></pre>
  
  <p><strong>Service where the Variable-Change is triggered:</strong></p>
  
  <pre><code> public intentsChange: Subject&lt;object&gt; = new Subject&lt;object&gt;();
     .....
  
      public updateIntents(appId: number) {
          this.requestsService.getAllIntents(appId)
            .subscribe(intents =&gt; {
              this.setIntents(intents);
              this.intentsChange.next(intents);
            });
        }
  </code></pre>
  
  <p><strong>Tests of the component which are currently failing because:</strong></p>
  
  <blockquote>
    <p>TypeError: updateService.intentsChange.subscribe is not a function</p>
  </blockquote>
  
  <pre><code>describe('TrainButtonComponent', () =&gt; {
    let component: TrainButtonComponent;
    let fixture: ComponentFixture&lt;TrainButtonComponent&gt;;
  
    let mockUpdateService;
    let intentsChange: Subject&lt;object&gt; = new Subject&lt;object&gt;();
  
  
    beforeEach(async(() =&gt; {
        intentsChange() {
          return Subject.of({});
        }
      };
      TestBed.configureTestingModule({
        imports: [ ],
        declarations: [ TrainButtonComponent ],
        providers: [
          { provide: UpdateService, useValue: mockUpdateService }
        ]
      })
      .compileComponents();
    }));
  
    beforeEach(() =&gt; {
      fixture = TestBed.createComponent(TrainButtonComponent);
      component = fixture.componentInstance;
      mockUpdateService = fixture.debugElement.injector.get(UpdateService);
      fixture.detectChanges();
    });
  
    it('should be created', () =&gt; {
      expect(component).toBeTruthy();
    });
  
  });
  </code></pre>
  
  <p>Does anyone know how to fix that Error so my Tests are actually running through again?</p>