Extend Type to support abstract classes #737
oleksii-nikishkin
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am building an app with Nest.js. I don't like the idea of tokens (
@Inject(SOME_TOKEN)
) and depending on final classes. I prefer having an interface or an abstract class of a service that might have multiple implementations. Here is an example:It works fine with the Nest's DI. It also works with their testing modules. However, I found it's not possible to create a test unit with mocked abstract dependencies using Suites. Here is an example:
get()
method doesn't let me access any dependency typed in the service as an abstract class or an interface.There is an interface
Type
(link) in your types package. I think it can be extended to support at least abstract classes by adding theabstract
key beforenew
, like this:I tried to tweak my unit test to consider
Logger
asType<Logger>
(even without theabstract
key) – it seems to be working fine, it successfully mocked the abstract class and injected it into the service. I was later able to spy on thelogger
.Beta Was this translation helpful? Give feedback.
All reactions