You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
describe('SomeHeaderDirective',()=>{beforeEach(waitForAsync(()=>{TestBed.configureTestingModule({imports: [HostComponent],}).compileComponents();}));it('should have correct foo and bar value',()=>{constfixture=TestBed.createComponent(HostComponent);fixture.detectChanges();constdebugElement=fixture.debugElement.queryAllNodes(By.directive(SomeHeaderDirective))[0];constdirective=debugElement.injector.get(SomeHeaderDirective);expect(directive.foo).toBe('foo');expect(directive.bar).toBe(true);});});
The above test works as expected, unless we introduce ng-mocks into the project. It breaks, even if ng-mocks not actively being called. Example code that will break the above test (can by in any .spec.ts file):
When I recently updated an internal project from Angular 16 to 17, a unit test making use of a structural directive that inherits from another structural directive broke. The project is using @angular/cdk's CdkHeaderRowDef that is being extended in the exact same way @angular/material's MatHeaderRowDef does it.
As far as I can see, CdkHeaderRowDef changed its sticky input definition from using the inputs property of @Directive to decorating the sticky class member via @Input while MatHeaderRowDef (we are keeping our custom component in-sync with its changes) kept overriding that input via the inputs property @Directive.
Description of the bug
Unit tests for a structural directive break when
ng-mocks
is used anywhere in a test (even if that test is unrelated to that directive).This is the structural directive:
The
BaseHeaderDirective
being extended:The test being run:
The above test works as expected, unless we introduce
ng-mocks
into the project. It breaks, even ifng-mocks
not actively being called. Example code that will break the above test (can by in any.spec.ts
file):The error shown:
An example of the bug
Created a minimal reproduction here:
https://github.com/nsgundy/ng-mocks-structural-directive-inheritance-issue
Context
When I recently updated an internal project from Angular 16 to 17, a unit test making use of a structural directive that inherits from another structural directive broke. The project is using
@angular/cdk
'sCdkHeaderRowDef
that is being extended in the exact same way@angular/material
'sMatHeaderRowDef
does it.As far as I can see,
CdkHeaderRowDef
changed itssticky
input definition from using theinputs
property of@Directive
to decorating thesticky
class member via@Input
whileMatHeaderRowDef
(we are keeping our custom component in-sync with its changes) kept overriding that input via theinputs
property@Directive
.This can be worked around by changing the override to using
@Input
instead. See nsgundy/ng-mocks-structural-directive-inheritance-issue@fe2bd2b.The text was updated successfully, but these errors were encountered: