title: Testing return value of function in Jasmine & Angular2
body: <p>In Jasmine you can check a function has been run by spying on it; you can also check what arguments have been given (if any); but how can you check what value that function returns?</p>
  
  <p><strong>Component</strong></p>
  
  <pre><code>ngOnInit() {
     this.checkString('Hello World');
  }
  
  checkString(str: string): boolean {
    if (str === 'Hello World') {
      return true;
    } else {
      return false;
    }
  }
  </code></pre>
  
  <p><strong>Spec</strong></p>
  
  <pre><code>...
  component = fixture.componentInstance;
  ...
  
  
  it('should check string equals `Hello World` and return boolean', () =&gt; {
  
    let spy = spyOn(component, "checkString");
  
    fixture.detectChanges(); // This runs the component OnInit() which contains a call to checkString();
  
    expect(spy).toBeTruthy(); // &lt;&lt;&lt; This line fails. How can I get the returned value of the method?
  
  });
  </code></pre>