testdouble.js
testdouble.js copied to clipboard
Add td.asyncFunc
There has been some intermittent discussion of how we can make the tdjs API feel terser for async functions, and support is good enough now that I think we can solve it by adding a new top-level constructor td.asyncFunc and update imitate() to invoke that for all instances of AsyncFunction
This would resolve: #245 #371
cc/ @neall @jasonkarns
Love the idea! 👍
I'd love to see this as well! Something to consider is that I would expect mockAsyncFn[Symbol.toStringTag] to return "AsyncFunction" to allow full interoperability with how current versions Node.js tag async functions.
async function actualFn() {}
assert.equal(actualFn[Symbol.toStringTag], "AsyncFunction")
const mockFn = td.asyncFunction("mockFn")
assert.equal(mockFn[Symbol.toStringTag], "AsyncFunction")
Stale. Closing. Please reopen if still relevant and I will look into it.