Closed floisloading closed 1 year ago
I have the same issue. It also happens on Angular 14.1.3. Interestingly, cloning this project, upgrading to V14.2 and running the directive example still works fine.
Thank you for the workaround.
I have the same problem after upgrading from A12 to A13.
Also, using .dontMock
isn't a great solution. It doesn't make sense to dontMock
the whole Angular Material library, routerLink, etc.
@getsaf Is there a chance you could have a look at this?
@floisloading Did you ever find a solution to this problem?
@jacek-dargiel unfortunately not, but I didn't try.
Others are solving the issue by adding
"emitDecoratorMetadata": true,
"esModuleInterop": true,
to tsconfig.spec.json, but this doesn't solve the issue for me. It's a huge blocker on our side.
@FrEaKmAn didn't work for me either :(
Started running into this in our ng 14 upgrade also.
Several hundred tests failing 😱 I am afraid there is no easy bailout for us.
Did anyone already do some investigation of what the actual root cause is, and if it could be fixed in a reasonable way? Maybe we could help with that?
I looked a bit into the issue. This repo could also be used to reproduce the issue. It's a fresh angular library created according to: https://angular.io/guide/creating-libraries
According to these Angular Docs the base classes of @Directive/@Component
annotated classes need the annotation as well:
"[...] When a class has a @Directive()
or @Component()
decorator, the Angular compiler generates extra code to inject dependencies into the constructor. When using inheritance, Ivy needs both the parent class and the child class to apply a decorator to generate the correct code."
So is it possible that the @Directive
annotation is missing on the classes which are extended by MockDirective? That would be Mock and MockWithStubs . But those classes are also used by MockComponent so the @Directive()
/ @Component()
decorators would probably have to be set dynamic / conditional.
Could anybody have a look at this? This issue is making the upgrade to angular 14 quite hard for us as we have many hundred tests using shallow-render.
Hey all, sorry for the delay in getting this fix. Debugging was tough but the fix was pretty simple. Looks like the directive constructor props weren't being picked up by the Angular compiler so I manually added an @Inject
directive.
LMK how v14.2.0
works for you.
brandon, thank you!!! this is huge!
Thanks a lot, 14.2 works perfectly fine on our end. I reckon that wasn't easy to debug 💪 👍
Since updating to Angular 14.2.0, all Shallow-specs for Components with Directives in their temlates are failing with this message:
Complete console output of ng test
Output of
ng version
Minimal reproduction of the problem
Paste this into
app.component.spec.ts
:And execute
ng test
Workaround
The only solution I found is to not mock it at all: