title: Unit test Angular 2 service subject
body: <p>I'm trying to write a test for an angular service which has a Subject property and a method to call <code>.next()</code> on that subject.</p>
  
  <p>The service is the following:</p>
  
  <pre><code>@Injectable()
  export class SubjectService {
    serviceSubjectProperty$: Subject&lt;any&gt; = new Subject();
  
    callNextOnSubject(data: any) {
      this.serviceSubjectProperty$.next(data);
    }
  }
  </code></pre>
  
  <p>And the test file for that service:</p>
  
  <pre><code>import { TestBed, inject } from '@angular/core/testing';
  
  import { SubjectService } from './subject.service';
  
  describe('SubjectService', () =&gt; {
  
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        providers: [
          SubjectService
        ]
      });
    });
  
    it('callNextOnSubject() should emit data to serviceSubjectProperty$ Subject',
      inject([SubjectService], (subjectService) =&gt; {
        subjectService.callNextOnSubject('test');
  
        subjectServiceProperty$.subscribe((message) =&gt; {
          expect(message).toBe('test');
        })
    }));
  });
  </code></pre>
  
  <p>The test always passes event if I change the argument of <code>subjectService.callNextOnSubject</code> from <code>'test'</code> to anything else.</p>
  
  <p>I have also tried wrapping everything with <code>async</code> and <code>fakeAsync</code>, but the result is the same.</p>
  
  <p>What would be the correct way to test if <code>callNextOnSubject</code> is emitting data to the <code>serviceSubjectProperty$</code> Subject?</p>