You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function SomeCallable() {}
SomeCallable.doInterestingThing = function () {}
module.exports = SomeCallable
This "callable object" pattern is common in the Express-centric world, and is not currently mockable with td.object. I understand the desire to Not Mock What We Don't Own, but I ran into this while trying to isolate a unit in client (i.e. Not Mine, But Not Practically Shimmable) code.
In lieu of an undiscussed PR, here's the patch for a sample test:
diff --git a/test/src/object-test.coffee b/test/src/object-test.coffee
index 8cf1896..0dd0318 100644
--- a/test/src/object-test.coffee
+++ b/test/src/object-test.coffee
@@ -24,6 +24,12 @@ describe 'td.object', ->
Then -> expect(@result.message).to.contain(
"Please use `td.function()` or `td.constructor()` instead")
+ describe 'passing a callback object to td.object', ->
+ Given -> @callable = ->
+ Given -> @callable.someMethod = ->
+ Given -> @testDouble = td.object(@callable)
+ When -> td.when(@testDouble.someMethod('hi')).thenReturn('consider me greeted')
+ Then -> @testDouble.someMethod('hi') == 'consider me greeted'
if global.Proxy?
describe 'creating a proxy object (ES2015; only supported in FF + Edge atm)', ->
The text was updated successfully, but these errors were encountered:
Do we want to try to support this? The way this pattern materializes, td.object(Object.keys(hopefully_just_this_but_sometimes.constructor.prototype)) is a workaround. It's obviously annoying.
Hey Schoon, I'm really sorry for taking two months to read this properly, but what you described right out the gate can already be done by passing SomeCallable to td.function(), as it'll also replace any first-layer function properties underneath it.
This "callable object" pattern is common in the Express-centric world, and is not currently mockable with
td.object
. I understand the desire to Not Mock What We Don't Own, but I ran into this while trying to isolate a unit in client (i.e. Not Mine, But Not Practically Shimmable) code.In lieu of an undiscussed PR, here's the patch for a sample test:
The text was updated successfully, but these errors were encountered: