title: Test value of variable inside javascript function - sinon / chai
body: <p>I've got the following function in a React component:</p>
  
  <pre><code>parentFunction: function(items){
    let variableOfInterest = this.callThisFunction().toArray().filter((ele) =&gt; {
      if(obj[ele.get('id')]){
        return ele
      }
    }).map((ele) =&gt; ele.get('id'))
  
    this.setState({newState:variableOfInterest})
  }
  </code></pre>
  
  <p>I'm able to write a test for the invocation of callThisFunction using stubs, but have been unable to figure out if it is possible use sinon or chai to spy on the value of the variableOfInterest. I'd like to write a test where I can pass in an argument, and use 'expect' to test for the result's value. It doesn't really make sense to return the value either at the end - and doing so just for the test seems unnecessary. 
  I'd also love to be able to test for the result of calling toArray(), and also filter() if that is possible. Thanks for any insight!</p>
  
  <p>This is my test for the invocation of callThisFunction():</p>
  
  <pre><code>it('should call callThisFunction() once', () =&gt; {   
    let callThisFunctionStub = sinon.stub(prototype, 'callThisFunction')
    let stub = callThisFunctionStub.callsFake(() =&gt; objectToReturn)
    prototype.callParentFunction(items)
    sinon.assert.calledOnce(stub)
  })
  </code></pre>