NagRock / ts-mockito

Mocking library for TypeScript
MIT License
974 stars 93 forks source link

Throw exception if not stubbed. #190

Open startswithaj opened 4 years ago

startswithaj commented 4 years ago

Is there a way to configure a mock so that if a function or property is not stubbed using when it will throw an exception.

I have issue where I will have mocked classes with member functions that are suppose to return observables, but when not stubbed just return null. The problem here is that if they are called from within an observable stream such as inside a flatMap an exception is thrown later sometimes after the test completes.

Uncaught TypeError: You provided 'null' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. thrown

It would be good if mocks were configurable so that if a member is not set or unimplemented - that when accessed the proxy would throw an exception.

joelmeaders commented 4 years ago

YES, I too need this option! I have been writing tests for reactive services all week and tracking down every single observable through the chain manually is not fun.

Necroskillz commented 4 years ago

as a workaround: its usually visible from coverage where it stops.