Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It should warn or throw when used without instance #169

Open
k0pernikus opened this issue Nov 25, 2019 · 2 comments
Open

It should warn or throw when used without instance #169

k0pernikus opened this issue Nov 25, 2019 · 2 comments

Comments

@k0pernikus
Copy link

k0pernikus commented Nov 25, 2019

ts-mockito requires the use of instance (see: #87) to get the actual mocked object instance instead of a helper object. This is fine.

I find its behavior strange though when used in a test-case when not used with instance. (I have asked and answered a question on StackOverflow about "How to mock a method using ts-mockito?
"
because of it.)

TypeScript will transpile it, my Intellij WebStorm IDE will show no error, it will even autocomplete functions on the non-instance "mock".

From my perspective, the mock generated by mock looks like the actual mock instance. So I was very confused and spent a few hours figuring out why I was not getting the actual mocked value but this ts-mockito "proxy" object.

I'd propose that ts-mockito should have proxy on every method and issue a "Did you forget to use instance?" hint if possible. It will not catch all cases but for the ones were the developer is calling methods on the proxy object, they would get a more straightforward hint and not a generic runtime TypeError: actualReturnValue.{whatEverWasCalled} is not a function.

@pkrukp
Copy link

pkrukp commented Apr 23, 2020

ts-mockito requires the use of instance (see: #87) to get the actual mocked object instance instead of a helper object. This is fine.

But it looks like other mocking frameworks don't need a separate call to make an instance? For example TypeMoq: https://github.com/florinn/typemoq#dynamic-mocks

@awvalenti
Copy link

Same here. Got confused between Mock and instance(Mock) and spent great time finding the problem.

Mockito from Java is like @k0pernikus described, there are only instances. Shouldn't ts-mockito follow the same pattern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants