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
I'm trying to stub a dependency of the module I'm testing.
Issue
I'm new to using TestDouble so this is likely just my ignorance. I am trying, unsuccessfully so far, to stub a dependency of a module under test. The dependency is a module containing a class declared using module.exports = class clsName style. I can get a stubbed version but in my module when new clsName is executed it comes back with an error saying clsName is not a constructor.
I'm actually using Typescript but the code below is a contrived example of what I'm trying to do in plain Javascript. Is there anything obvious that I am doing wrong? Can I do what I'm attempting to do?
consttd=require('testdouble');describe('UnderTest',()=>{letUnderTest=null;beforeEach(()=>{constDependencyA=td.replace('./dep');td.when(newDependencyA(td.matchers.anything())).thenReturn({});td.when(DependencyA.prototype.doSomething()).thenReturn('I did it!');UnderTest=require('./undertest').UnderTest;});afterEach(()=>{UnderTest=null;td.reset();});it('Can Be Created',()=>{constunderTest=newUnderTest();});});
The text was updated successfully, but these errors were encountered:
Description
I'm trying to stub a dependency of the module I'm testing.
Issue
I'm new to using TestDouble so this is likely just my ignorance. I am trying, unsuccessfully so far, to stub a dependency of a module under test. The dependency is a module containing a class declared using module.exports = class clsName style. I can get a stubbed version but in my module when new clsName is executed it comes back with an error saying clsName is not a constructor.
I'm actually using Typescript but the code below is a contrived example of what I'm trying to do in plain Javascript. Is there anything obvious that I am doing wrong? Can I do what I'm attempting to do?
Environment
node 10.5.0
npm 6.3.0
testdouble 3.8.1
mocha 5.2.0
Code-fenced Examples
dep.js
undertest.js
test.js
The text was updated successfully, but these errors were encountered: