We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi,
I'd like to know how to mock internal calls in this specific scenario:
module1.js
function function1() { //Some logic code return module2.function2(arg1); }
I want to fake function2, but the code under test, which is function1, runs the real implementation.
Right now, I'm stuck with this solution:
const module1 = require('path/to/module1.js'); it('should return fake function2', () => { //Arrange let function2Return = { test:'test', test2:'test2' }; //module2.js contains function2() let mod2= testdouble.replace('path/to/module2.js'); testdouble.when(mod2.function2().thenReturn( function2Return )); //Act //module1.js contains function1() let result = module1.function1(); //Assert assert.strictEqual('test2',result.test2); });
How do I tie the real implementation of function1() with the fake implementation of function2()?
Thanks
The text was updated successfully, but these errors were encountered:
You need to require module1 after you've replaced module2.
module1
module2
it('should return fake function2', () => { //Arrange let function2Return = { test:'test', test2:'test2' }; //module2.js contains function2() let mod2= testdouble.replace('path/to/module2.js'); const module1 = require('path/to/module1.js'); // <-- like this testdouble.when(mod2.function2().thenReturn( function2Return )); //Act //module1.js contains function1() let result = module1.function1(); //Assert assert.strictEqual('test2',result.test2); });
Sorry, something went wrong.
No branches or pull requests
Hi,
I'd like to know how to mock internal calls in this specific scenario:
module1.js
I want to fake function2, but the code under test, which is function1, runs the real implementation.
Right now, I'm stuck with this solution:
How do I tie the real implementation of function1() with the fake implementation of function2()?
Thanks
The text was updated successfully, but these errors were encountered: