Sinon: callThrough doesn't work on a withArgs sub-stub

Created on 5 Jan 2019  Â·  4Comments  Â·  Source: sinonjs/sinon

Describe the bug

1442 was not fully fixed by #1549. The case of using stubs directly instead of with mocks and expectations, as shown in https://github.com/sinonjs/sinon/issues/1442#issuecomment-306330402, is still broken.

To Reproduce
Steps to reproduce the behavior:
This code will throw an exception TypeError: Cannot read property 'apply' of undefined due to the fake returned from withArgs not having a wrappedMethod member.

let stub = sinon.stub(obj, 'method')
    .withArgs(123)
    .returns('bar')
    .callThrough();
obj.method('bar')

Expected behavior
The callThrough behavior should be available on withArgs fakes.

Screenshots
If applicable, add screenshots to help explain your problem.

Context (please complete the following information):

  • Library version: Verified with 6.3.4 and master at 97a12178
  • Environment: Linux Node 10.x
  • Example URL: N/A
  • Other libraries you are using: N/A

Additional context

I've prepared a test case demonstrating the issue:
https://github.com/sinonjs/sinon/compare/master...mgabeler-lee-6rs:issue-1964

Help wanted

All 4 comments

That's a nice test ✨

Would you like to contribute a PR to fix it?

I had started looking into that at first, but didn't understand sinon's internals well enough to do so. If I have time to figure that out, I'd happily do so, but TBH I don't see that happening in the next couple weeks, so if someone else wants to go for it in the meantime, that's fine with me. If not, I'll try to revisit this when I have time :)

Had some time to dig into this finally today, filed #2012 with a proposed fix

Very nice work :heart:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

byohay picture byohay  Â·  3Comments

ljian3377 picture ljian3377  Â·  3Comments

ALeschinsky picture ALeschinsky  Â·  4Comments

fearphage picture fearphage  Â·  3Comments

zimtsui picture zimtsui  Â·  3Comments