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
Verify the behavior your issue is concerned with by clicking "Run"
Link to the Runkit here
Code-fenced Examples
import*astdfrom'testdouble';constmyObj={myFunc(arg1,arg2){console.log(`I am executed with: ${arg1} and ${arg2}`);}};// Create a test double for `myObj.myFunc`constmyFunc=td.replace(myObj,'myFunc');// Call through the test double and execute the original `myObj.myFunc` methodtd.when(myFunc('foo','bar')).thenDo((...args)=>myObj.myFunc(...args));// Call the code that uses `myObj.myFunc`myObj.myFunc('foo','bar');// Verify that `myObj.myFunc` was called once with the specified argumentstd.verify(myObj.myFunc('foo','bar'),{times: 1});console.log('ALL TESTS PASSED!');
I would like to spy on an existing function and also execute it. Specifically, I want to run
console.log(`I am executed with: ${arg1} and ${arg2}`);
In some other libraries, this can be done with a callThrough method, but I have been unable to do so here. Instead, I am receiving a RangeError: Maximum call stack size exceeded.
How can I resolve this issue?
The text was updated successfully, but these errors were encountered:
td.replace overwrites the reference until td.reset is called. If you wanted to do this for whatever reason, you'd have to grab a reference to the function you're overwriting (see ogFunc = … below).
Note that stubbing this interaction and then verifying it was called is a separate issue that triggers a warning in testdouble.js because it's a common test smell with mocking
consttd=require('testdouble');constmyObj={myFunc(arg1,arg2){console.log(`I am executed with: ${arg1} and ${arg2}`);}};constogFunc=myObj.myFunc;// Overwrite myObj.myFunc with a test doubleconstmyFunc=td.replace(myObj,'myFunc');// Call through the test double and execute the original `myObj.myFunc` methodtd.when(myFunc('foo','bar')).thenDo((...args)=>ogFunc(...args));// Call the code that uses `myObj.myFunc`myObj.myFunc('foo','bar');// Verify that `myObj.myFunc` was called once with the specified argumentstd.verify(myObj.myFunc('foo','bar'),{times: 1});// Restore myObj.myFunctd.reset();console.log('ALL TESTS PASSED!');
Description
I want to spy and call through original function.
Issue
I am getting
RangeError: Maximum call stack size exceeded
Environment
node -v
output: v14.19.1npm -v
(oryarn --version
) output: 6.14.16npm ls testdouble
(oryarn list testdouble
) version:Failing Test
Example Repo
npm it
and observe the issueRunkit Notebook
var td = require('testdouble')
at the topCode-fenced Examples
I would like to spy on an existing function and also execute it. Specifically, I want to run
In some other libraries, this can be done with a
callThrough
method, but I have been unable to do so here. Instead, I am receiving aRangeError: Maximum call stack size exceeded
.How can I resolve this issue?
The text was updated successfully, but these errors were encountered: