Closed KarmaCop213 closed 4 years ago
It's not too good idea to spy on global API with ts-mockito
. It overrides implementation and can cause unexpected behaviors in other tests when you forgot to store real console
implementation and reset it after test. Usually it is good practice to wrap low level API. To have custom logger class that is wrapping global console
object and spy on it instead of console
from global scope.
Inside an angular service I have a function with the following:
When I call that function inside a test, and if I run the tests using the command
ng test
I get:If I run using the command
jest
(which is my test framework) it works fine.Just for sanity check I tried using jest.spyOn and it worked: