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
it('should not crash',function(){constmock=td.func();// 1st expectation: a generic onetd.when(mock(td.matchers.anything())).thenThrow(newError('1st expectation'));// 2nd expectation: a more specific one// => IT CRASH (the 1st expectation is executed when defining this one!!!)td.when(mock(400)).thenThrow(newError('2nd expectation'));});
Issue
The 2nd expectation crashes because the 1st expectation is executed when defining the 2nd.
We had seen that this behavior correspond to this note: "Note that because rehearsal calls invoke the test double function, it's possible to configure a thenThrow stubbing and then accidentally trigger it when you attempt to configure subsequent stubbings or verifications. In these cases, you'll need to work around it by re-ordering your configurations or catch'ing the error."
Is it possible to add an option that prevent to invoke the test double function when configuring a subsequent one?
Environment
mocha
node -v output: 11.2.0
npm -v (or yarn --version) output: 6.5.0
npm ls testdouble (or yarn list testdouble) version: 3.9.3
The text was updated successfully, but these errors were encountered:
As you pointed out from having read the note above, what the above code does is not yet supported by the library. I imagine what would be needed is some kind of td.disable(someFunc) API that allowed calls to be stubbed/verified without inadvertently invoking the prior stubbings of someFunc, followed by a td.enable(someFunc) API to enable it.
This would be a pretty significant code change. I'm open to it if it doesn't add a large maintenance burden, but I don't think this is a common enough case for me to invest the time to implement it.
What I'd do in your shoes is just do a single stubbing with a custom stubbing thenDo:
The Mocha test that shows the crash
Issue
The 2nd expectation crashes because the 1st expectation is executed when defining the 2nd.
We had seen that this behavior correspond to this note: "Note that because rehearsal calls invoke the test double function, it's possible to configure a thenThrow stubbing and then accidentally trigger it when you attempt to configure subsequent stubbings or verifications. In these cases, you'll need to work around it by re-ordering your configurations or catch'ing the error."
Is it possible to add an option that prevent to invoke the test double function when configuring a subsequent one?
Environment
node -v
output: 11.2.0npm -v
(oryarn --version
) output: 6.5.0npm ls testdouble
(oryarn list testdouble
) version: 3.9.3The text was updated successfully, but these errors were encountered: