test(language-service): add test for multiple bound attributes in microsyntax (#39062)

It used to be the case that all microsyntax bindings share the same source
span, so the second bound attribute would overwrite the first.

This has been fixed in #39036, this case is added to prevent regression.

PR Close #39062
This commit is contained in:
Keen Yee Liau 2020-09-30 08:59:47 -07:00 committed by Joey Perrott
parent 8e3710349d
commit eec9f4a84e
1 changed files with 13 additions and 0 deletions

View File

@ -535,6 +535,19 @@ describe('findNodeAtPosition for microsyntax expression', () => {
expect((node as t.BoundAttribute).name).toBe('ngForTrackBy');
});
it('should locate first bound attribute when there are two', () => {
// It used to be the case that all microsyntax bindings share the same
// source span, so the second bound attribute would overwrite the first.
// This has been fixed in pr/39036, this case is added to prevent regression.
const {errors, nodes, position} =
parse(`<div *ngFor="let item o¦f items; trackBy: trackByFn"></div>`);
expect(errors).toBe(null);
const node = findNodeAtPosition(nodes, position);
expect(isTemplateNode(node!)).toBe(true);
expect(node).toBeInstanceOf(t.BoundAttribute);
expect((node as t.BoundAttribute).name).toBe('ngForOf');
});
it('should locate bound attribute value', () => {
const {errors, nodes, position} = parse(`<div *ngFor="let item of it¦ems"></div>`);
expect(errors).toBe(null);