help-me-mom / ng-mocks

Angular testing library for mocking components, directives, pipes, services and facilitating TestBed setup
https://www.npmjs.com/package/ng-mocks
MIT License
1.04k stars 76 forks source link

Bug: cannot `.replace()` a component that has an abstract base class #8201

Open Eugeny opened 7 months ago

Eugeny commented 7 months ago

ng-mocks is checking the decorators and will fail if there's both @Component and @Injectable present. Instead, it should ignore @Injectable if there's @Component or @Directive present.

@Injectable is required on base component classes to avoid the Class is using Angular features error when inheriting, for example:

@Injectable()
abstract class Base {
    ngOnInit () {} 
}

@Component({...})
class Component extends Base {}
Dji75 commented 3 months ago

Why do you need Base to be Injectable as you can't inject it directly ? 🤔

I have a similar architecture, so I can purpose another way if you can adapt your code:

@Component({
  selector: 'app-base',
  template: '',
  standalone: true,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export abstract class Base {
Eugeny commented 3 months ago

It's a base class for both components and directives

Dji75 commented 3 months ago

What about an abstract directive then ?

@Directive({
  standalone: true,
})
export abstract class Base {