fix(ivy): classes should not mess up matching for bound dir attributes (#30002)
Previously, we had a bug where directive matching could fail if the directive attribute was bound and followed a certain number of classes. This is because in the matching logic, we were treating classes like normal attributes. We should instead be skipping classes in the attribute matching logic. Otherwise classes will match for directives with attribute selectors, and as we are iterating through them in twos (when they are stored as name-only, not in name-value pairs), it may throw off directive matching for any bound attributes that come after. This commit changes the directive matching logic to skip classes altogether. PR Close #30002
This commit is contained in:
@ -58,6 +58,30 @@ describe('directives', () => {
|
||||
expect(nodesWithDirective.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should match a mix of bound directives and classes', () => {
|
||||
TestBed.configureTestingModule({declarations: [TestComponent, TitleDirective]});
|
||||
TestBed.overrideTemplate(TestComponent, `
|
||||
<div class="one two" [id]="someId" [title]="title"></div>
|
||||
`);
|
||||
|
||||
const fixture = TestBed.createComponent(TestComponent);
|
||||
const nodesWithDirective = fixture.debugElement.queryAllNodes(By.directive(TitleDirective));
|
||||
|
||||
expect(nodesWithDirective.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should NOT match classes to directive selectors', () => {
|
||||
TestBed.configureTestingModule({declarations: [TestComponent, TitleDirective]});
|
||||
TestBed.overrideTemplate(TestComponent, `
|
||||
<div class="title" [id]="someId"></div>
|
||||
`);
|
||||
|
||||
const fixture = TestBed.createComponent(TestComponent);
|
||||
const nodesWithDirective = fixture.debugElement.queryAllNodes(By.directive(TitleDirective));
|
||||
|
||||
expect(nodesWithDirective.length).toBe(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user