Closed barbados-clemens closed 3 years ago
Thanks for the detail and the reproduction. I pulled down your project and inspected the decorator. It seems to be an issue with your decorator replacing the component's constructor method which does not copy over the constructor's reflection metadata to the replacement.
I was able to resolve this by changing this line:
const isMethod = descriptor.value instanceof Function;
to avoid replacing the constructor:
const isMethod = descriptor.value instanceof Function && descriptor !== target.prototype.constructor;
You may have some luck in attempting to copy the reflected metadata from the constructor but this could get tricky since Angular has changed the way this works over the years and you'd potentially run into issues if you decorated an "older" metadata constructor.
Thank you for the help!
the code provided had to me slightly modified to be
const isMethod = descriptor.value instanceof Function && descriptor.value !== target.prototype.constructor;
but that did the trick and makes total sense. Thank you for the quick response!
Awesome! Thanks for submitting the issue with so much detail, that really made debugging super-easy.
I have a use case where I am performing some overriding logic on component methods, but when trying to test these components via shallow-render the test returns the following handler
When using the TestBed directly it works fine, only shallow-render tests are failing with this error.
where
syncHandler
is the method that is overriding the method on a component class.when debugging I don't see any extra annotation data on the original method so I'm not 100% sure what is missing. I don't remove any of the class-level annotations that I can tell.
Here is a minimal reproducible https://github.com/barbados-clemens/ng-shallow-render-decorator-error