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
Hi guys, I'd like some help witha simple thing I'm missing.
I'm testing a function from a module which has a dependency from another function of the same module.
So I wanted to stub the dependency function:
let contentClient = require('../../content-client');
var getAggregatedContentDetail = td.replace(contentClient, 'getAggregatedContentDetail');
td.when(getAggregatedContentDetail(td.matchers.anything(), td.matchers.anything(), td.matchers.anything(), td.matchers.anything()))
.thenReturn('1234');
//Function under test
let contentDetails = contentClient.getSimpleContentDetails();
In short: getSimpleContentDetails calls getAggregatedContentDetail internally, but executing the test, it's getting the real implementation of getAggregatedContentDetail, not the stub.
What I'm missing?
Thanks
The text was updated successfully, but these errors were encountered:
As far as I can tell, the above should work. The only thing I could ask at this point is you provide a minimal reproducible example repository for us to check into
@leandro-toledo-uux In the case of the sample repo, the issue is that getDetails calls getId directly, rather than through the exported object (i.e. module.exports.getId). There is no way for testdouble to replace getId itself; instead, it has to replace the reference to getId via the exported object.
Additionally, this is only an issue because your example is contaminating the veracity of the subject under test by taking the module being tested and faking out one portion of it. This is a more severe sub-type of a partial mock and I'd encourage you to break the relationship up so it's abundantly clear to the reader what's real and what's fake.
Hi guys, I'd like some help witha simple thing I'm missing.
I'm testing a function from a module which has a dependency from another function of the same module.
So I wanted to stub the dependency function:
In short: getSimpleContentDetails calls getAggregatedContentDetail internally, but executing the test, it's getting the real implementation of getAggregatedContentDetail, not the stub.
What I'm missing?
Thanks
The text was updated successfully, but these errors were encountered: