-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different objects created using the same constructor function obtained using td.constructor share the same stubs #305
Comments
Conceptually, what you're stubbing is the const dogA = td.object(new Dog());
const dogB = td.object(new Dog()); I believe that a more accurate solution for what you want could be accomplished if td.when(FakeDog.prototype.bark(), {withContext: dogA}).thenReturn('woof');
td.when(FakeDog.prototype.bark(), {withContext: dogB}).thenReturn('arf'); Closing as if this were a duplicate of #207 |
Oh, for a slightly uglier solution that still has you faking the td.when(FakeDog.prototype.bark()).thenDo(function () {
return this == dogA ? 'woof' : 'arf'
}) Update: fixed method name to |
The problem of using Just for reference, the solution I am using now is:
Once |
blah, sorry |
I was expecting two different objects created using the same constructor function obtained using
td.constructor
will allow independent stubbing but I have found that latesttd.when
call replaces previous ones for every instance. Here is some example code of how to reproduce it:Online example here: https://repl.it/repls/ExhaustedQuintessentialGelada
Documentation says:
but doesn't say anything about stubbing in one instance to be shared with every other instance so I suppose this is not expected.
The text was updated successfully, but these errors were encountered: