Open james-schwartzkopf opened 4 years ago
Hi @james-schwartzkopf, thanks for reporting the issue and providing a repro.
I performed additional investigation and found out that the SomeBase
class doesn't have any Angular decorators, but has the ngOnDestroy
lifecycle method and as a result, Ivy compiles it as if it has the base @Directive()
decorator, see additional info here. As a result, the main Pipe class at runtime has both Directive and Pipe metadata. Since the base Directive has no selector
defined, runtime checks that verify NgModule
structure fail.
We will look into this problem more, but as a current solution, please add the @Pipe
decorator (with some fake name
field value, like @Pipe({ name: 'base-pipe-class' })
) to the SomeBase
class - it should resolve the problem.
Thank you.
This looks suspect:
The getDirectiveDef
call finds the abstract directive as compiled by Ivy, but doesn't notice that the type is actually a pipe.
We will look into this problem more, but as a current solution, please add the
@Pipe
decorator (with some fakename
field value, like@Pipe({ name: 'base-pipe-class' })
) to theSomeBase
class - it should resolve the problem.Thank you.
Unfortunately I can't add the @Pipe because then I get ERROR: Cannot determine the module for class AsyncPipeBase
. And since it's an abstract class I can't just add it to the module.
@james-schwartzkopf, you can make the class non-abstract, and add it to the module that way. Or, as an alternative workaround, mark the abstract pipe with @Injectable()
.
I have the same issue, and my base class has the @Injectable
decorator on it. The thing is this error happens only in my unit tests, not when actually running the app.
I have the same problem. Happens only during tests.
Same issue.. Why no update on this? I just implemented OnDestroy in my base class and instance class and immediatelly my tests fail...
π bug report
Affected Package
The issue is caused by package @angular/core/testing ### Is this a regression? Yes, this worked in 8.2. ### Description When I have a Pipe in a library project that has a super class with a ngOnDestroy method, a TestBed that imports the library module fails with the error "Directive SomePipe has no selector, please add it!". This doesn't happen when the super class does not have an ngOnDestroy method, and it doesn't happen if the Pipe is included directly in the TestBed, or if the Module is part of the default app instead of a library project. ``` export abstract class SomeBase implements OnDestroy { /* * My real base class had a transform method, ect, but this seems to be * all that's needed to trigger it, and it wouldn't trigger without it */ ngOnDestroy() { } } @Pipe({ name: 'some' }) export class SomePipe extends SomeBase implements OnDestroy, PipeTransform { transform(value: unknown, ...args: unknown[]): unknown { return null; } // Is this needed, or will Ivy use the base class's ngOnDestroy without it?? // it's not needed to trigger the error ngOnDestroy() { super.ngOnDestroy(); } } ``` ``` beforeEach(async(() => { TestBed.configureTestingModule({ imports: [SomeLibModule], declarations: [ AppComponent ], }).compileComponents(); })); ``` ## π¬ Minimal Reproduction https://github.com/james-schwartzkopf/ng9-issues/tree/lib-pipe-issue ``` yarn ng build some-lib ng test ``` ## π₯ Exception or Error ## π Your Environment **Angular Version:**Anything else relevant?