title: How to verify results of spied function (callThrough)
body: <p>I want to verify/assert the results of spied function. I'm using nestjs framework with jasmine. I create a jasmine spy on a method i want to "spy" on, that is, eavesdrop args and response/exception. However, I can't access return value of spied method.</p>
  
  <p>Let's say I have an emitter and listener and I want to assert that my listener throws an exception when a DB operation fails.</p>
  
  <p>Listener:</p>
  
  <pre><code>  onModuleInit() {
      this.emitter.on('documentDeleted', d =&gt; this.onDocumentDeleted(d));
    }
  
    @CatchAndLogAnyException()
    private async onDocumentDeleted(dto: DocumentDeletedEventDTO) {
      this.logger.log(`Deleting document with id '${dto.id}'...`);
  
      const result = await this.ResearchHearingTestModel.deleteOne({ _id: dto.id });
      if (!result.ok) {
        throw new DataAccessException(
          `Deleting document with id '${dto.id}' failed. Model.deleteOne(id) result: ${result}`,
        );
      }
      if (result.n &lt; 1) {
        throw new DocumentNotFoundException(`Deleting document with id '${dto.id}' failed.`);
      }
  
      this.logger.log(`Deleted document with id '${dto.id}.`);
    }
  </code></pre>
  
  <p>Test:</p>
  
  <pre class="lang-js prettyprint-override"><code>      const mockId = 123;
        const spyDelete = spyOn(model, 'deleteOne').and.returnValue({ ok: 1, n: 0 });
        const spyOnDeleted = spyOn(listener, 'onDocumentDeleted');
        spyOnDeleted.and.callThrough();
  
        await emitter.emit('documentDeleted', new DocumentDeletedEventDTO(mockId));
  
        expect(spyOnDeleted).toHaveBeenCalledTimes(1);
        expect(spyDelete).toHaveBeenCalledTimes(1);
        expect(spyDelete).toHaveBeenCalledWith(expect.objectContaining({ _id: mockId }));
        expect(spyOnDeleted).toThrow(DocumentNotFoundException);
  </code></pre>
  
  <p>So when debugging, I can see <code>spyOnDeleted["[[Scopes]]"][0].spy.calls.mostRecent["[[Scopes]]"][0].calls[0].returnValue</code> is a promise i'm probably looking for, but I can't access it or verify on it.</p>
  
  <p>And when I run the test, this is the output:</p>
  
  <pre><code>    expect(received).toThrow(expected)
  
      Expected name: "DocumentNotFoundException"
  
      Received function did not throw
  
         95 |       expect(spyDelete).toHaveBeenCalledTimes(1);
         96 |       expect(spyDelete).toHaveBeenCalledWith(expect.objectContaining({ _id: mockId }));
      &gt;  97 |       expect(spyOnDeleted).toThrow(DocumentNotFoundException);
            |                            ^
         98 |     });
         99 |   });
        100 | });
  </code></pre>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/38919057/callthrough-injected-spy">CallThrough injected spy</a> and several other questions that are similar, but I'm still hoping it's possible to spy on callThrough methods and eavesdrop on in/out of it. Any suggestions?</p>