typemoq icon indicating copy to clipboard operation
typemoq copied to clipboard

reset invocations

Open troywweber7 opened this issue 6 years ago • 2 comments

I'm trying to use typemoq in an Angular project to mock up certain behavior and verify calls to Excel API (which isn't available at the time of testing so I need to make use of the dynamic mocking). I use the setup to force relationships between certain objects, but later on down the line when I'm expecting something to be called once, it is actually called 9 times (from previous specs that were run).

How can I mitigate this situation? It seems like I need to be able to reset invocations of a call. However, I don't see this available in the API. Or is there a better way to write setups? I've also tried resetting the mock in question and reinitializing the original setup, but this leads to other problems...

troywweber7 avatar Oct 27 '18 00:10 troywweber7

There is a reset call on the mock: https://github.com/florinn/typemoq#reset-mocks E.g.

 const mockRouter: TypeMoq.IMock<Router> = TypeMoq.Mock.ofType<Router>();

mockRouter.reset();

WillEllis avatar Mar 14 '19 09:03 WillEllis

There is a reset call on the mock: https://github.com/florinn/typemoq#reset-mocks E.g.

 const mockRouter: TypeMoq.IMock<Router> = TypeMoq.Mock.ofType<Router>();

mockRouter.reset();

I'm facing the same problem. The aforementioned reset requires to do the setup again, so it will be something like setup -> call test -> reset -> setup again ... .

reflash avatar Apr 27 '20 08:04 reflash