Stubbing callbacks
See original GitHub issueWhat if you could do this:
var fetch = td.function()
td.when(fetch('/some/path', td.callback(null, 'some data'))).thenReturn(undefined)
myFunction(fetch)
The td.callback API would just immediately invoke whatever function it captures at call-time with the provided arguments.
All so that you could synchronously specify this behavior in your source:
myFunction(fetch) {
fetch('/some/path', function(er, data){
console.log('my data is', data)
}
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:20 (12 by maintainers)
Top Results From Across the Web
How do I stub callbacks of a method? - Stack Overflow
I am using Firebase Phone Auth in my Flutter project and want to test my auth class. I know how to use when()...
Read more >Using Stub Callbacks - Parasoft C/C++test Professional 10.4.0 ...
Stub Callbacks provide a powerful mechanism for programming test case-specific stub logic. For each test case, you can define specific stub ...
Read more >Testing Callbacks with Mockito - Baeldung
Now we'll look at a common solution for stubbing methods that have callbacks using Mockito's Answer object and doAnswer method to stub the ......
Read more >Mockito 3 Stubbing with Callback - Junit 5 Jupiter | wesome.org
Callback with stub is a bit controversial feature hence originally was not included in Mockito. The callback method returns an Answer Interface.
Read more >Stubs - Sinon.JS
Invokes callbacks passed as a property of an object to the stub. Like yield , yieldTo grabs the first matching argument, finds the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is already already supported, but if you want to control the callback function then you should configure it separately. Trying to do both in one shot would be too confusing, and any additional parameters to the
td.callbackmatcher would be passed to the callback function, since all its args are forwarded.Would this work?
That’s what I was looking for, thanks!